From 72b42f420d99975c14938a2ef9f74998080763cc Mon Sep 17 00:00:00 2001 From: "W. Kavanaugh Latiolais" Date: Sat, 29 Aug 2020 14:39:03 -0500 Subject: [PATCH] Adding plugins and tests for initContainers Tagged version as alpha since there are other breaking change under discussion Signed-off-by: W. Kavanaugh Latiolais --- README.md | 9 ++ charts/velero/Chart.yaml | 2 +- charts/velero/templates/_helpers.tpl | 27 +++- charts/velero/templates/deployment.yaml | 22 +++- charts/velero/tests/base-values.yaml | 9 ++ .../tests/deployment_initContainers_test.yaml | 116 ++++++++++++++++++ charts/velero/values.yaml | 12 ++ 7 files changed, 186 insertions(+), 11 deletions(-) create mode 100644 charts/velero/tests/base-values.yaml create mode 100644 charts/velero/tests/deployment_initContainers_test.yaml diff --git a/README.md b/README.md index 928e0cbc..dcdb4c84 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,15 @@ You can then run `helm search repo vmware-tanzu` to see the charts. TBD +### Running Tests + +To run unit tests in this repository please install helm-unittest + +```sh +helm plugin install https://github.com/quintush/helm-unittest +helm unittest -3 charts/velero +``` + ## License [Apache 2.0 License](./LICENSE). diff --git a/charts/velero/Chart.yaml b/charts/velero/Chart.yaml index 34460564..8aae5f9f 100644 --- a/charts/velero/Chart.yaml +++ b/charts/velero/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v1 appVersion: 1.4.0 description: A Helm chart for velero name: velero -version: 3.0.0 +version: 3.0.0-alpha.1 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/templates/_helpers.tpl b/charts/velero/templates/_helpers.tpl index 77f0d1bf..6b88d012 100644 --- a/charts/velero/templates/_helpers.tpl +++ b/charts/velero/templates/_helpers.tpl @@ -112,9 +112,28 @@ Create the volume snapshot location provider {{- end -}} {{- define "velero.image-from-values" -}} - {{- if .digest }} - {{- .repository }}@{{ .digest }} - {{- else }} - {{- .repository }}:{{ .tag }} + {{- if kindIs "string" . -}} + {{- . }} + {{- else -}} + {{- if .digest -}} + {{- .repository }}@{{ .digest }} + {{- else -}} + {{- .repository }}:{{ .tag }} + {{- end -}} + {{- end -}} +{{- end -}} +{{- define "velero.pull-policy-from-values" -}} + {{- if kindIs "string" . -}} + {{ "IfNotPresent" -}} + {{- else -}} + {{ .pullPolicy -}} + {{- end -}} +{{- end -}} + +{{- define "velero.name-from-values" -}} + {{- if kindIs "string" . -}} + {{ splitList "@" . | first | splitList ":" | first | splitList "/" | last -}} + {{- else -}} + {{ splitList "/" .repository | last -}} {{- end -}} {{- end -}} diff --git a/charts/velero/templates/deployment.yaml b/charts/velero/templates/deployment.yaml index ae43e0ae..6b8a760b 100644 --- a/charts/velero/templates/deployment.yaml +++ b/charts/velero/templates/deployment.yaml @@ -45,7 +45,7 @@ spec: containers: - name: velero image: {{include "velero.image-from-values" .Values.image }} - imagePullPolicy: {{ .Values.image.pullPolicy }} + imagePullPolicy: {{ include "velero.pull-policy-from-values" .Values.image }} {{- if .Values.metrics.enabled }} ports: - name: monitoring @@ -135,11 +135,19 @@ spec: {{- end }} {{- end }} initContainers: - {{- range $providers }} - {{- $pluginImage := get $.Values.pluginImages . }} - - name: velero-plugin-for-{{.}} - image: {{include "velero.image-from-values" $pluginImage }} - imagePullPolicy: {{ $pluginImage.pullPolicy }} + {{- $plugins := list -}} + {{- if kindIs "string" .Values.plugins -}} + {{- $plugins = splitList "," .Values.plugins -}} + {{- else -}} + {{- $plugins = .Values.plugins -}} + {{- end -}} + {{- range $providers -}} + {{- $plugins = append $plugins (get $.Values.pluginImages .) }} + {{- end }} + {{- range $pluginImage := $plugins }} + - name: {{ include "velero.name-from-values" $pluginImage }} + image: {{ include "velero.image-from-values" $pluginImage }} + imagePullPolicy: {{ include "velero.pull-policy-from-values" $pluginImage }} volumeMounts: - mountPath: /target name: plugins @@ -147,6 +155,8 @@ spec: {{- if .Values.initContainers }} {{- toYaml .Values.initContainers | nindent 8 }} {{- end }} + + volumes: {{- if .Values.credentials.useSecret }} - name: cloud-credentials diff --git a/charts/velero/tests/base-values.yaml b/charts/velero/tests/base-values.yaml new file mode 100644 index 00000000..c5a2f8fc --- /dev/null +++ b/charts/velero/tests/base-values.yaml @@ -0,0 +1,9 @@ +configuration: + provider: gcp +schedules: + - name: mybackup + schedule: "0 0 * * *" + template: + ttl: "240h" + includedNamespaces: + - foo diff --git a/charts/velero/tests/deployment_initContainers_test.yaml b/charts/velero/tests/deployment_initContainers_test.yaml new file mode 100644 index 00000000..945748ec --- /dev/null +++ b/charts/velero/tests/deployment_initContainers_test.yaml @@ -0,0 +1,116 @@ +tests: + - it: installs initContainers for initContainers array + set: + initContainers: + - image: test/an-init-container + imagePullPolicy: Always + name: the-init-container + volumeMounts: + - mountPath: /test + name: test + values: + - base-values.yaml + template: deployment.yaml + asserts: + - contains: + path: spec.template.spec.initContainers + content: + image: test/an-init-container + imagePullPolicy: Always + name: the-init-container + volumeMounts: + - mountPath: /test + name: test + - it: installs plugins initContainers for the various provider values + set: + configuration: + provider: aws + backupStorageLocation: + provider: azure + volumeSnapshotLocation: + provider: alibabacloud + values: + - base-values.yaml + template: deployment.yaml + asserts: + - contains: + path: spec.template.spec.initContainers + content: + image: velero/velero-plugin-for-aws:v1.1.0 + imagePullPolicy: IfNotPresent + name: velero-plugin-for-aws + volumeMounts: + - mountPath: /target + name: plugins + - contains: + path: spec.template.spec.initContainers + content: + image: velero/velero-plugin-for-microsoft-azure:v1.1.0 + imagePullPolicy: IfNotPresent + name: velero-plugin-for-microsoft-azure + volumeMounts: + - mountPath: /target + name: plugins + - contains: + path: spec.template.spec.initContainers + content: + image: registry.cn-hangzhou.aliyuncs.com/acs/velero-plugin-alibabacloud:v1.1.0 + imagePullPolicy: IfNotPresent + name: velero-plugin-alibabacloud + volumeMounts: + - mountPath: /target + name: plugins + - it: installs plugins initContainers for plugins as a array of image tags/objects + set: + plugins: + - velero/velero-plugin-for-test1:first + - repository: velero/velero-plugin-for-test2 + digest: sha256:second + pullPolicy: Always + values: + - base-values.yaml + template: deployment.yaml + asserts: + - contains: + path: spec.template.spec.initContainers + content: + image: velero/velero-plugin-for-test1:first + imagePullPolicy: IfNotPresent + name: velero-plugin-for-test1 + volumeMounts: + - mountPath: /target + name: plugins + - contains: + path: spec.template.spec.initContainers + content: + name: velero-plugin-for-test2 + image: velero/velero-plugin-for-test2@sha256:second + imagePullPolicy: Always + volumeMounts: + - mountPath: /target + name: plugins + - it: allows plugins as a string of plugin images + set: + plugins: velero/velero-plugin-for-test1:first,velero/velero-plugin-for-test2@sha256:second + values: + - base-values.yaml + template: deployment.yaml + asserts: + - contains: + path: spec.template.spec.initContainers + content: + name: velero-plugin-for-test1 + image: velero/velero-plugin-for-test1:first + imagePullPolicy: IfNotPresent + volumeMounts: + - mountPath: /target + name: plugins + - contains: + path: spec.template.spec.initContainers + content: + name: velero-plugin-for-test2 + image: velero/velero-plugin-for-test2@sha256:second + imagePullPolicy: IfNotPresent + volumeMounts: + - mountPath: /target + name: plugins diff --git a/charts/velero/values.yaml b/charts/velero/values.yaml index 977991f6..e11d0c8d 100644 --- a/charts/velero/values.yaml +++ b/charts/velero/values.yaml @@ -12,6 +12,7 @@ image: # digest: pullPolicy: IfNotPresent +# default plugin images to enabled when used by providers pluginImages: alibabacloud: repository: registry.cn-hangzhou.aliyuncs.com/acs/velero-plugin-alibabacloud @@ -34,6 +35,17 @@ pluginImages: tag: v1.1.0 pullPolicy: IfNotPresent +# Additional plugin images to install +# Supports a comma seperated string +# plugins: 'velero/velero-plugin-for-aws:v1.1.0,velero/velero-plugin-for-csi:v0.1.1' +# +# Or an array of images as strings and/or objects +# plugins: +# - velero/velero-plugin-for-aws:v1.1.0 +# - repository: velero/velero-plugin-for-csi +# digest: sha256:60d47fd25216f13073525823a067eab223d12e695d4b41e480aa3ff13a58c916 +# pullPolicy: Always +plugins: [] # Annotations to add to the Velero deployment's pod template. Optional.