Skip to content

Commit

Permalink
Adding plugins and tests for initContainers
Browse files Browse the repository at this point in the history
 Tagged version as alpha since there are other breaking change under discussion

Signed-off-by: W. Kavanaugh Latiolais <[email protected]>
  • Loading branch information
kav committed Aug 29, 2020
1 parent 8aeb07b commit 72b42f4
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 11 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion charts/velero/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 23 additions & 4 deletions charts/velero/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
22 changes: 16 additions & 6 deletions charts/velero/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,18 +135,28 @@ 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
{{- end }}
{{- if .Values.initContainers }}
{{- toYaml .Values.initContainers | nindent 8 }}
{{- end }}


volumes:
{{- if .Values.credentials.useSecret }}
- name: cloud-credentials
Expand Down
9 changes: 9 additions & 0 deletions charts/velero/tests/base-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
configuration:
provider: gcp
schedules:
- name: mybackup
schedule: "0 0 * * *"
template:
ttl: "240h"
includedNamespaces:
- foo
116 changes: 116 additions & 0 deletions charts/velero/tests/deployment_initContainers_test.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions charts/velero/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 72b42f4

Please sign in to comment.