From 6131e5bbea66dcfb87207bbe9445531c897e0e33 Mon Sep 17 00:00:00 2001 From: Dejan Zele Pejchev Date: Tue, 26 Nov 2024 13:43:59 +0100 Subject: [PATCH] fix controller panics due to missing defaults Signed-off-by: Dejan Zele Pejchev --- api/install/v1alpha1/scheduler_webhook.go | 18 ++++++++++++ .../install/armadaserver_controller.go | 2 +- internal/controller/install/common_helpers.go | 4 +++ .../controller/install/lookout_controller.go | 2 +- .../install/lookout_controller_test.go | 2 +- .../install/scheduler_controller.go | 29 ++++++++++--------- .../install/scheduler_controller_test.go | 4 +-- 7 files changed, 42 insertions(+), 19 deletions(-) diff --git a/api/install/v1alpha1/scheduler_webhook.go b/api/install/v1alpha1/scheduler_webhook.go index b60d6799..c853a33e 100644 --- a/api/install/v1alpha1/scheduler_webhook.go +++ b/api/install/v1alpha1/scheduler_webhook.go @@ -83,6 +83,24 @@ func (r *Scheduler) Default() { } } + if r.Spec.Pruner == nil { + r.Spec.Pruner = &PrunerConfig{ + Schedule: "@hourly", + } + if r.Spec.Pruner.Resources == nil { + r.Spec.Pruner.Resources = &corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + "cpu": resource.MustParse("300m"), + "memory": resource.MustParse("1Gi"), + }, + Requests: corev1.ResourceList{ + "cpu": resource.MustParse("200m"), + "memory": resource.MustParse("512Mi"), + }, + } + } + } + // prometheus if r.Spec.Prometheus != nil && r.Spec.Prometheus.Enabled { if r.Spec.Prometheus.ScrapeInterval == nil { diff --git a/internal/controller/install/armadaserver_controller.go b/internal/controller/install/armadaserver_controller.go index 3dd642bf..a94b0b6e 100644 --- a/internal/controller/install/armadaserver_controller.go +++ b/internal/controller/install/armadaserver_controller.go @@ -316,7 +316,7 @@ func createArmadaServerMigrationJobs(as *installv1alpha1.ArmadaServer, commonCon Containers: []corev1.Container{{ Name: "wait-for-pulsar", ImagePullPolicy: corev1.PullIfNotPresent, - Image: "alpine:3.16", + Image: defaultAlpineImage(), Args: []string{ "/bin/sh", "-c", diff --git a/internal/controller/install/common_helpers.go b/internal/controller/install/common_helpers.go index 0067c349..e7e6c7f8 100644 --- a/internal/controller/install/common_helpers.go +++ b/internal/controller/install/common_helpers.go @@ -866,3 +866,7 @@ func defaultDeploymentStrategy(maxUnavailable int32) appsv1.DeploymentStrategy { }, } } + +func defaultAlpineImage() string { + return "alpine:3.20" +} diff --git a/internal/controller/install/lookout_controller.go b/internal/controller/install/lookout_controller.go index 3dd6ebf1..0557a88c 100644 --- a/internal/controller/install/lookout_controller.go +++ b/internal/controller/install/lookout_controller.go @@ -503,7 +503,7 @@ func createLookoutCronJob(lookout *installv1alpha1.Lookout, serviceAccountName s SecurityContext: lookout.Spec.PodSecurityContext, InitContainers: []corev1.Container{{ Name: "lookout-db-pruner-db-wait", - Image: "alpine:3.10", + Image: defaultAlpineImage(), Command: []string{ "/bin/sh", "-c", diff --git a/internal/controller/install/lookout_controller_test.go b/internal/controller/install/lookout_controller_test.go index 113b9a24..94105f85 100644 --- a/internal/controller/install/lookout_controller_test.go +++ b/internal/controller/install/lookout_controller_test.go @@ -829,7 +829,7 @@ func TestLookoutReconciler_CreateCronJob(t *testing.T) { InitContainers: []corev1.Container{ { Name: "lookout-db-pruner-db-wait", - Image: "alpine:3.10", + Image: defaultAlpineImage(), Command: []string{ "/bin/sh", "-c", diff --git a/internal/controller/install/scheduler_controller.go b/internal/controller/install/scheduler_controller.go index 810efc58..0f089e72 100644 --- a/internal/controller/install/scheduler_controller.go +++ b/internal/controller/install/scheduler_controller.go @@ -494,18 +494,20 @@ func newSchedulerCronJob(scheduler *installv1alpha1.Scheduler, serviceAccountNam appConfigFlag, appConfigFilepath, } - if scheduler.Spec.Pruner.Args.Timeout != "" { - prunerArgs = append(prunerArgs, "--timeout", scheduler.Spec.Pruner.Args.Timeout) - } - if scheduler.Spec.Pruner.Args.Batchsize > 0 { - prunerArgs = append(prunerArgs, "--batchsize", fmt.Sprintf("%v", scheduler.Spec.Pruner.Args.Batchsize)) - } - if scheduler.Spec.Pruner.Args.ExpireAfter != "" { - prunerArgs = append(prunerArgs, "--expireAfter", scheduler.Spec.Pruner.Args.ExpireAfter) - } - prunerResources := corev1.ResourceRequirements{} - if scheduler.Spec.Pruner.Resources != nil { - prunerResources = *scheduler.Spec.Pruner.Resources + var prunerResources corev1.ResourceRequirements + if pruner := scheduler.Spec.Pruner; pruner != nil { + if pruner.Args.Timeout != "" { + prunerArgs = append(prunerArgs, "--timeout", scheduler.Spec.Pruner.Args.Timeout) + } + if pruner.Args.Batchsize > 0 { + prunerArgs = append(prunerArgs, "--batchsize", fmt.Sprintf("%v", scheduler.Spec.Pruner.Args.Batchsize)) + } + if pruner.Args.ExpireAfter != "" { + prunerArgs = append(prunerArgs, "--expireAfter", scheduler.Spec.Pruner.Args.ExpireAfter) + } + if pruner.Resources != nil { + prunerResources = *scheduler.Spec.Pruner.Resources + } } name := scheduler.Name + "-db-pruner" @@ -518,7 +520,6 @@ func newSchedulerCronJob(scheduler *installv1alpha1.Scheduler, serviceAccountNam Annotations: map[string]string{"checksum/config": GenerateChecksumConfig(scheduler.Spec.ApplicationConfig.Raw)}, }, Spec: batchv1.CronJobSpec{ - Schedule: scheduler.Spec.Pruner.Schedule, JobTemplate: batchv1.JobTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ @@ -543,7 +544,7 @@ func newSchedulerCronJob(scheduler *installv1alpha1.Scheduler, serviceAccountNam SecurityContext: scheduler.Spec.PodSecurityContext, InitContainers: []corev1.Container{{ Name: "scheduler-db-pruner-db-wait", - Image: "alpine:3.10", + Image: defaultAlpineImage(), Command: []string{ "/bin/sh", "-c", diff --git a/internal/controller/install/scheduler_controller_test.go b/internal/controller/install/scheduler_controller_test.go index d716173d..2eaf26ef 100644 --- a/internal/controller/install/scheduler_controller_test.go +++ b/internal/controller/install/scheduler_controller_test.go @@ -1026,11 +1026,11 @@ func TestSchedulerReconciler_createSchedulerCronJob(t *testing.T) { InitContainers: []corev1.Container{ { Name: "scheduler-db-pruner-db-wait", - Image: "alpine:3.10", + Image: defaultAlpineImage(), Command: []string{ "/bin/sh", "-c", - `echo "Waiting for Postres..." + `echo "Waiting for Postgres..." while ! nc -z $PGHOST $PGPORT; do sleep 1 done