Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose DBPurge Age and Schedule #170

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
age:
default: 30
type: integer
schedule:
default: 1 0 * * *
type: string
type: object
debug:
properties:
dbPurge:
Expand Down
30 changes: 4 additions & 26 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1beta1

import (
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
corev1 "k8s.io/api/core/v1"
)

Expand All @@ -30,6 +29,10 @@ const (
ManilaSchedulerContainerImage = "quay.io/podified-antelope-centos9/openstack-manila-scheduler:current-podified"
// ManilaShareContainerImage is the fall-back container image for ManilaShare
ManilaShareContainerImage = "quay.io/podified-antelope-centos9/openstack-manila-share: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 * * *"
)

// ManilaTemplate defines common input parameters used by all Manila services
Expand Down Expand Up @@ -114,19 +117,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 All @@ -135,15 +125,3 @@ type ManilaServiceDebug struct {
// service enable debug
Service bool `json:"service,omitempty"`
}

// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
func SetupDefaults() {
// Acquire environmental defaults and initialize Manila defaults with them
manilaDefaults := ManilaDefaults{
APIContainerImageURL: util.GetEnvVar("RELATED_IMAGE_MANILA_API_IMAGE_URL_DEFAULT", ManilaAPIContainerImage),
SchedulerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_MANILA_SCHEDULER_IMAGE_URL_DEFAULT", ManilaSchedulerContainerImage),
ShareContainerImageURL: util.GetEnvVar("RELATED_IMAGE_MANILA_SHARE_IMAGE_URL_DEFAULT", ManilaShareContainerImage),
}

SetupManilaDefaults(manilaDefaults)
}
29 changes: 29 additions & 0 deletions api/v1beta1/manila_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,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 -
DBPurge DBPurge `json:"dbPurge,omitempty"`
}

// ManilaStatus defines the observed state of Manila
Expand Down Expand Up @@ -148,6 +152,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
ASBishop marked this conversation as resolved.
Show resolved Hide resolved
// Age is the DBPurgeAge parameter and indicates the number of days of purging DB records
Age int `json:"age"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you add the "+kubebuilder:validation:Minimum=1" in this PR (after CI issues are resolved) or in a follow-up patch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to add this line in a follow up patch because I have that one line change that allows me to focus more on the CI (zuul based) execution rather than the change introduced by the patch.

// +kubebuilder:validation:Optional
// +kubebuilder:default="1 0 * * *"
//Schedule defines the crontab format string to schedule the DBPurge cronJob
Schedule string `json:"schedule"`
}

// ManilaDebug contains flags related to multiple debug activities. See the
// individual comments for what this means for each flag.
type ManilaDebug struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default=false
// DBSync pauses the dbSync container instead of executing the db_sync command.
DBSync bool `json:"dbSync,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:default=false
// DBPurge increases log verbosity by executing the db_purge command with "--debug".
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
28 changes: 24 additions & 4 deletions api/v1beta1/manila_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ limitations under the License.
package v1beta1

