Skip to content

Commit 8b44f08

Browse files
committed
Expose DBPurge Age and Schedule
This patch updates the current glance CR to expose both dbPurgeAge and dbPurgeSchedule as customizable parameters. They were previously hardcoded as constants in the code, and it makes sense removing that part as long as the human operator has the ability to customize them. This also aligns the glance-operator with the work already done in both Manila and Cinder. Signed-off-by: Francesco Pantano <[email protected]>
1 parent 007aeec commit 8b44f08

File tree

8 files changed

+76
-12
lines changed

8 files changed

+76
-12
lines changed

api/bases/glance.openstack.org_glances.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,19 @@ spec:
4949
databaseUser:
5050
default: glance
5151
type: string
52+
dbPurge:
53+
properties:
54+
age:
55+
default: 30
56+
minimum: 1
57+
type: integer
58+
schedule:
59+
default: 1 0 * * *
60+
type: string
61+
type: object
5262
debug:
5363
properties:
54-
cronJob:
64+
dbPurge:
5565
default: false
5666
type: boolean
5767
type: object

api/v1beta1/common_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const (
3939

4040
// GlanceAPIContainerImage is the fall-back container image for GlanceAPI
4141
GlanceAPIContainerImage = "quay.io/podified-antelope-centos9/openstack-glance-api:current-podified"
42+
//DBPurgeDefaultAge indicates the number of days of purging DB records
43+
DBPurgeDefaultAge = 30
44+
//DBPurgeDefaultSchedule is in crontab format, and the default runs the job once every day
45+
DBPurgeDefaultSchedule = "1 0 * * *"
4246
)
4347

