From 778384ffac4ea60e9ce279395720027f37b03fca Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Sat, 25 Nov 2023 16:14:42 +0200 Subject: [PATCH] add s3 too --- .../spec_test.yaml | 28 ++++++++++++++++++- .../templates/lib/velero/_providerSecret.tpl | 11 ++++++-- .../velero/_volumeSnapshotLocation.tpl | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/library/common-test/tests/veleroVolumeSnapshotLocation/spec_test.yaml b/library/common-test/tests/veleroVolumeSnapshotLocation/spec_test.yaml index fad02143..40cc0817 100644 --- a/library/common-test/tests/veleroVolumeSnapshotLocation/spec_test.yaml +++ b/library/common-test/tests/veleroVolumeSnapshotLocation/spec_test.yaml @@ -5,7 +5,7 @@ release: name: test-release-name namespace: test-release-namespace tests: - - it: should generate correct spec with provided provider and credential + - it: should generate correct spec with aws provider and credential set: volumeSnapshotLocation: - enabled: true @@ -31,6 +31,32 @@ tests: name: vsl-test-release-name-common-test-my-snap1 key: cloud + - it: should generate correct spec with s3 provider and credential + set: + volumeSnapshotLocation: + - enabled: true + name: my-snap1 + provider: s3 + credential: + s3: + id: my-id + key: my-key + asserts: + - documentIndex: &volSnapLocDoc 1 + isKind: + of: VolumeSnapshotLocation + - documentIndex: *volSnapLocDoc + isAPIVersion: + of: velero.io/v1 + - documentIndex: *volSnapLocDoc + equal: + path: spec + value: + provider: velero.io/aws + credential: + name: vsl-test-release-name-common-test-my-snap1 + key: cloud + - it: should generate correct spec with provided provider and credential set: volumeSnapshotLocation: diff --git a/library/common/templates/lib/velero/_providerSecret.tpl b/library/common/templates/lib/velero/_providerSecret.tpl index 407f8ce4..75108164 100644 --- a/library/common/templates/lib/velero/_providerSecret.tpl +++ b/library/common/templates/lib/velero/_providerSecret.tpl @@ -1,8 +1,9 @@ {{- define "tc.v1.common.lib.velero.provider.secret" -}} {{- $rootCtx := .rootCtx }} {{- $objectData := .objectData -}} + {{- $prefix := .prefix -}} - {{- $creds := "" -}} {{/* We can add additinal providers here, and only create the template for the data */}} + {{- $creds := "" -}} {{/* Make sure provider is a string */}} {{- $provider := $objectData.provider | toString -}} @@ -11,12 +12,16 @@ {{- $creds = (include "tc.v1.common.lib.velero.provider.aws.secret" (dict "creds" $objectData.credential.aws) | fromYaml).data -}} {{/* Map provider */}} {{- $_ := set $objectData "provider" "velero.io/aws" -}} + {{- else if and (eq $provider "s3") $objectData.credential.s3 -}} + {{- $creds = (include "tc.v1.common.lib.velero.provider.aws.secret" (dict "creds" $objectData.credential.s3) | fromYaml).data -}} + {{/* Map provider */}} + {{- $_ := set $objectData "provider" "velero.io/aws" -}} {{- end -}} {{/* If we matched a provider, create the secret */}} {{- if $creds -}} {{- $secretData := (dict - "name" (printf "vsl-%s" $objectData.name) + "name" (printf "%s-%s" $prefix $objectData.name) "labels" $objectData.labels "annotations" $objectData.annotations "data" (dict "cloud" $creds) @@ -26,7 +31,7 @@ {{- include "tc.v1.common.class.secret" (dict "rootCtx" $rootCtx "objectData" $secretData) -}} {{/* Update the credential object with the name and key */}} - {{- $_ := set $objectData.credential "name" (printf "vsl-%s" $objectData.name) -}} + {{- $_ := set $objectData.credential "name" (printf "%s-%s" $prefix $objectData.name) -}} {{- $_ := set $objectData.credential "key" "cloud" -}} {{- end -}} diff --git a/library/common/templates/spawner/velero/_volumeSnapshotLocation.tpl b/library/common/templates/spawner/velero/_volumeSnapshotLocation.tpl index 66eaf23a..867a2df8 100644 --- a/library/common/templates/spawner/velero/_volumeSnapshotLocation.tpl +++ b/library/common/templates/spawner/velero/_volumeSnapshotLocation.tpl @@ -58,7 +58,7 @@ {{- $_ := set $objectData "shortName" $volSnapLoc.name -}} {{/* Create secret with creds for provider, if the provider is not matched, it will skip creation */}} - {{- include "tc.v1.common.lib.velero.provider.secret" (dict "rootCtx" $ "objectData" $objectData) -}} + {{- include "tc.v1.common.lib.velero.provider.secret" (dict "rootCtx" $ "objectData" $objectData "prefix" "vsl") -}} {{- include "tc.v1.common.lib.velero.volumesnapshotlocation.validation" (dict "objectData" $objectData) -}}