HoustonPutman commented on a change in pull request #302: URL: https://github.com/apache/solr-operator/pull/302#discussion_r714152301
########## File path: api/v1beta1/solrcloud_types.go ########## @@ -331,7 +335,50 @@ type SolrBackupRestoreOptions struct { // Since the volume will be mounted to all solrNodes, it must be able to be written from multiple pods. // If a PVC reference is given, the PVC must have `accessModes: - ReadWriteMany`. // Other options are to use a NFS volume. - Volume corev1.VolumeSource `json:"volume"` + // Deprecated: Create an explicit 'managedRepositories' entry instead. + Volume *corev1.VolumeSource `json:"volume,omitempty"` + + // Allows specification of multiple different "repositories" for Solr to use when backing up data to GCS. + GcsRepositories *[]GcsStorage `json:"gcsRepositories,omitempty"` Review comment: Don't need a pointer here, arrays are optional. But `// +optional` should be used. ########## File path: api/v1beta1/solrcloud_types.go ########## @@ -331,7 +335,50 @@ type SolrBackupRestoreOptions struct { // Since the volume will be mounted to all solrNodes, it must be able to be written from multiple pods. // If a PVC reference is given, the PVC must have `accessModes: - ReadWriteMany`. // Other options are to use a NFS volume. - Volume corev1.VolumeSource `json:"volume"` + // Deprecated: Create an explicit 'managedRepositories' entry instead. + Volume *corev1.VolumeSource `json:"volume,omitempty"` + + // Allows specification of multiple different "repositories" for Solr to use when backing up data to GCS. + GcsRepositories *[]GcsStorage `json:"gcsRepositories,omitempty"` + + // Allows specification of multiple different "repositories" for Solr to use when backing up data "locally". + // Repositories defined here are considered "managed" and can take advantage of special operator features, such as + // post-backup compression. + ManagedRepositories *[]ManagedStorage `json:"managedRepositories,omitempty"` Review comment: Don't need a pointer here, arrays are optional. But `// +optional` should be used. ########## File path: controllers/solrcloud_controller.go ########## @@ -699,6 +694,41 @@ func reconcileCloudStatus(r *SolrCloudReconciler, solrCloud *solr.SolrCloud, log return outOfDatePods, outOfDatePodsNotStarted, availableUpdatedPodCount, nil } +func isPodReadyForBackup(pod corev1.Pod, backupOptions *solr.SolrBackupRestoreOptions) bool { Review comment: Maybe instead of all this complex logic, when creating a podTemplate, we add an annotation for all the backupRepositories that pod is ready to handle... That will make it a lot easier to determine what repositories the cloud is "ready" for (just take an intersection of the lists from the pod annotations). We can do this in a different PR though, don't want to complicate this one further. ########## File path: api/v1beta1/solrcloud_types.go ########## @@ -331,7 +335,50 @@ type SolrBackupRestoreOptions struct { // Since the volume will be mounted to all solrNodes, it must be able to be written from multiple pods. // If a PVC reference is given, the PVC must have `accessModes: - ReadWriteMany`. // Other options are to use a NFS volume. - Volume corev1.VolumeSource `json:"volume"` + // Deprecated: Create an explicit 'managedRepositories' entry instead. + Volume *corev1.VolumeSource `json:"volume,omitempty"` + + // Allows specification of multiple different "repositories" for Solr to use when backing up data to GCS. + GcsRepositories *[]GcsStorage `json:"gcsRepositories,omitempty"` + + // Allows specification of multiple different "repositories" for Solr to use when backing up data "locally". + // Repositories defined here are considered "managed" and can take advantage of special operator features, such as + // post-backup compression. + ManagedRepositories *[]ManagedStorage `json:"managedRepositories,omitempty"` + + // Select a custom directory name to mount the backup/restore data from the given volume. + // If not specified, then the name of the solrcloud will be used by default. + // Deprecated: Create an explicit 'managedRepositories' entry instead. + // +optional + Directory string `json:"directory,omitempty"` +} + +type GcsStorage struct { + // A name used to identify this GCS storage profile. Values should follow RFC-1123. (See here for more details: + // https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names) + Name string `json:"name"` + + // The name of the GCS bucket that all backup data will be stored in + Bucket string `json:"bucket"` + + // The name of a Kubernetes secret holding a Google cloud service account key + GcsCredentialSecret string `json:"gcsCredentialSecret"` Review comment: Should this have a secret key as well? ########## File path: controllers/solrbackup_controller.go ########## @@ -89,6 +90,7 @@ func (r *SolrBackupReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) solrCloud, allCollectionsComplete, collectionActionTaken, err := reconcileSolrCloudBackup(r, backup) if err != nil { + // TODO Should we be failing the backup for some sub-set of errors here? Review comment: Yeah since we know the Solr errors, it would probably be good to do stuff here in case. But I think we can do it in a future Issue/PR. ########## File path: api/v1beta1/solrcloud_types.go ########## @@ -331,7 +335,50 @@ type SolrBackupRestoreOptions struct { // Since the volume will be mounted to all solrNodes, it must be able to be written from multiple pods. // If a PVC reference is given, the PVC must have `accessModes: - ReadWriteMany`. // Other options are to use a NFS volume. - Volume corev1.VolumeSource `json:"volume"` + // Deprecated: Create an explicit 'managedRepositories' entry instead. Review comment: Should have `// +optional` since this is optional now. ########## File path: controllers/util/solr_util.go ########## @@ -215,16 +216,63 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl } // Add backup volumes if solrCloud.Spec.StorageOptions.BackupRestoreOptions != nil { - solrVolumes = append(solrVolumes, corev1.Volume{ - Name: BackupRestoreVolume, - VolumeSource: solrCloud.Spec.StorageOptions.BackupRestoreOptions.Volume, - }) - volumeMounts = append(volumeMounts, corev1.VolumeMount{ - Name: BackupRestoreVolume, - MountPath: BaseBackupRestorePath, - SubPath: BackupRestoreSubPathForCloud(solrCloud.Spec.StorageOptions.BackupRestoreOptions.Directory, solrCloud.Name), - ReadOnly: false, - }) + backupOptions := solrCloud.Spec.StorageOptions.BackupRestoreOptions + // Backup volumes can come from three sources: a singleton volume for local backups (legacy), a list of "managed" + // (i.e. local) repositories, and a list of gcs repositories. All three of these require a volume and + // accompanying mount: either for credentials to reach GCS or for the data itself. + + // Handle the "singleton" local volume first + if backupOptions.Volume != nil { + solrVolumes = append(solrVolumes, corev1.Volume{ + Name: solr.BackupRestoreVolume, + VolumeSource: *backupOptions.Volume, + }) + volumeMounts = append(volumeMounts, corev1.VolumeMount{ + Name: solr.BackupRestoreVolume, + MountPath: solr.BaseBackupRestorePath, + SubPath: BackupRestoreSubPathForCloud(backupOptions.Directory, solrCloud.Name), + ReadOnly: false, + }) + } + + // Then handle any other managed volumes + if backupOptions.ManagedRepositories != nil { + for _, managedRepository := range *backupOptions.ManagedRepositories { + solrVolumes = append(solrVolumes, corev1.Volume{ + Name: managedRepository.GetVolumeName(), + VolumeSource: *managedRepository.Volume, + }) + volumeMounts = append(volumeMounts, corev1.VolumeMount{ + Name: managedRepository.GetVolumeName(), + MountPath: managedRepository.GetSolrMountPath(), + SubPath: BackupRestoreSubPathForCloud(managedRepository.Directory, solrCloud.Name), + ReadOnly: false, + }) + } + } + + // Lastly, handle the volumes needed for any GCS credentials. + if backupOptions.GcsRepositories != nil { + for _, gcsRepository := range *backupOptions.GcsRepositories { + fals := false + solrVolumes = append(solrVolumes, corev1.Volume{ + Name: gcsRepository.GetVolumeName(), + VolumeSource: corev1.VolumeSource{ Review comment: We might need to worry about restarting the Solr Pods when these secrets update. But again we can have a separate issue/PR for that. ########## File path: controllers/util/backup_util_test.go ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package util + +import ( + solr "github.com/apache/solr-operator/api/v1beta1" + "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "testing" +) + +func TestSolrBackupApiParamsForLegacyBackup(t *testing.T) { + legacyRepository := solr.SolrBackupRestoreOptions{ + Volume: &corev1.VolumeSource{}, // Actual volume info doesn't matter here + Directory: "/somedirectory", + } + backupConfig := solr.SolrBackup{ + ObjectMeta: metav1.ObjectMeta{ + Name: "somebackupname", + }, + Spec: solr.SolrBackupSpec{ + SolrCloud: "solrcloudcluster", + RepositoryName: "legacy_local_repository", + Collections: []string{"col1", "col2"}, + }, + } + + queryParams := GenerateQueryParamsForBackup(&legacyRepository, &backupConfig, "col2") + + assert.Equal(t, "BACKUP", queryParams.Get("action")) Review comment: Messages on the asserts would be helpful when debugging 🙂 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org