4448
// GlanceAPITemplate defines the desired state of GlanceAPI
@@ -117,6 +121,8 @@ func SetupDefaults() {
117121
// Acquire environmental defaults and initialize Glance defaults with them
118122
glanceDefaults := GlanceDefaults{
119123
ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_GLANCE_API_IMAGE_URL_DEFAULT", GlanceAPIContainerImage),
124+
DBPurgeAge: DBPurgeDefaultAge,
125+
DBPurgeSchedule: DBPurgeDefaultSchedule,
120126
}
121127

122128
SetupGlanceDefaults(glanceDefaults)

api/v1beta1/glance_types.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ type GlanceSpec struct {
124124
// keystone catalog, and it acts as a selector for the underlying glanceAPI(s)
125125
// that can be specified by name
126126
KeystoneEndpoint string `json:"keystoneEndpoint"`
127+
// +kubebuilder:validation:Optional
128+
// DBPurge parameters -
129+
DBPurge DBPurge `json:"dbPurge,omitempty"`
127130
}
128131

129132
// PasswordSelector to identify the DB and AdminUser password from the Secret
@@ -139,12 +142,25 @@ type PasswordSelector struct {
139142
Service string `json:"service"`
140143
}
141144

145+
// DBPurge struct is used to model the parameters exposed to the Glance API CronJob
146+
type DBPurge struct {
147+
// +kubebuilder:validation:Optional
148+
// +kubebuilder:default=30
149+
// +kubebuilder:validation:Minimum=1
150+
// Age is the DBPurgeAge parameter and indicates the number of days of purging DB records
151+
Age int `json:"age"`
152+
// +kubebuilder:validation:Optional
153+
// +kubebuilder:default="1 0 * * *"
154+
//Schedule defines the crontab format string to schedule the DBPurge cronJob
155+
Schedule string `json:"schedule"`
156+
}
157+
142158
// GlanceDebug defines the observed state of GlanceAPIDebug
143159
type GlanceDebug struct {
144160
// +kubebuilder:validation:Optional
145161
// +kubebuilder:default=false
146-
// CronJob enable debug
147-
CronJob bool `json:"cronJob"`
162+
// DBPurge increases log verbosity by executing the db_purge command with "--debug".
163+
DBPurge bool `json:"dbPurge"`
148164
}
149165

150166
// GlanceStatus defines the observed state of Glance

api/v1beta1/glance_webhook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
// GlanceDefaults -
3030
type GlanceDefaults struct {
3131
ContainerImageURL string
32+
DBPurgeAge int
33+
DBPurgeSchedule string
3234
}
3335

3436
var glanceDefaults GlanceDefaults
@@ -84,6 +86,14 @@ func (spec *GlanceSpec) Default() {
8486
if len(spec.ContainerImage) == 0 {
8587
spec.ContainerImage = glanceDefaults.ContainerImageURL
8688
}
89+
90+
if spec.DBPurge.Age == 0 {
91+
spec.DBPurge.Age = glanceDefaults.DBPurgeAge
92+
}
93+
94+
if spec.DBPurge.Schedule == "" {
95+
spec.DBPurge.Schedule = glanceDefaults.DBPurgeSchedule
96+
}
8797
// When no glanceAPI(s) are specified in the top-level CR
8898
// we build one by default, but we set replicas=0 and we
8999
// build a "CustomServiceConfig" template that should be

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/glance.openstack.org_glances.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,19 @@ spec:
4949
databaseUser:
5050
default: glance
5151
type: string
52+
dbPurge:
53+
properties:
54+
age:
55+
default: 30
56+
minimum: 1
57+
type: integer
58+
schedule:
59+
default: 1 0 * * *
60+
type: string
61+
type: object
5262
debug:
5363
properties:
54-
cronJob:
64+
dbPurge:
5565
default: false
5666
type: boolean
5767
type: object

pkg/glance/const.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,12 @@ const (
7777
// endpoints in keystone
7878
KeystoneEndpoint = "keystoneEndpoint"
7979

80-
//DBPurgeAge -
81-
DBPurgeAge = 30
8280
//DBPurge -
8381
DBPurge CronJobType = "purge"
8482
//CacheCleaner -
8583
CacheCleaner CronJobType = "cleaner"
8684
//CachePruner -
8785
CachePruner CronJobType = "pruner"
88-
//DBPurgeDefaultSchedule -
89-
DBPurgeDefaultSchedule = "1 0 * * *"
9086
//CacheCleanerDefaultSchedule -
9187
CacheCleanerDefaultSchedule = "1 0 * * *"
9288
//CachePrunerDefaultSchedule -

pkg/glance/cronjob.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func CronJob(
4343
case "purge":
4444
cronJobCommand = DBPurgeCommandBase[:]
4545
// Extend the resulting command with the DBPurgeAge int in case purge is
46-
cronJobCommand = append(cronJobCommand, strconv.Itoa(DBPurgeAge))
47-
cronJobSchedule = DBPurgeDefaultSchedule
46+
cronJobCommand = append(cronJobCommand, strconv.Itoa(instance.Spec.DBPurge.Age))
47+
cronJobSchedule = instance.Spec.DBPurge.Schedule
4848
case "cleaner":
4949
cronJobCommand = CacheCleanerCommandBase[:]
5050
cronJobSchedule = CacheCleanerDefaultSchedule
@@ -53,13 +53,13 @@ func CronJob(
5353
cronJobSchedule = CachePrunerDefaultSchedule
5454
default:
5555
cronJobCommand = DBPurgeCommandBase[:]
56-
cronJobSchedule = DBPurgeDefaultSchedule
56+
cronJobSchedule = instance.Spec.DBPurge.Schedule
5757
}
5858

5959
var cronCommand []string = cronJobCommand[:]
6060
args := []string{"-c"}
6161

62-
if !instance.Spec.Debug.CronJob {
62+
if !instance.Spec.Debug.DBPurge {
6363
// If debug mode is not requested, remove the --debug option
6464
cronCommand = append(cronJobCommand[:1], cronJobCommand[2:]...)
6565
}

0 commit comments

Comments
 (0)