From a31c82a9c142d0aabfddf5a3599417ac49bd0cf4 Mon Sep 17 00:00:00 2001 From: saksham Date: Thu, 27 Mar 2025 14:49:29 +0530 Subject: [PATCH] adding random offset to discvery cronjob --- charts/logan/Chart.yaml | 2 +- charts/logan/templates/_helpers.tpl | 16 ++++++++++++++++ charts/logan/templates/discovery-cronjob.yaml | 2 +- charts/oci-onm/Chart.yaml | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/charts/logan/Chart.yaml b/charts/logan/Chart.yaml index d8e0fd0..378679d 100644 --- a/charts/logan/Chart.yaml +++ b/charts/logan/Chart.yaml @@ -5,7 +5,7 @@ apiVersion: v2 name: oci-onm-logan description: Charts for sending Kubernetes platform logs, compute logs, and Kubernetes Objects information to OCI Logging Analytics. type: application -version: 3.5.3 +version: 3.5.4 appVersion: "3.0.0" dependencies: 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 85969fc..7e552fe 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: Replace successfulJobsHistoryLimit: {{ .Values.k8sDiscovery.objects.successfulJobsHistoryLimit }} diff --git a/charts/oci-onm/Chart.yaml b/charts/oci-onm/Chart.yaml index f130703..b5fcc51 100644 --- a/charts/oci-onm/Chart.yaml +++ b/charts/oci-onm/Chart.yaml @@ -32,7 +32,7 @@ dependencies: repository: "file://../common" condition: oci-onm-common.enabled - name: oci-onm-logan - version: "3.5.3" + version: "3.5.4" repository: "file://../logan" condition: oci-onm-logan.enabled - name: oci-onm-mgmt-agent