diff --git a/api/bases/manila.openstack.org_manilas.yaml b/api/bases/manila.openstack.org_manilas.yaml index baddda24..30ddeaa5 100644 --- a/api/bases/manila.openstack.org_manilas.yaml +++ b/api/bases/manila.openstack.org_manilas.yaml @@ -44,6 +44,15 @@ spec: databaseUser: default: manila type: string + dbPurge: + properties: + age: + default: 30 + type: integer + schedule: + default: 1 0 * * * + type: string + type: object debug: properties: dbPurge: diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 63b0873a..7495a395 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -17,7 +17,6 @@ limitations under the License. package v1beta1 import ( - "github.com/openstack-k8s-operators/lib-common/modules/common/util" corev1 "k8s.io/api/core/v1" ) @@ -30,6 +29,10 @@ 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" + //DBPurgeDefaultAge indicates the number of days of purging DB records + DBPurgeDefaultAge = 30 + //DBPurgeDefaultSchedule is in crontab format, and the default runs the job once every day + DBPurgeDefaultSchedule = "1 0 * * *" ) // ManilaTemplate defines common input parameters used by all Manila services @@ -114,19 +117,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 { @@ -135,15 +125,3 @@ type ManilaServiceDebug struct { // service enable debug Service bool `json:"service,omitempty"` } - -// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks) -func SetupDefaults() { - // Acquire environmental defaults and initialize Manila defaults with them - manilaDefaults := ManilaDefaults{ - 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), - } - - SetupManilaDefaults(manilaDefaults) -} diff --git a/api/v1beta1/manila_types.go b/api/v1beta1/manila_types.go index d376a0e9..1e5ae632 100644 --- a/api/v1beta1/manila_types.go +++ b/api/v1beta1/manila_types.go @@ -95,6 +95,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 @@ -148,6 +152,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 is the DBPurgeAge parameter and indicates the number of days of purging DB records + Age int `json:"age"` + // +kubebuilder:validation:Optional + // +kubebuilder:default="1 0 * * *" + //Schedule defines the crontab format string to schedule the DBPurge cronJob + Schedule string `json:"schedule"` +} + +// ManilaDebug contains flags related to multiple debug activities. See the +// individual comments for what this means for each flag. +type ManilaDebug struct { + // +kubebuilder:validation:Optional + // +kubebuilder:default=false + // DBSync pauses the dbSync container instead of executing the db_sync command. + DBSync bool `json:"dbSync,omitempty"` + // +kubebuilder:validation:Optional + // +kubebuilder:default=false + // DBPurge increases log verbosity by executing the db_purge command with "--debug". + DBPurge bool `json:"dbPurge,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..4cbcdc19 100644 --- a/api/v1beta1/manila_webhook.go +++ b/api/v1beta1/manila_webhook.go @@ -23,6 +23,7 @@ limitations under the License. package v1beta1 import ( + "github.com/openstack-k8s-operators/lib-common/modules/common/util" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -34,6 +35,8 @@ type ManilaDefaults struct { APIContainerImageURL string SchedulerContainerImageURL string ShareContainerImageURL string + DBPurgeAge int + DBPurgeSchedule string } var manilaDefaults ManilaDefaults @@ -41,10 +44,19 @@ var manilaDefaults ManilaDefaults // log is for logging in this package. var manilalog = logf.Log.WithName("manila-resource") -// SetupManilaDefaults - initialize Manila spec defaults for use with either internal or external webhooks -func SetupManilaDefaults(defaults ManilaDefaults) { - manilaDefaults = defaults - manilalog.Info("Manila defaults initialized", "defaults", defaults) +// SetupDefaults - initializes any CRD field defaults based on environment variables +// (the defaulting mechanism itself is implemented via webhooks) +func SetupDefaults() { + // Acquire environmental defaults and initialize Manila defaults with them + manilaDefaults = ManilaDefaults{ + 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, + } + + manilalog.Info("Manila defaults initialized", "defaults", manilaDefaults) } // SetupWebhookWithManager sets up the webhook with the Manager @@ -82,6 +94,14 @@ func (spec *ManilaSpec) Default() { spec.ManilaShares[key] = manilaShare } } + + if spec.DBPurge.Age == 0 { + spec.DBPurge.Age = manilaDefaults.DBPurgeAge + } + + if spec.DBPurge.Schedule == "" { + 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 baddda24..30ddeaa5 100644 --- a/config/crd/bases/manila.openstack.org_manilas.yaml +++ b/config/crd/bases/manila.openstack.org_manilas.yaml @@ -44,6 +44,15 @@ spec: databaseUser: default: manila type: string + dbPurge: + properties: + age: + default: 30 + type: integer + schedule: + default: 1 0 * * * + type: string + type: object debug: properties: dbPurge: 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..0e22ad09 100644 --- a/pkg/manila/cronjob.go +++ b/pkg/manila/cronjob.go @@ -16,6 +16,7 @@ limitations under the License. package manila import ( + "fmt" manilav1 "github.com/openstack-k8s-operators/manila-operator/api/v1beta1" batchv1 "k8s.io/api/batch/v1" @@ -36,7 +37,6 @@ func CronJob( ) *batchv1.CronJob { var config0644AccessMode int32 = 0644 var DBPurgeCommand []string = DBPurgeCommandBase[:] - args := []string{"-c"} if !instance.Spec.Debug.DBPurge { // If debug mode is not requested, remove the --debug option @@ -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 := []string{"-c", DBPurgeCommandString + strconv.Itoa(instance.Spec.DBPurge.Age)} parallelism := int32(1) completions := int32(1) @@ -79,11 +79,12 @@ func CronJob( cronjob := &batchv1.CronJob{ ObjectMeta: metav1.ObjectMeta{ - Name: ServiceName + "-cron", + Name: fmt.Sprintf("%s-db-purge", ServiceName), Namespace: instance.Namespace, + Labels: labels, }, Spec: batchv1.CronJobSpec{ - Schedule: DBPurgeDefaultSchedule, + Schedule: instance.Spec.DBPurge.Schedule, ConcurrencyPolicy: batchv1.ForbidConcurrent, JobTemplate: batchv1.JobTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ @@ -94,10 +95,14 @@ func CronJob( Parallelism: ¶llelism, Completions: &completions, Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: annotations, + Labels: labels, + }, Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: ServiceName + "-cron", + Name: fmt.Sprintf("%s-db-purge", ServiceName), Image: instance.Spec.ManilaAPI.ContainerImage, Command: []string{ "/bin/bash", diff --git a/test/kuttl/common/assert_sample_deployment.yaml b/test/kuttl/common/assert_sample_deployment.yaml index 2b682410..ddd96705 100644 --- a/test/kuttl/common/assert_sample_deployment.yaml +++ b/test/kuttl/common/assert_sample_deployment.yaml @@ -128,7 +128,7 @@ status: apiVersion: batch/v1 kind: CronJob metadata: - name: manila-cron + name: manila-db-purge spec: jobTemplate: metadata: @@ -146,7 +146,7 @@ spec: db purge 30 command: - /bin/bash - name: manila-cron + name: manila-db-purge volumeMounts: - mountPath: /etc/manila/manila.conf.d name: db-purge-config-data diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index 906da730..64612e48 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -1,7 +1,7 @@ --- - job: name: manila-operator-kuttl - parent: cifmw-multinode-kuttl + parent: cifmw-base-multinode-kuttl attempts: 1 vars: cifmw_kuttl_tests_env_vars: diff --git a/zuul.d/projects.yaml b/zuul.d/projects.yaml index 52fd57f4..bd5dd58f 100644 --- a/zuul.d/projects.yaml +++ b/zuul.d/projects.yaml @@ -7,3 +7,4 @@ - manila-operator-kuttl: dependencies: - openstack-k8s-operators-content-provider + voting: false