gerlowskija commented on a change in pull request #302:
URL: https://github.com/apache/solr-operator/pull/302#discussion_r707291123
##########
File path: api/v1beta1/solrcloud_types.go
##########
@@ -325,20 +329,158 @@ type SolrEphemeralDataStorageOptions struct {
EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty"`
}
+func (backupOptions *SolrBackupRestoreOptions) IsManaged() bool {
+ return true
+}
+
+func (backupOptions *SolrBackupRestoreOptions) GetVolumeSource()
corev1.VolumeSource {
+ return *backupOptions.Volume
+}
+
+func (backupOptions *SolrBackupRestoreOptions) GetDirectory() string {
+ return backupOptions.Directory
+}
+
+func (backupOptions *SolrBackupRestoreOptions) GetSolrMountPath() string {
+ return BaseBackupRestorePath
+}
+
+func (backupOptions *SolrBackupRestoreOptions) GetInitPodMountPath() string {
+ return BackupRestoreInitContainerPath
+}
+
+func (backupOptions *SolrBackupRestoreOptions) GetBackupPath(backupName
string) string {
+ return backupOptions.GetSolrMountPath() + "/backups/" + backupName
+}
+
+func (backupOptions *SolrBackupRestoreOptions) GetVolumeName() string {
+ return BackupRestoreVolume
+}
+
type SolrBackupRestoreOptions struct {
+ // TODO Do we need to support this (Volume) here for backcompat, or can
it live exclusively in ManagedStorage?
+
// This is a volumeSource for a volume that will be mounted to all
solrNodes to store backups and load restores.
// The data within the volume will be namespaces for this instance, so
feel free to use the same volume for multiple clouds.
// 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"`
+ 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""`
+
+ // TODO Do we need to support this here for backcompat, or can it live
exclusively in ManagedStorage
// 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.
// +optional
Directory string `json:"directory,omitempty"`
}
+type GcsStorage struct {
+ // A name used to identify this GCS storage profile.
+ 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"`
+ // JEGERLOW TODO Should 'baseLocation' be optional?
+ // A chroot within the bucket to store data in. If specified this
should already exist
+ BaseLocation string `json:"baseLocation"`
+}
+
+func VolumeExistsWithName(needle string, haystack []corev1.Volume) bool {
+ for _, volume := range haystack {
+ if volume.Name == needle {
+ return true
+ }
+ }
+ return false
+}
+
+func (gcsRepository *GcsStorage) IsManaged() bool { return false }
+
+func (gcsRepository *GcsStorage) GetSolrMountPath() string {
+ return fmt.Sprintf("%s-%s-%s", BaseBackupRestorePath, "gcscredential",
gcsRepository.Name)
+}
+
+func (gcsRepository *GcsStorage) GetInitPodMountPath() string {
+ return ""
+}
+
+func (gcsRepository *GcsStorage) GetBackupPath(backupName string) string {
+ if gcsRepository.BaseLocation != "" {
+ return gcsRepository.BaseLocation
+ }
+ return "/"
+}
+
+func (gcsRepository *GcsStorage) GetVolumeName() string {
+ return fmt.Sprintf("%s-%s", gcsRepository.Name,
BackupRestoreCredentialVolume)
+}
+
+func (gcs *GcsStorage) IsCredentialVolumePresent(volumes []corev1.Volume) bool
{
+ expectedVolumeName := gcs.GetVolumeName()
+ return VolumeExistsWithName(expectedVolumeName, volumes)
+}
+
+type ManagedStorage struct {
+ // A name used to identify this local storage profile.
+ Name string `json:"name"`
+
+ // This is a volumeSource for a volume that will be mounted to all
solrNodes to store backups and load restores.
+ // The data within the volume will be namespaces for this instance, so
feel free to use the same volume for multiple clouds.
+ // 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,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.
+ // +optional
+ Directory string `json:"directory,omitempty"`
+}
+
+func (managedRepository *ManagedStorage) IsManaged() bool { return true }
Review comment:
AFAICT, golang "receiver functions" need to be defined in the same
package as the type they're received by. So I was able to move these out to a
new file (solrcloud_type_helpers.go), but it's still in the API package by
necessity.
Hope that's what you were looking for!
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]