From 9c700ee417e750ba9ce3d8a784bf986e5599df4a Mon Sep 17 00:00:00 2001 From: Matheus Moraes Date: Thu, 21 Mar 2024 11:14:28 -0300 Subject: [PATCH] avoid updating scans schedule on helm upgrades when schedules are not explicitly set --- .../zora/templates/clusterscan/clusterscan.yaml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/charts/zora/templates/clusterscan/clusterscan.yaml b/charts/zora/templates/clusterscan/clusterscan.yaml index c7764c95..3ac32269 100644 --- a/charts/zora/templates/clusterscan/clusterscan.yaml +++ b/charts/zora/templates/clusterscan/clusterscan.yaml @@ -30,12 +30,17 @@ metadata: labels: zora.undistro.io/default: "true" {{- include "zora.labels" . | nindent 4 }} - name: {{ include "truncate.name" (dict "name" (printf "%s-misconfig" (include "zora.clusterName" .)) "len" 63 ) }} - + {{- $misconfigScanName := include "truncate.name" (dict "name" (printf "%s-misconfig" (include "zora.clusterName" .)) "len" 63 ) }} + name: {{ $misconfigScanName }} spec: clusterRef: name: {{ include "zora.clusterName" . }} + {{- $currentMisconfigScan := (lookup "zora.undistro.io/v1alpha1" "ClusterScan" .Release.Namespace $misconfigScanName) }} + {{- if and $currentMisconfigScan (not .Values.scan.misconfiguration.schedule) }} + schedule: {{ $currentMisconfigScan.spec.schedule | quote }} + {{- else }} schedule: {{ include "zora.misconfigSchedule" . | quote }} + {{- end }} successfulScansHistoryLimit: {{ .Values.scan.misconfiguration.successfulScansHistoryLimit }} {{- if .Values.scan.misconfiguration.plugins }} plugins: @@ -52,11 +57,17 @@ metadata: labels: zora.undistro.io/default: "true" {{- include "zora.labels" . | nindent 4 }} - name: {{ include "truncate.name" (dict "name" (printf "%s-vuln" (include "zora.clusterName" .)) "len" 63 ) }} + {{- $vulnScanName := include "truncate.name" (dict "name" (printf "%s-vuln" (include "zora.clusterName" .)) "len" 63 ) }} + name: {{ $vulnScanName }} spec: clusterRef: name: {{ include "zora.clusterName" . }} + {{- $currentVulnScan := (lookup "zora.undistro.io/v1alpha1" "ClusterScan" .Release.Namespace $vulnScanName) }} + {{- if and $currentVulnScan (not .Values.scan.vulnerability.schedule) }} + schedule: {{ $currentVulnScan.spec.schedule | quote }} + {{- else }} schedule: {{ include "zora.vulnSchedule" . | quote }} + {{- end }} successfulScansHistoryLimit: {{ .Values.scan.vulnerability.successfulScansHistoryLimit }} {{- if .Values.scan.vulnerability.plugins }} plugins: