diff --git a/api/bases/manila.openstack.org_manilas.yaml b/api/bases/manila.openstack.org_manilas.yaml index e686f573..9591bded 100644 --- a/api/bases/manila.openstack.org_manilas.yaml +++ b/api/bases/manila.openstack.org_manilas.yaml @@ -44,12 +44,21 @@ spec: databaseUser: default: manila type: string + dbPurge: + properties: + age: + default: 30 + type: integer + schedule: + default: 1 0 * * * + type: string + type: object debug: properties: - dbPurge: + dbSync: default: false type: boolean - dbSync: + debug: default: false type: boolean type: object diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 63b0873a..3b685430 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -30,6 +30,11 @@ const ( ManilaSchedulerContainerImage = "quay.io/podified-antelope-centos9/openstack-manila-scheduler:current-podified" // ManilaShareContainerImage is the fall-back container image for ManilaShare ManilaShareContainerImage = "quay.io/podified-antelope-centos9/openstack-manila-share:current-podified" + //DBPurgeAge - + DBPurgeDefaultAge = 30 + //DBPurgeDefaultSchedule - + DBPurgeDefaultSchedule = "1 0 * * *" + ) // ManilaTemplate defines common input parameters used by all Manila services @@ -114,19 +119,6 @@ type PasswordSelector struct { Service string `json:"service,omitempty"` } -// ManilaDebug indicates whether certain stages of Manila deployment should -// pause in debug mode -type ManilaDebug struct { - // +kubebuilder:validation:Optional - // +kubebuilder:default=false - // dbSync enable debug - DBSync bool `json:"dbSync,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:default=false - // dbPurge enable debug on the DBPurge CronJob - DBPurge bool `json:"dbPurge,omitempty"` -} - // ManilaServiceDebug indicates whether certain stages of Manila service // deployment should pause in debug mode type ManilaServiceDebug struct { @@ -143,6 +135,8 @@ func SetupDefaults() { APIContainerImageURL: util.GetEnvVar("RELATED_IMAGE_MANILA_API_IMAGE_URL_DEFAULT", ManilaAPIContainerImage), SchedulerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_MANILA_SCHEDULER_IMAGE_URL_DEFAULT", ManilaSchedulerContainerImage), ShareContainerImageURL: util.GetEnvVar("RELATED_IMAGE_MANILA_SHARE_IMAGE_URL_DEFAULT", ManilaShareContainerImage), + DBPurgeAge: DBPurgeDefaultAge, + DBPurgeSchedule: DBPurgeDefaultSchedule, } SetupManilaDefaults(manilaDefaults) diff --git a/api/v1beta1/manila_types.go b/api/v1beta1/manila_types.go index 9f734dfb..7bf517c5 100644 --- a/api/v1beta1/manila_types.go +++ b/api/v1beta1/manila_types.go @@ -90,6 +90,10 @@ type ManilaSpec struct { // NodeSelector here acts as a default value and can be overridden by service // specific NodeSelector Settings. NodeSelector map[string]string `json:"nodeSelector,omitempty"` + + // +kubebuilder:validation:Optional + // DBPurge parameters - + DBPurge DBPurge `json:"dbPurge,omitempty"` } // ManilaStatus defines the observed state of Manila @@ -143,6 +147,31 @@ func init() { SchemeBuilder.Register(&Manila{}, &ManilaList{}) } +// DBPurge struct is used to model the parameters exposed to the Manila API CronJob +type DBPurge struct { + // +kubebuilder:validation:Optional + // +kubebuilder:default=30 + // Age - + Age int `json:"age"` + // +kubebuilder:validation:Optional + // +kubebuilder:default="1 0 * * *" + //Schedule - + Schedule string `json:"schedule"` +} + +// ManilaDebug indicates whether certain stages of Manila deployment should +// pause in debug mode +type ManilaDebug struct { + // +kubebuilder:validation:Optional + // +kubebuilder:default=false + // dbSync enable debug + DBSync bool `json:"dbSync,omitempty"` + // +kubebuilder:validation:Optional + // +kubebuilder:default=false + // DBPurge enables debug mode on the DBPurge CronJob + DBPurge bool `json:"debug,omitempty"` +} + // IsReady - returns true if Manila is reconciled successfully func (instance Manila) IsReady() bool { return instance.Status.Conditions.IsTrue(condition.ReadyCondition) diff --git a/api/v1beta1/manila_webhook.go b/api/v1beta1/manila_webhook.go index 1e6957fe..741f2919 100644 --- a/api/v1beta1/manila_webhook.go +++ b/api/v1beta1/manila_webhook.go @@ -34,6 +34,8 @@ type ManilaDefaults struct { APIContainerImageURL string SchedulerContainerImageURL string ShareContainerImageURL string + DBPurgeAge int + DBPurgeSchedule string } var manilaDefaults ManilaDefaults @@ -82,6 +84,11 @@ func (spec *ManilaSpec) Default() { spec.ManilaShares[key] = manilaShare } } + + if (spec.DBPurge.Age == 0) && (spec.DBPurge.Schedule == "") { + spec.DBPurge.Age = manilaDefaults.DBPurgeAge + spec.DBPurge.Schedule = manilaDefaults.DBPurgeSchedule + } } // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index d89e750d..e6f18c6d 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -50,6 +50,21 @@ func (in *APIOverrideSpec) DeepCopy() *APIOverrideSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DBPurge) DeepCopyInto(out *DBPurge) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBPurge. +func (in *DBPurge) DeepCopy() *DBPurge { + if in == nil { + return nil + } + out := new(DBPurge) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Manila) DeepCopyInto(out *Manila) { *out = *in @@ -697,6 +712,7 @@ func (in *ManilaSpec) DeepCopyInto(out *ManilaSpec) { (*out)[key] = val } } + out.DBPurge = in.DBPurge } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManilaSpec. diff --git a/config/crd/bases/manila.openstack.org_manilas.yaml b/config/crd/bases/manila.openstack.org_manilas.yaml index e686f573..9591bded 100644 --- a/config/crd/bases/manila.openstack.org_manilas.yaml +++ b/config/crd/bases/manila.openstack.org_manilas.yaml @@ -44,12 +44,21 @@ spec: databaseUser: default: manila type: string + dbPurge: + properties: + age: + default: 30 + type: integer + schedule: + default: 1 0 * * * + type: string + type: object debug: properties: - dbPurge: + dbSync: default: false type: boolean - dbSync: + debug: default: false type: boolean type: object diff --git a/pkg/manila/const.go b/pkg/manila/const.go index f8bd54b3..ef118c0c 100644 --- a/pkg/manila/const.go +++ b/pkg/manila/const.go @@ -59,11 +59,6 @@ const ( // CustomServiceConfigSecretsFileName - Snippet generated by Secrets passed // to the sub CR CustomServiceConfigSecretsFileName = "04-config.conf" - - //DBPurgeAge - - DBPurgeAge = 30 - //DBPurgeDefaultSchedule - - DBPurgeDefaultSchedule = "1 0 * * *" ) // DbsyncPropagation keeps track of the DBSync Service Propagation Type diff --git a/pkg/manila/cronjob.go b/pkg/manila/cronjob.go index d26e08fe..5a1be992 100644 --- a/pkg/manila/cronjob.go +++ b/pkg/manila/cronjob.go @@ -46,7 +46,7 @@ func CronJob( DBPurgeCommandString := strings.Join(DBPurgeCommand, " ") // Extend the resulting command with the DBPurgeAge int - args = append(args, DBPurgeCommandString+strconv.Itoa(DBPurgeAge)) + args = append(args, DBPurgeCommandString+strconv.Itoa(instance.Spec.DBPurge.Age)) parallelism := int32(1) completions := int32(1) @@ -83,7 +83,7 @@ func CronJob( Namespace: instance.Namespace, }, Spec: batchv1.CronJobSpec{ - Schedule: DBPurgeDefaultSchedule, + Schedule: instance.Spec.DBPurge.Schedule, ConcurrencyPolicy: batchv1.ForbidConcurrent, JobTemplate: batchv1.JobTemplateSpec{ ObjectMeta: metav1.ObjectMeta{