diff --git a/api/bases/glance.openstack.org_glances.yaml b/api/bases/glance.openstack.org_glances.yaml index bcce2f79..f1c7eb91 100644 --- a/api/bases/glance.openstack.org_glances.yaml +++ b/api/bases/glance.openstack.org_glances.yaml @@ -49,9 +49,19 @@ spec: databaseUser: default: glance type: string + dbPurge: + properties: + age: + default: 30 + minimum: 1 + type: integer + schedule: + default: 1 0 * * * + type: string + type: object debug: properties: - cronJob: + dbPurge: default: false type: boolean type: object diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index c6c9fe9f..0fe83679 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -39,6 +39,10 @@ const ( // GlanceAPIContainerImage is the fall-back container image for GlanceAPI GlanceAPIContainerImage = "quay.io/podified-antelope-centos9/openstack-glance-api: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 * * *" ) // GlanceAPITemplate defines the desired state of GlanceAPI @@ -117,6 +121,8 @@ func SetupDefaults() { // Acquire environmental defaults and initialize Glance defaults with them glanceDefaults := GlanceDefaults{ ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_GLANCE_API_IMAGE_URL_DEFAULT", GlanceAPIContainerImage), + DBPurgeAge: DBPurgeDefaultAge, + DBPurgeSchedule: DBPurgeDefaultSchedule, } SetupGlanceDefaults(glanceDefaults) diff --git a/api/v1beta1/glance_types.go b/api/v1beta1/glance_types.go index 45f91505..9616f8be 100644 --- a/api/v1beta1/glance_types.go +++ b/api/v1beta1/glance_types.go @@ -124,6 +124,9 @@ type GlanceSpec struct { // keystone catalog, and it acts as a selector for the underlying glanceAPI(s) // that can be specified by name KeystoneEndpoint string `json:"keystoneEndpoint"` + // +kubebuilder:validation:Optional + // DBPurge parameters - + DBPurge DBPurge `json:"dbPurge,omitempty"` } // PasswordSelector to identify the DB and AdminUser password from the Secret @@ -139,12 +142,25 @@ type PasswordSelector struct { Service string `json:"service"` } +// DBPurge struct is used to model the parameters exposed to the Glance API CronJob +type DBPurge struct { + // +kubebuilder:validation:Optional + // +kubebuilder:default=30 + // +kubebuilder:validation:Minimum=1 + // 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"` +} + // GlanceDebug defines the observed state of GlanceAPIDebug type GlanceDebug struct { // +kubebuilder:validation:Optional // +kubebuilder:default=false - // CronJob enable debug - CronJob bool `json:"cronJob"` + // DBPurge increases log verbosity by executing the db_purge command with "--debug". + DBPurge bool `json:"dbPurge"` } // GlanceStatus defines the observed state of Glance diff --git a/api/v1beta1/glance_webhook.go b/api/v1beta1/glance_webhook.go index fc8c862d..78cf03d0 100644 --- a/api/v1beta1/glance_webhook.go +++ b/api/v1beta1/glance_webhook.go @@ -29,6 +29,8 @@ import ( // GlanceDefaults - type GlanceDefaults struct { ContainerImageURL string + DBPurgeAge int + DBPurgeSchedule string } var glanceDefaults GlanceDefaults @@ -84,6 +86,14 @@ func (spec *GlanceSpec) Default() { if len(spec.ContainerImage) == 0 { spec.ContainerImage = glanceDefaults.ContainerImageURL } + + if spec.DBPurge.Age == 0 { + spec.DBPurge.Age = glanceDefaults.DBPurgeAge + } + + if spec.DBPurge.Schedule == "" { + spec.DBPurge.Schedule = glanceDefaults.DBPurgeSchedule + } // When no glanceAPI(s) are specified in the top-level CR // we build one by default, but we set replicas=0 and we // build a "CustomServiceConfig" template that should be diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index d2c225a3..01865c19 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 *Glance) DeepCopyInto(out *Glance) { *out = *in @@ -382,6 +397,7 @@ func (in *GlanceSpec) DeepCopyInto(out *GlanceSpec) { } } out.Quotas = in.Quotas + out.DBPurge = in.DBPurge } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GlanceSpec. diff --git a/config/crd/bases/glance.openstack.org_glances.yaml b/config/crd/bases/glance.openstack.org_glances.yaml index bcce2f79..f1c7eb91 100644 --- a/config/crd/bases/glance.openstack.org_glances.yaml +++ b/config/crd/bases/glance.openstack.org_glances.yaml @@ -49,9 +49,19 @@ spec: databaseUser: default: glance type: string + dbPurge: + properties: + age: + default: 30 + minimum: 1 + type: integer + schedule: + default: 1 0 * * * + type: string + type: object debug: properties: - cronJob: + dbPurge: default: false type: boolean type: object diff --git a/pkg/glance/const.go b/pkg/glance/const.go index d94481ac..1ba3b6cc 100644 --- a/pkg/glance/const.go +++ b/pkg/glance/const.go @@ -77,16 +77,12 @@ const ( // endpoints in keystone KeystoneEndpoint = "keystoneEndpoint" - //DBPurgeAge - - DBPurgeAge = 30 //DBPurge - DBPurge CronJobType = "purge" //CacheCleaner - CacheCleaner CronJobType = "cleaner" //CachePruner - CachePruner CronJobType = "pruner" - //DBPurgeDefaultSchedule - - DBPurgeDefaultSchedule = "1 0 * * *" //CacheCleanerDefaultSchedule - CacheCleanerDefaultSchedule = "1 0 * * *" //CachePrunerDefaultSchedule - diff --git a/pkg/glance/cronjob.go b/pkg/glance/cronjob.go index 17d2fb7a..854c19db 100644 --- a/pkg/glance/cronjob.go +++ b/pkg/glance/cronjob.go @@ -43,8 +43,8 @@ func CronJob( case "purge": cronJobCommand = DBPurgeCommandBase[:] // Extend the resulting command with the DBPurgeAge int in case purge is - cronJobCommand = append(cronJobCommand, strconv.Itoa(DBPurgeAge)) - cronJobSchedule = DBPurgeDefaultSchedule + cronJobCommand = append(cronJobCommand, strconv.Itoa(instance.Spec.DBPurge.Age)) + cronJobSchedule = instance.Spec.DBPurge.Schedule case "cleaner": cronJobCommand = CacheCleanerCommandBase[:] cronJobSchedule = CacheCleanerDefaultSchedule @@ -53,13 +53,13 @@ func CronJob( cronJobSchedule = CachePrunerDefaultSchedule default: cronJobCommand = DBPurgeCommandBase[:] - cronJobSchedule = DBPurgeDefaultSchedule + cronJobSchedule = instance.Spec.DBPurge.Schedule } var cronCommand []string = cronJobCommand[:] args := []string{"-c"} - if !instance.Spec.Debug.CronJob { + if !instance.Spec.Debug.DBPurge { // If debug mode is not requested, remove the --debug option cronCommand = append(cronJobCommand[:1], cronJobCommand[2:]...) }