Skip to content

Commit

Permalink
Merge pull request #436 from fmount/expose_cronjob_params
Browse files Browse the repository at this point in the history
Expose DBPurge Age and Schedule
  • Loading branch information
openshift-merge-bot[bot] authored Feb 5, 2024
2 parents 007aeec + 8b44f08 commit 7c87bfa
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 12 deletions.
12 changes: 11 additions & 1 deletion api/bases/glance.openstack.org_glances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 18 additions & 2 deletions api/v1beta1/glance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions api/v1beta1/glance_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
// GlanceDefaults -
type GlanceDefaults struct {
ContainerImageURL string
DBPurgeAge int
DBPurgeSchedule string
}

var glanceDefaults GlanceDefaults
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion config/crd/bases/glance.openstack.org_glances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions pkg/glance/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
8 changes: 4 additions & 4 deletions pkg/glance/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:]...)
}
Expand Down

0 comments on commit 7c87bfa

Please sign in to comment.