From 0fc0edca1f74371be17da9916cdb16a88a7d3c18 Mon Sep 17 00:00:00 2001 From: Igor Cezar Date: Wed, 18 Nov 2020 05:50:54 -0300 Subject: [PATCH] [velero] Add enable/disable option for helm hooks (#171) * Add enable/disable option for helm hooks * Adjust crds.yaml * Make one variable for all hooks * Remove all helm hooks in crds folder * Add Helm v2 hooks for CRDs from _helpers template * Bump chart version and change hook comments Signed-off-by: Igor Cezar --- charts/velero/Chart.yaml | 2 +- charts/velero/crds/backups.yaml | 2 -- charts/velero/crds/backupstoragelocations.yaml | 2 -- charts/velero/crds/deletebackuprequests.yaml | 2 -- charts/velero/crds/downloadrequests.yaml | 2 -- charts/velero/crds/podvolumebackups.yaml | 2 -- charts/velero/crds/podvolumerestores.yaml | 2 -- charts/velero/crds/resticrepositories.yaml | 2 -- charts/velero/crds/restores.yaml | 2 -- charts/velero/crds/schedules.yaml | 2 -- charts/velero/crds/serverstatusrequests.yaml | 2 -- charts/velero/crds/volumesnapshotlocations.yaml | 2 -- charts/velero/templates/_helpers.tpl | 8 ++++++++ charts/velero/templates/backupstoragelocation.yaml | 2 ++ charts/velero/templates/crds.yaml | 11 +++++++++++ charts/velero/templates/schedule.yaml | 2 ++ charts/velero/templates/volumesnapshotlocation.yaml | 2 ++ charts/velero/values.yaml | 5 +++++ 18 files changed, 31 insertions(+), 23 deletions(-) diff --git a/charts/velero/Chart.yaml b/charts/velero/Chart.yaml index 6ca48324..c4bd7b5e 100644 --- a/charts/velero/Chart.yaml +++ b/charts/velero/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v1 appVersion: 1.5.2 description: A Helm chart for velero name: velero -version: 2.13.6 +version: 2.13.7 home: https://github.com/vmware-tanzu/velero icon: https://cdn-images-1.medium.com/max/1600/1*-9mb3AKnKdcL_QD3CMnthQ.png sources: diff --git a/charts/velero/crds/backups.yaml b/charts/velero/crds/backups.yaml index 9314cdeb..034716f9 100644 --- a/charts/velero/crds/backups.yaml +++ b/charts/velero/crds/backups.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: velero annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: backups.velero.io spec: diff --git a/charts/velero/crds/backupstoragelocations.yaml b/charts/velero/crds/backupstoragelocations.yaml index 672348b9..cbc1b411 100644 --- a/charts/velero/crds/backupstoragelocations.yaml +++ b/charts/velero/crds/backupstoragelocations.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: "velero" annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: backupstoragelocations.velero.io spec: diff --git a/charts/velero/crds/deletebackuprequests.yaml b/charts/velero/crds/deletebackuprequests.yaml index 81289b30..3e974343 100644 --- a/charts/velero/crds/deletebackuprequests.yaml +++ b/charts/velero/crds/deletebackuprequests.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: "velero" annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: deletebackuprequests.velero.io spec: diff --git a/charts/velero/crds/downloadrequests.yaml b/charts/velero/crds/downloadrequests.yaml index 59d2a1bb..025f9a08 100644 --- a/charts/velero/crds/downloadrequests.yaml +++ b/charts/velero/crds/downloadrequests.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: "velero" annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: downloadrequests.velero.io spec: diff --git a/charts/velero/crds/podvolumebackups.yaml b/charts/velero/crds/podvolumebackups.yaml index 3f392895..d5c309b9 100644 --- a/charts/velero/crds/podvolumebackups.yaml +++ b/charts/velero/crds/podvolumebackups.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: "velero" annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: podvolumebackups.velero.io spec: diff --git a/charts/velero/crds/podvolumerestores.yaml b/charts/velero/crds/podvolumerestores.yaml index d1362d52..d8d24e23 100644 --- a/charts/velero/crds/podvolumerestores.yaml +++ b/charts/velero/crds/podvolumerestores.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: "velero" annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: podvolumerestores.velero.io spec: diff --git a/charts/velero/crds/resticrepositories.yaml b/charts/velero/crds/resticrepositories.yaml index 7c548b6f..f6650ef6 100644 --- a/charts/velero/crds/resticrepositories.yaml +++ b/charts/velero/crds/resticrepositories.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: "velero" annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: resticrepositories.velero.io spec: diff --git a/charts/velero/crds/restores.yaml b/charts/velero/crds/restores.yaml index ca100aea..85c86a33 100644 --- a/charts/velero/crds/restores.yaml +++ b/charts/velero/crds/restores.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: velero annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: restores.velero.io spec: diff --git a/charts/velero/crds/schedules.yaml b/charts/velero/crds/schedules.yaml index 628e6ef7..31cf1595 100644 --- a/charts/velero/crds/schedules.yaml +++ b/charts/velero/crds/schedules.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: "velero" annotations: - "helm.sh/hook": pre-install,post-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: schedules.velero.io spec: diff --git a/charts/velero/crds/serverstatusrequests.yaml b/charts/velero/crds/serverstatusrequests.yaml index dd4ea84f..6dd005e0 100644 --- a/charts/velero/crds/serverstatusrequests.yaml +++ b/charts/velero/crds/serverstatusrequests.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: "velero" annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: serverstatusrequests.velero.io spec: diff --git a/charts/velero/crds/volumesnapshotlocations.yaml b/charts/velero/crds/volumesnapshotlocations.yaml index 0bd3f7cf..a915b1ff 100644 --- a/charts/velero/crds/volumesnapshotlocations.yaml +++ b/charts/velero/crds/volumesnapshotlocations.yaml @@ -5,8 +5,6 @@ metadata: labels: app.kubernetes.io/name: "velero" annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-delete-policy": "before-hook-creation" controller-gen.kubebuilder.io/version: v0.3.0 name: volumesnapshotlocations.velero.io spec: diff --git a/charts/velero/templates/_helpers.tpl b/charts/velero/templates/_helpers.tpl index 3ac184e6..52eb4553 100644 --- a/charts/velero/templates/_helpers.tpl +++ b/charts/velero/templates/_helpers.tpl @@ -110,3 +110,11 @@ Create the volume snapshot location provider {{ default .provider .volumeSnapshotLocation.provider }} {{- end -}} {{- end -}} + +{{/* +Helm hooks for Helm v2 CRDs +*/}} +{{- define "velero.helmhooks.crds" -}} +{{ print "\"helm.sh/hook\": pre-install,pre-upgrade" | indent 4 }} +{{ print "\"helm.sh/hook-delete-policy\": \"before-hook-creation\"" | indent 4 }} +{{- end -}} diff --git a/charts/velero/templates/backupstoragelocation.yaml b/charts/velero/templates/backupstoragelocation.yaml index 789168b9..de99d36b 100644 --- a/charts/velero/templates/backupstoragelocation.yaml +++ b/charts/velero/templates/backupstoragelocation.yaml @@ -4,8 +4,10 @@ kind: BackupStorageLocation metadata: name: {{ include "velero.backupStorageLocation.name" . }} annotations: + {{- if .Values.enableHelmHooks }} "helm.sh/hook": post-install,post-upgrade "helm.sh/hook-delete-policy": "before-hook-creation" + {{- end }} labels: app.kubernetes.io/name: {{ include "velero.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/velero/templates/crds.yaml b/charts/velero/templates/crds.yaml index 8e605395..4a92f8d7 100644 --- a/charts/velero/templates/crds.yaml +++ b/charts/velero/templates/crds.yaml @@ -1,6 +1,17 @@ {{- if and .Values.installCRDs (eq .Release.Service "Tiller") }} {{- range $path, $bytes := .Files.Glob "crds/*.yaml" }} +{{- if not $.Values.enableHelmHooks }} {{ $.Files.Get $path }} +{{- else }} +{{- range $.Files.Lines $path }} +{{- if contains "annotations:" . }} +{{ . }} +{{ template "velero.helmhooks.crds" . }} +{{- else }} +{{ . }} +{{- end }} +{{- end }} +{{- end }} --- {{- end }} {{- end }} diff --git a/charts/velero/templates/schedule.yaml b/charts/velero/templates/schedule.yaml index 406c4e88..22500b13 100644 --- a/charts/velero/templates/schedule.yaml +++ b/charts/velero/templates/schedule.yaml @@ -4,8 +4,10 @@ kind: Schedule metadata: name: {{ include "velero.fullname" $ }}-{{ $scheduleName }} annotations: + {{- if $.Values.enableHelmHooks }} "helm.sh/hook": post-install,post-upgrade "helm.sh/hook-delete-policy": "before-hook-creation" + {{- end }} labels: app.kubernetes.io/name: {{ include "velero.name" $ }} app.kubernetes.io/instance: {{ $.Release.Name }} diff --git a/charts/velero/templates/volumesnapshotlocation.yaml b/charts/velero/templates/volumesnapshotlocation.yaml index 96fdd7fc..39f61b25 100644 --- a/charts/velero/templates/volumesnapshotlocation.yaml +++ b/charts/velero/templates/volumesnapshotlocation.yaml @@ -4,8 +4,10 @@ kind: VolumeSnapshotLocation metadata: name: {{ include "velero.volumeSnapshotLocation.name" . }} annotations: + {{- if .Values.enableHelmHooks }} "helm.sh/hook": post-install,post-upgrade "helm.sh/hook-delete-policy": "before-hook-creation" + {{- end }} labels: app.kubernetes.io/name: {{ include "velero.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/velero/values.yaml b/charts/velero/values.yaml index 88fd9146..b1cadef8 100644 --- a/charts/velero/values.yaml +++ b/charts/velero/values.yaml @@ -75,6 +75,11 @@ metrics: # Install CRDs as a templates. Enabled by default. installCRDs: true +# Enable/disable all helm hooks annotations +# You should disable this if using a deploy tool that doesn't support helm hooks, +# such as ArgoCD +enableHelmHooks: true + ## ## End of deployment-related settings. ##