Skip to content

Commit

Permalink
[velero] Add support for multiple backupstoragelocations and volumesn…
Browse files Browse the repository at this point in the history
…apshotlocations (#413)

* Add support for multiple backupstoragelocations and volumesnapshotlocations
* Make BSL and VSL templates backwards compatible and preserve the default provider behavior
* Fix ci lint failure
* fix accessMode rendering
* put values file back
* remove configuration.provider
* add logic for BSL and VSL names
* remove names logic
* update ct values
* fix test values for BSL credential
* add BSL provider to test values
* move accessmode logic to helpers
* fix: set credential when it's configured
* ci: test multiple BSL/VSL
* fix: fix linter error
* ci: only support one default BSL
* doc: update README
* chore: add error message when the BSL/VSL configures as map

Signed-off-by: Brandon Steinman <[email protected]>
Co-authored-by: JenTing Hsiao <[email protected]>
  • Loading branch information
bsteinm2 and jenting authored Apr 26, 2023
1 parent 8f7795d commit 4553dc5
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 76 deletions.
2 changes: 1 addition & 1 deletion charts/velero/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ appVersion: 1.11.0
kubeVersion: ">=1.16.0-0"
description: A Helm chart for velero
name: velero
version: 3.2.0
version: 4.0.0
home: https://github.com/vmware-tanzu/velero
icon: https://cdn-images-1.medium.com/max/1600/1*-9mb3AKnKdcL_QD3CMnthQ.png
sources:
Expand Down
13 changes: 7 additions & 6 deletions charts/velero/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ helm install velero vmware-tanzu/velero \
--namespace <YOUR NAMESPACE> \
--create-namespace \
--set-file credentials.secretContents.cloud=<FULL PATH TO FILE> \
--set configuration.provider=<PROVIDER NAME> \
--set configuration.backupStorageLocation.name=<BACKUP STORAGE LOCATION NAME> \
--set configuration.backupStorageLocation.bucket=<BUCKET NAME> \
--set configuration.backupStorageLocation.config.region=<REGION> \
--set configuration.volumeSnapshotLocation.name=<VOLUME SNAPSHOT LOCATION NAME> \
--set configuration.volumeSnapshotLocation.config.region=<REGION> \
--set configuration.backupStorageLocation[0].name=<BACKUP STORAGE LOCATION NAME> \
--set configuration.backupStorageLocation[0].provider=<PROVIDER NAME> \
--set configuration.backupStorageLocation[0].bucket=<BUCKET NAME> \
--set configuration.backupStorageLocation[0].config.region=<REGION> \
--set configuration.volumeSnapshotLocation[0].name=<VOLUME SNAPSHOT LOCATION NAME> \
--set configuration.volumeSnapshotLocation[0].provider=<PROVIDER NAME> \
--set configuration.volumeSnapshotLocation[0].config.region=<REGION> \
--set initContainers[0].name=velero-plugin-for-<PROVIDER NAME> \
--set initContainers[0].image=velero/velero-plugin-for-<PROVIDER NAME>:<PROVIDER PLUGIN TAG> \
--set initContainers[0].volumeMounts[0].mountPath=/target \
Expand Down
25 changes: 19 additions & 6 deletions charts/velero/ci/test-values.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
# Set provider name and backup storage location bucket name
configuration:
provider: aws
backupStorageLocation:
name: primary
bucket: velero
- name: backups-primary
bucket: velero-backups
default: true
provider: aws
credential:
name: test-credential
key: test-key
config:
region: us-east-1
profile: us-east-1-profile
- name: backups-secondary
bucket: velero-backups
provider: aws
config:
region: us-west-1
profile: test
profile: us-west-1-profile
volumeSnapshotLocation:
- name: ebs-us-east-1
provider: aws
config:
bucket: velero
region: us-west-1
region: us-east-1
- name: portworx-cloud
provider: portworx
config:
type: cloud

schedules:
mybackup:
Expand Down
12 changes: 12 additions & 0 deletions charts/velero/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ More info on the official site: https://velero.io/docs
{{- $breaking_title = print $breaking_title "\n###### the `helm template` command. #####" }}
{{- $breaking_title = print $breaking_title "\n#################################################################################" }}

{{- if typeIs "map[string]interface {}" .Values.configuration.backupStorageLocation }}
{{- $breaking = print $breaking "\n\nERROR: Please make .configuration.backupStorageLocation from map to slice" }}
{{- end }}

{{- if typeIs "map[string]interface {}" .Values.configuration.volumeSnapshotLocation }}
{{- $breaking = print $breaking "\n\nERROR: Please make .configuration.volumeSnapshotLocation from map to slice" }}
{{- end }}

{{- if hasKey .Values.configuration "provider" }}
{{- $breaking = print $breaking "\n\nREMOVED: .configuration.provider has been removed, instead each backupStorageLocation and volumeSnapshotLocation has a provider configured" }}
{{- end }}

{{- if hasKey .Values "resticTimeout" }}
{{- $breaking = print $breaking "\n\nREMOVED: resticTimeout has been removed, and it is named fsBackupTimeout" }}
{{- end }}
Expand Down
36 changes: 0 additions & 36 deletions charts/velero/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,6 @@ Create the node-Agent priority class name.
{{- end -}}
{{- end -}}

{{/*
Create the backup storage location name
*/}}
{{- define "velero.backupStorageLocation.name" -}}
{{- with .Values.configuration.backupStorageLocation -}}
{{ default "default" .name }}
{{- end -}}
{{- end -}}

{{/*
Create the backup storage location provider
*/}}
{{- define "velero.backupStorageLocation.provider" -}}
{{- with .Values.configuration -}}
{{ default .provider .backupStorageLocation.provider }}
{{- end -}}
{{- end -}}

{{/*
Create the volume snapshot location name
*/}}
{{- define "velero.volumeSnapshotLocation.name" -}}
{{- with .Values.configuration.volumeSnapshotLocation -}}
{{ default "default" .name }}
{{- end -}}
{{- end -}}

{{/*
Create the volume snapshot location provider
*/}}
{{- define "velero.volumeSnapshotLocation.provider" -}}
{{- with .Values.configuration -}}
{{ default .provider .volumeSnapshotLocation.provider }}
{{- end -}}
{{- end -}}

{{/*
Kubernetes version
Built-in object .Capabilities.KubeVersion.Minor can provide non-number output
Expand Down
33 changes: 23 additions & 10 deletions charts/velero/templates/backupstoragelocation.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
{{- if .Values.backupsEnabled }}

{{- if typeIs "[]interface {}" .Values.configuration.backupStorageLocation }}
{{- range .Values.configuration.backupStorageLocation }}
---
apiVersion: velero.io/v1
kind: BackupStorageLocation
metadata:
name: {{ include "velero.backupStorageLocation.name" . }}
namespace: {{ .Release.Namespace }}
name: {{ .name | default "default" }}
namespace: {{ $.Release.Namespace }}
annotations:
"helm.sh/hook": post-install,post-upgrade,post-rollback
"helm.sh/hook-delete-policy": before-hook-creation
labels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
app.kubernetes.io/name: {{ include "velero.name" $ }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
helm.sh/chart: {{ include "velero.chart" $ }}
spec:
provider: {{ include "velero.backupStorageLocation.provider" . }}
{{- with .Values.configuration.backupStorageLocation.default }}
{{- if not (empty .credential) }}
credential:
{{- with .credential.name }}
name: {{ . }}
{{- end }}
{{- with .credential.key }}
key: {{ . }}
{{- end }}
{{- end }}
provider: {{ .provider }}
accessMode: {{ .accessMode | default "ReadWrite" }}
{{- with .default }}
default: {{ . }}
{{- end }}
accessMode: {{ .Values.configuration.backupStorageLocation.accessMode }}
{{- with .Values.configuration.backupStorageLocation }}
objectStorage:
bucket: {{ .bucket | quote }}
{{- with .prefix }}
Expand All @@ -35,3 +47,4 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- end }}
22 changes: 14 additions & 8 deletions charts/velero/templates/volumesnapshotlocation.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
{{- if .Values.snapshotsEnabled }}

{{- if typeIs "[]interface {}" .Values.configuration.volumeSnapshotLocation }}
{{- range .Values.configuration.volumeSnapshotLocation }}
---
apiVersion: velero.io/v1
kind: VolumeSnapshotLocation
metadata:
name: {{ include "velero.volumeSnapshotLocation.name" . }}
namespace: {{ .Release.Namespace }}
name: {{ .name | default "default" }}
namespace: {{ $.Release.Namespace }}
annotations:
"helm.sh/hook": post-install,post-upgrade,post-rollback
"helm.sh/hook-delete-policy": before-hook-creation
labels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
app.kubernetes.io/name: {{ include "velero.name" $ }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
helm.sh/chart: {{ include "velero.chart" $ }}
spec:
provider: {{ include "velero.volumeSnapshotLocation.provider" . }}
{{- with .Values.configuration.volumeSnapshotLocation.config }}
provider: {{ .provider }}
{{- with .config }}
config:
{{- range $key, $value := . }}
{{- $key | nindent 4 }}: {{ $value | quote }}
{{- end }}
{{- end -}}
{{- end }}
{{- end }}
{{- end }}
21 changes: 12 additions & 9 deletions charts/velero/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,12 @@ cleanUpCRDs: false
## and additional server settings.
##
configuration:
# Cloud provider being used (e.g. aws, azure, gcp).
provider:

# Parameters for the `default` BackupStorageLocation. See
# https://velero.io/docs/v1.6/api-types/backupstoragelocation/
# Parameters for the BackupStorageLocation(s). Configure multiple by adding other element(s) to the backupStorageLocation slice.
# See https://velero.io/docs/v1.6/api-types/backupstoragelocation/
backupStorageLocation:
# name is the name of the backup storage location where backups should be stored. If a name is not provided,
# a backup storage location will be created with the name "default". Optional.
name:
- name:
# provider is the name for the backup storage location provider. If omitted
# `configuration.provider` will be used instead.
provider:
Expand All @@ -256,6 +253,11 @@ configuration:
# accessMode determines if velero can write to this backup storage location. Optional.
# default to ReadWrite, ReadOnly is used during migrations and restores.
accessMode: ReadWrite
credential:
# name of the secret used by this backupStorageLocation.
name:
# name of key that contains the secret data to be used.
key:
# Additional provider-specific configuration. See link above
# for details of required/optional fields for your provider.
config: {}
Expand All @@ -275,11 +277,11 @@ configuration:
# flag. For Velero client Command like velero backup describe, velero backup logs needs to add the flag --insecure-skip-tls-verify
# insecureSkipTLSVerify:

# Parameters for the `default` VolumeSnapshotLocation. See
# https://velero.io/docs/v1.6/api-types/volumesnapshotlocation/
# Parameters for the VolumeSnapshotLocation(s). Configure multiple by adding other element(s) to the volumeSnapshotLocation slice.
# See https://velero.io/docs/v1.6/api-types/volumesnapshotlocation/
volumeSnapshotLocation:
# name is the name of the volume snapshot location where snapshots are being taken. Required.
name:
- name:
# provider is the name for the volume snapshot provider. If omitted
# `configuration.provider` will be used instead.
provider:
Expand Down Expand Up @@ -499,6 +501,7 @@ nodeAgent:
# useOwnerReferencesInBackup: false
# template:
# ttl: "240h"
# storageLocation: default
# includedNamespaces:
# - foo
schedules: {}
Expand Down

0 comments on commit 4553dc5

Please sign in to comment.