diff --git a/chart/Chart.yaml b/chart/Chart.yaml index 1382627..863ddcb 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -10,9 +10,9 @@ description: | type: application -version: 0.2.30 +version: 0.2.31 -appVersion: "0.2.30" +appVersion: "0.2.31" home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator diff --git a/chart/values.yaml b/chart/values.yaml index 0f130fb..3b42884 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.30 + tag: 0.2.31 resources: limits: cpu: 500m diff --git a/internal/controller/raczylo.com/clusterimageexport_controller.go b/internal/controller/raczylo.com/clusterimageexport_controller.go index 51ec044..836bc1b 100644 --- a/internal/controller/raczylo.com/clusterimageexport_controller.go +++ b/internal/controller/raczylo.com/clusterimageexport_controller.go @@ -268,12 +268,32 @@ func (r *ClusterImageExportReconciler) handleDeletion(ctx context.Context, clust // Continue with deletion even if cleanup fails } - // Attempt to run cleanup job but don't block on errors - r.runCleanupJob(ctx, clusterImageExport) + // Check if cleanup job already exists + jobName := "cleanup-" + shared.NormalizeImageName(clusterImageExport.Name) + existingJob := &batchv1.Job{} + err := r.Get(ctx, client.ObjectKey{ + Namespace: clusterImageExport.Namespace, + Name: jobName, + }, existingJob) + + if err == nil { + // Job exists, don't create a new one + l.Info("Cleanup job already exists, skipping creation", "job", jobName) + } else if errors.IsNotFound(err) { + // Job doesn't exist, create it + r.runCleanupJob(ctx, clusterImageExport) + } else { + // Unexpected error, log but continue + l.Error(err, "Error checking for existing cleanup job") + } // Remove the finalizer regardless of cleanup job status controllerutil.RemoveFinalizer(clusterImageExport, clusterImageExportFinalizer) if err := r.Update(ctx, clusterImageExport); err != nil { + if errors.IsNotFound(err) { + // CRD is already gone, which is fine + return ctrl.Result{}, nil + } return ctrl.Result{}, err } }