From 8f85d05b4c16c84b29bfb24c7e8bb513cc5cf92a Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Tue, 6 Feb 2024 22:07:03 +0100 Subject: [PATCH] Update _schedule.tpl --- .../templates/class/velero/_schedule.tpl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/library/common/templates/class/velero/_schedule.tpl b/library/common/templates/class/velero/_schedule.tpl index ff5419e0..d0fa8ef7 100644 --- a/library/common/templates/class/velero/_schedule.tpl +++ b/library/common/templates/class/velero/_schedule.tpl @@ -14,12 +14,22 @@ objectData: {{- $rootCtx := .rootCtx -}} {{- $objectData := .objectData }} + {{- $namespace := ( include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "Schedule" ) -}} + {{- $lookupBSL := (lookup "velero.io/v1" "BackupStorageLocation" "" "") -}} + {{- if and $lookupBSL $lookupBSL.items -}} + {{- with (index $lookupBSL.items 0) }} + {{- $lookupBSL = . -}} + {{- end }} + {{- end -}} + {{- if $lookupBSL -}} + {{- $namespace = $lookupBSL.metadata.namespace -}} + {{- end -}} --- apiVersion: velero.io/v1 kind: Schedule metadata: name: {{ $objectData.name }} - namespace: {{ include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "Schedule") }} + namespace: {{ $namespace }} {{- $labels := (mustMerge ($objectData.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} labels: @@ -35,8 +45,13 @@ spec: {{- if (kindIs "bool" $objectData.useOwnerReferencesInBackup) }} useOwnerReferencesInBackup: {{ $objectData.useOwnerReferencesInBackup }} {{- end -}} - {{- with $objectData.template }} template: + {{- if or ( not $objectData.template ) ( and ( not $objectData.template ) ( not $objectData.template.includedNamespaces ) ) -}} + includedNamespaces: + - {{ include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "Schedule") }} + {{- end -}} + {{- with $objectData.template }} {{- toYaml . | nindent 4 }} + {{- end -}} {{- end -}} {{- end -}}