fixup! fixup! fixup! General improvements

This commit is contained in:
2025-01-10 12:19:37 +00:00
parent 3a5b22bb0b
commit 23345c56c6
2 changed files with 20 additions and 11 deletions
@@ -316,6 +316,10 @@ func (r *ClusterImageExportReconciler) runCleanupJob(ctx context.Context, cluste
defaultCommands = append(defaultCommands, additionalCommands...) defaultCommands = append(defaultCommands, additionalCommands...)
} }
// Set up the cleanup job with retry limits and TTL
backoffLimit := int32(2) // 3 total attempts (initial + 2 retries)
ttlSecondsAfterFinished := int32(30) // Delete job 30 seconds after completion
jobParams := shared.JobParams{ jobParams := shared.JobParams{
Name: normalisedImageName, Name: normalisedImageName,
Namespace: clusterImageExport.Namespace, Namespace: clusterImageExport.Namespace,
@@ -324,6 +328,8 @@ func (r *ClusterImageExportReconciler) runCleanupJob(ctx context.Context, cluste
Annotations: clusterImageExport.Spec.JobAnnotations, Annotations: clusterImageExport.Spec.JobAnnotations,
ServiceAccount: "", ServiceAccount: "",
ImagePullSecrets: clusterImageExport.Spec.ImagePullSecrets, ImagePullSecrets: clusterImageExport.Spec.ImagePullSecrets,
BackoffLimit: &backoffLimit,
TTLSecondsAfterFinished: &ttlSecondsAfterFinished,
} }
cleanupJob := shared.CreateJob(jobParams, func(raczylocomv1.ClusterImageExport) []string { return nil }) cleanupJob := shared.CreateJob(jobParams, func(raczylocomv1.ClusterImageExport) []string { return nil })
@@ -334,5 +340,5 @@ func (r *ClusterImageExportReconciler) runCleanupJob(ctx context.Context, cluste
return return
} }
l.Info("Created cleanup job") l.Info("Created cleanup job with retry limit and TTL")
} }
+13 -10
View File
@@ -13,15 +13,17 @@ import (
) )
type JobParams struct { type JobParams struct {
Name string Name string
Namespace string Namespace string
Annotations map[string]string Annotations map[string]string
Image string Image string
Commands []string Commands []string
EnvVars []corev1.EnvVar EnvVars []corev1.EnvVar
OwnerReferences []metav1.OwnerReference OwnerReferences []metav1.OwnerReference
ServiceAccount string // Can be empty to use controller's service account ServiceAccount string // Can be empty to use controller's service account
ImagePullSecrets []corev1.LocalObjectReference ImagePullSecrets []corev1.LocalObjectReference
BackoffLimit *int32 // Optional: number of retries before marking the job as failed
TTLSecondsAfterFinished *int32 // Optional: seconds after which completed/failed job is automatically deleted
} }
func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job { func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job {
@@ -62,7 +64,8 @@ func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job
Annotations: params.Annotations, Annotations: params.Annotations,
}, },
Spec: batchv1.JobSpec{ Spec: batchv1.JobSpec{
TTLSecondsAfterFinished: pointer.Int32(300), BackoffLimit: params.BackoffLimit,
TTLSecondsAfterFinished: params.TTLSecondsAfterFinished,
Template: corev1.PodTemplateSpec{ Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{