import (
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -34,17 +35,28 @@ type ManilaDefaults struct {
APIContainerImageURL string
SchedulerContainerImageURL string
ShareContainerImageURL string
DBPurgeAge int
DBPurgeSchedule string
}

var manilaDefaults ManilaDefaults

// log is for logging in this package.
var manilalog = logf.Log.WithName("manila-resource")

// SetupManilaDefaults - initialize Manila spec defaults for use with either internal or external webhooks
func SetupManilaDefaults(defaults ManilaDefaults) {
manilaDefaults = defaults
manilalog.Info("Manila defaults initialized", "defaults", defaults)
// SetupDefaults - initializes any CRD field defaults based on environment variables
// (the defaulting mechanism itself is implemented via webhooks)
func SetupDefaults() {
// Acquire environmental defaults and initialize Manila defaults with them
manilaDefaults = ManilaDefaults{
APIContainerImageURL: util.GetEnvVar("RELATED_IMAGE_MANILA_API_IMAGE_URL_DEFAULT", ManilaAPIContainerImage),
SchedulerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_MANILA_SCHEDULER_IMAGE_URL_DEFAULT", ManilaSchedulerContainerImage),
ShareContainerImageURL: util.GetEnvVar("RELATED_IMAGE_MANILA_SHARE_IMAGE_URL_DEFAULT", ManilaShareContainerImage),
DBPurgeAge: DBPurgeDefaultAge,
DBPurgeSchedule: DBPurgeDefaultSchedule,
}

manilalog.Info("Manila defaults initialized", "defaults", manilaDefaults)
}

// SetupWebhookWithManager sets up the webhook with the Manager
Expand Down Expand Up @@ -82,6 +94,14 @@ func (spec *ManilaSpec) Default() {
spec.ManilaShares[key] = manilaShare
}
}

if spec.DBPurge.Age == 0 {
spec.DBPurge.Age = manilaDefaults.DBPurgeAge
}

if spec.DBPurge.Schedule == "" {
spec.DBPurge.Schedule = manilaDefaults.DBPurgeSchedule
}
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
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:
age:
default: 30
type: integer
schedule:
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
15 changes: 10 additions & 5 deletions pkg/manila/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package manila

import (
"fmt"
manilav1 "github.com/openstack-k8s-operators/manila-operator/api/v1beta1"

batchv1 "k8s.io/api/batch/v1"
Expand All @@ -36,7 +37,6 @@ func CronJob(
) *batchv1.CronJob {
var config0644AccessMode int32 = 0644
var DBPurgeCommand []string = DBPurgeCommandBase[:]
args := []string{"-c"}

if !instance.Spec.Debug.DBPurge {
// If debug mode is not requested, remove the --debug option
Expand All @@ -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 := []string{"-c", DBPurgeCommandString + strconv.Itoa(instance.Spec.DBPurge.Age)}

parallelism := int32(1)
completions := int32(1)
Expand Down Expand Up @@ -79,11 +79,12 @@ func CronJob(

cronjob := &batchv1.CronJob{
ObjectMeta: metav1.ObjectMeta{
Name: ServiceName + "-cron",
Name: fmt.Sprintf("%s-db-purge", ServiceName),
Namespace: instance.Namespace,
Labels: labels,
},
Spec: batchv1.CronJobSpec{
Schedule: DBPurgeDefaultSchedule,
Schedule: instance.Spec.DBPurge.Schedule,
ConcurrencyPolicy: batchv1.ForbidConcurrent,
JobTemplate: batchv1.JobTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -94,10 +95,14 @@ func CronJob(
Parallelism: &parallelism,
Completions: &completions,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Annotations: annotations,
Labels: labels,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: ServiceName + "-cron",
Name: fmt.Sprintf("%s-db-purge", ServiceName),
Image: instance.Spec.ManilaAPI.ContainerImage,
Command: []string{
"/bin/bash",
Expand Down
4 changes: 2 additions & 2 deletions test/kuttl/common/assert_sample_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ status:
apiVersion: batch/v1
kind: CronJob
metadata:
name: manila-cron
name: manila-db-purge
spec:
jobTemplate:
metadata:
Expand All @@ -146,7 +146,7 @@ spec:
db purge 30
command:
- /bin/bash
name: manila-cron
name: manila-db-purge
volumeMounts:
- mountPath: /etc/manila/manila.conf.d
name: db-purge-config-data
Expand Down
2 changes: 1 addition & 1 deletion zuul.d/jobs.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- job:
name: manila-operator-kuttl
parent: cifmw-multinode-kuttl
parent: cifmw-base-multinode-kuttl
attempts: 1
vars:
cifmw_kuttl_tests_env_vars:
Expand Down
1 change: 1 addition & 0 deletions zuul.d/projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
- manila-operator-kuttl:
dependencies:
- openstack-k8s-operators-content-provider
voting: false