From 70595cd7e0754b98c7d2a8b6d1b8bc0b9d0134b8 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Fri, 20 Dec 2024 11:34:18 +0000 Subject: [PATCH] fixup! fixup! fixup! fixup! fixup! fixup! fixup! Ensure that jobs run with the controller service account if no service account is specified. --- chart/Chart.yaml | 4 ++-- chart/values.yaml | 2 +- .../raczylo.com/clusterimage_controller.go | 21 ++++++++++++++++--- internal/shared/jobs.go | 1 + 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/chart/Chart.yaml b/chart/Chart.yaml index a838274..46c7473 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -10,9 +10,9 @@ description: | type: application -version: 0.2.22 +version: 0.2.24 -appVersion: "0.2.22" +appVersion: "0.2.24" home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator diff --git a/chart/values.yaml b/chart/values.yaml index 0666733..e66365d 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -12,7 +12,7 @@ sa: - ALL image: repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator - tag: 0.2.22 + tag: 0.2.24 resources: limits: cpu: 500m diff --git a/internal/controller/raczylo.com/clusterimage_controller.go b/internal/controller/raczylo.com/clusterimage_controller.go index 21eb73c..c6cd023 100644 --- a/internal/controller/raczylo.com/clusterimage_controller.go +++ b/internal/controller/raczylo.com/clusterimage_controller.go @@ -138,12 +138,27 @@ func (r *ClusterImageReconciler) handleRunningClusterImage(ctx context.Context, if err != nil { if errors.IsNotFound(err) { - // Job doesn't exist, set status back to PENDING - clusterImage.Status.Progress = shared.STATUS_PENDING + l.Info("Job not found; assuming it completed successfully", "job", jobName) + + if clusterImage.Status.Progress == shared.STATUS_SUCCESS || clusterImage.Status.Progress == shared.STATUS_PRESENT { + // Job completed and status is already SUCCESS or PRESENT + return ctrl.Result{}, nil + } + + // If we have retries left, consider retrying + if clusterImage.Status.RetryCount < 3 { + clusterImage.Status.Progress = shared.STATUS_RETRYING + clusterImage.Status.RetryCount++ + } else { + // Exceeded retries; mark as FAILED + clusterImage.Status.Progress = shared.STATUS_FAILED + } + if err := r.Status().Update(ctx, clusterImage); err != nil { - l.Error(err, "unable to update ClusterImage status back to PENDING") + l.Error(err, "unable to update ClusterImage status after job not found") return ctrl.Result{}, err } + return ctrl.Result{Requeue: true}, nil } l.Error(err, "unable to check for existing job") diff --git a/internal/shared/jobs.go b/internal/shared/jobs.go index cd57f34..58862ee 100644 --- a/internal/shared/jobs.go +++ b/internal/shared/jobs.go @@ -62,6 +62,7 @@ func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job Annotations: params.Annotations, }, Spec: batchv1.JobSpec{ + TTLSecondsAfterFinished: pointer.Int32(300), Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{