Skip to content

Commit

Permalink
Expose dbPurgeAge and dbPurgeSchedule to the top-level manila CR
Browse files Browse the repository at this point in the history
This patch updates the current manila 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.

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Oct 31, 2023
1 parent f492250 commit d72bb95
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 20 deletions.
9 changes: 9 additions & 0 deletions api/bases/manila.openstack.org_manilas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ spec:
databaseUser:
default: manila
type: string
dbPurge:
properties:
dbPurgeAge:
default: 30
type: integer
dbPurgeSchedule:
default: 1 0 * * *
type: string
type: object
debug:
properties:
dbPurge:
Expand Down
13 changes: 0 additions & 13 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,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 {
Expand Down
29 changes: 29 additions & 0 deletions api/v1beta1/manila_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
DBPurgeSpec DBPurge `json:"dbPurge"`
}

// ManilaStatus defines the observed state of Manila
Expand Down Expand Up @@ -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
// DBPurgeAge -
DBPurgeAge int `json:"dbPurgeAge"`
// +kubebuilder:validation:Optional
// +kubebuilder:default="1 0 * * *"
//DBPurgeSchedule -
DBPurgeSchedule string `json:"dbPurgeSchedule"`
}

// 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"`
}

// IsReady - returns true if Manila is reconciled successfully
func (instance Manila) IsReady() bool {
return instance.Status.Conditions.IsTrue(condition.ReadyCondition)
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.

9 changes: 9 additions & 0 deletions config/crd/bases/manila.openstack.org_manilas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ spec:
databaseUser:
default: manila
type: string
dbPurge:
properties:
dbPurgeAge:
default: 30
type: integer
dbPurgeSchedule:
default: 1 0 * * *
type: string
type: object
debug:
properties:
dbPurge:
Expand Down
5 changes: 0 additions & 5 deletions pkg/manila/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/manila/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.DBPurgeSpec.DBPurgeAge))

parallelism := int32(1)
completions := int32(1)
Expand Down Expand Up @@ -83,7 +83,7 @@ func CronJob(
Namespace: instance.Namespace,
},
Spec: batchv1.CronJobSpec{
Schedule: DBPurgeDefaultSchedule,
Schedule: instance.Spec.DBPurgeSpec.DBPurgeSchedule,
ConcurrencyPolicy: batchv1.ForbidConcurrent,
JobTemplate: batchv1.JobTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit d72bb95

Please sign in to comment.