Skip to content

Commit

Permalink
Expose DBPurge Age and Schedule
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 dd80992
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 25 deletions.
13 changes: 11 additions & 2 deletions api/bases/manila.openstack.org_manilas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,21 @@ spec:
databaseUser:
default: manila
type: string
dbPurge:
properties:
age:
default: 30
type: integer
schedule:
default: 1 0 * * *
type: string
type: object
debug:
properties:
dbPurge:
dbSync:
default: false
type: boolean
dbSync:
debug:
default: false
type: boolean
type: object
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,omitempty"`
}

// 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
// Age -
Age int `json:"age"`
// +kubebuilder:validation:Optional
// +kubebuilder:default="1 0 * * *"
//Schedule -
Schedule string `json:"schedule"`
}

// 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
// DBPurgeDebug enables debug mode on the DBPurge CronJob
DBPurgeDebug bool `json:"debug,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.

13 changes: 11 additions & 2 deletions config/crd/bases/manila.openstack.org_manilas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,21 @@ spec:
databaseUser:
default: manila
type: string
dbPurge:
properties:
age:
default: 30
type: integer
schedule:
default: 1 0 * * *
type: string
type: object
debug:
properties:
dbPurge:
dbSync:
default: false
type: boolean
dbSync:
debug:
default: false
type: boolean
type: object
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
6 changes: 3 additions & 3 deletions pkg/manila/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ func CronJob(
var DBPurgeCommand []string = DBPurgeCommandBase[:]
args := []string{"-c"}

if !instance.Spec.Debug.DBPurge {
if !instance.Spec.Debug.DBPurgeDebug {
// If debug mode is not requested, remove the --debug option
DBPurgeCommand = append(DBPurgeCommandBase[:1], DBPurgeCommandBase[2:]...)
}
// Build the resulting command
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.Age))

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.Schedule,
ConcurrencyPolicy: batchv1.ForbidConcurrent,
JobTemplate: batchv1.JobTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit dd80992

Please sign in to comment.