From 7fb273555d0bbfde2a313890d2bc8448702f2a5c Mon Sep 17 00:00:00 2001 From: Amit Berner Date: Thu, 9 Nov 2023 15:26:57 +0200 Subject: [PATCH] controllers: insert ConcurrencyPolicy field to CronJob added the capability to keep resources on failed job execution with a timeout Signed-off-by: Amit Berner --- controllers/storageclient_controller.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/controllers/storageclient_controller.go b/controllers/storageclient_controller.go index 603d3015..1ae6e5ed 100644 --- a/controllers/storageclient_controller.go +++ b/controllers/storageclient_controller.go @@ -433,14 +433,24 @@ func (s *StorageClientReconciler) reconcileClientStatusReporterJob(instance *v1a cronJob.Namespace = s.OperatorNamespace addLabel(cronJob, storageClientNameLabel, instance.Name) addLabel(cronJob, storageClientNamespaceLabel, instance.Namespace) + var podDeadLineSeconds int64 = 120 + jobDeadLineSeconds := podDeadLineSeconds + 35 + var keepJobResourceSeconds int32 = 600 + var reducedKeptSuccecsful int32 = 1 + _, err := controllerutil.CreateOrUpdate(s.ctx, s.Client, cronJob, func() error { cronJob.Spec = batchv1.CronJobSpec{ Schedule: "* * * * *", + ConcurrencyPolicy: batchv1.ForbidConcurrent, + SuccessfulJobsHistoryLimit: &reducedKeptSuccecsful, JobTemplate: batchv1.JobTemplateSpec{ Spec: batchv1.JobSpec{ + ActiveDeadlineSeconds: &jobDeadLineSeconds, + TTLSecondsAfterFinished: &keepJobResourceSeconds, Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ + ActiveDeadlineSeconds: &podDeadLineSeconds, Containers: []corev1.Container{ { Name: "heartbeat",