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

fix: controller panics due to missing defaults #340

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions api/install/v1alpha1/scheduler_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ func (r *Scheduler) Default() {
}
}

if r.Spec.Pruner == nil {
dejanzele marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/install/armadaserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/install/common_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,7 @@ func defaultDeploymentStrategy(maxUnavailable int32) appsv1.DeploymentStrategy {
},
}
}

func defaultAlpineImage() string {
return "alpine:3.20"
}
10 changes: 5 additions & 5 deletions internal/controller/install/lookout_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ func createLookoutMigrationJob(lookout *installv1alpha1.Lookout, serviceAccountN
Command: []string{
"/bin/sh",
"-c",
`echo "Waiting for Postres..."
`echo "Waiting for Postgres..."
while ! nc -z $PGHOST $PGPORT; do
sleep 1
done
echo "Postres started!"
echo "Postgres started!"
echo "Creating DB $PGDB if needed..."
psql -v ON_ERROR_STOP=1 --username "$PGUSER" -c "CREATE DATABASE $PGDB"
psql -v ON_ERROR_STOP=1 --username "$PGUSER" -c "GRANT ALL PRIVILEGES ON DATABASE $PGDB TO $PGUSER"
Expand Down Expand Up @@ -503,15 +503,15 @@ 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",
`echo "Waiting for Postres..."
`echo "Waiting for Postgres..."
while ! nc -z $PGHOST $PGPORT; do
sleep 1
done
echo "Postres started!"`,
echo "Postgres started!"`,
},
Env: []corev1.EnvVar{
{
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/install/lookout_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,15 +829,15 @@ 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",
`echo "Waiting for Postres..."
`echo "Waiting for Postgres..."
while ! nc -z $PGHOST $PGPORT; do
sleep 1
done
echo "Postres started!"`,
echo "Postgres started!"`,
},
Env: []corev1.EnvVar{
{
Expand Down
35 changes: 18 additions & 17 deletions internal/controller/install/scheduler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func newSchedulerMigrationJob(scheduler *installv1alpha1.Scheduler, serviceAccou
Command: []string{
"/bin/sh",
"-c",
`echo "Waiting for Postres..."
`echo "Waiting for Postgres..."
while ! nc -z $PGHOST $PGPORT; do
sleep 1
done
Expand Down Expand Up @@ -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"
Expand All @@ -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{
Expand All @@ -543,15 +544,15 @@ 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",
`echo "Waiting for Postres..."
`echo "Waiting for Postgres..."
while ! nc -z $PGHOST $PGPORT; do
sleep 1
done
echo "Postres started!"`,
echo "Postgres started!"`,
},
Env: []corev1.EnvVar{
{
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/install/scheduler_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,15 +1026,15 @@ 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
echo "Postres started!"`,
echo "Postgres started!"`,
},
Env: []corev1.EnvVar{
{
Expand Down
Loading