diff --git a/charts/logan/templates/_helpers.tpl b/charts/logan/templates/_helpers.tpl index 1518d17..c721668 100644 --- a/charts/logan/templates/_helpers.tpl +++ b/charts/logan/templates/_helpers.tpl @@ -51,3 +51,19 @@ {{- "UNDEFINED" -}} {{- end -}} {{- end -}} + +#Add random offset for discovery job +{{- define "randomOffsetCronSchedule" -}} + {{- $cronSchedule := .Values.k8sDiscovery.objects.cronSchedule -}} + {{- $cronParts := regexSplit " " $cronSchedule -1 -}} + {{- $minutePart := index $cronParts 0 -}} + {{- if hasPrefix "*/" $minutePart -}} + {{- $interval := trimPrefix "*/" $minutePart | atoi -}} + {{- $intervalInt := int $interval -}} + {{- $randomOffset := randInt 0 $intervalInt -}} + {{- $newMinutePart := printf "%d/%d" $randomOffset $interval -}} + {{- printf "%s %s %s %s %s" $newMinutePart (index $cronParts 1) (index $cronParts 2) (index $cronParts 3) (index $cronParts 4) -}} + {{- else -}} + {{- $cronSchedule -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/logan/templates/discovery-cronjob.yaml b/charts/logan/templates/discovery-cronjob.yaml index 5b6444f..5bd102b 100644 --- a/charts/logan/templates/discovery-cronjob.yaml +++ b/charts/logan/templates/discovery-cronjob.yaml @@ -10,7 +10,7 @@ metadata: name: {{ .Values.global.resourceNamePrefix }}-discovery namespace: {{ $kubernetesNamespace }} spec: - schedule: {{ .Values.k8sDiscovery.objects.cronSchedule | quote }} + schedule: "{{ include "randomOffsetCronSchedule" . }}" startingDeadlineSeconds: 120 concurrencyPolicy: Forbid successfulJobsHistoryLimit: {{ .Values.k8sDiscovery.objects.successfulJobsHistoryLimit }}