diff --git a/library/common-test/tests/volumeSnapshot/metadata_test.yaml b/library/common-test/tests/volumeSnapshot/metadata_test.yaml index 1d0f5397..44d0b6d1 100644 --- a/library/common-test/tests/volumeSnapshot/metadata_test.yaml +++ b/library/common-test/tests/volumeSnapshot/metadata_test.yaml @@ -21,7 +21,7 @@ tests: g_annotation1: global_annotation1 g_annotation2: "{{ .Values.annotation2 }}" volumeSnapshots: - - name: example1 + example1: enabled: true source: volumeSnapshotContentName: some-name diff --git a/library/common-test/tests/volumeSnapshot/names_test.yaml b/library/common-test/tests/volumeSnapshot/names_test.yaml index cb5a4752..11b25958 100644 --- a/library/common-test/tests/volumeSnapshot/names_test.yaml +++ b/library/common-test/tests/volumeSnapshot/names_test.yaml @@ -8,11 +8,11 @@ tests: - it: should generate correct name set: volumeSnapshots: - - name: example1 + example1: enabled: true source: volumeSnapshotContentName: some-name - - name: example2 + example2: enabled: true source: volumeSnapshotContentName: some-name diff --git a/library/common-test/tests/volumeSnapshot/spec_test.yaml b/library/common-test/tests/volumeSnapshot/spec_test.yaml index c8dba5c8..eb150223 100644 --- a/library/common-test/tests/volumeSnapshot/spec_test.yaml +++ b/library/common-test/tests/volumeSnapshot/spec_test.yaml @@ -8,11 +8,11 @@ tests: - it: should generate correct spec set: volumeSnapshots: - - name: example1 + example1: enabled: true source: volumeSnapshotContentName: some-name - - name: example2 + example2: enabled: true source: persistentVolumeClaimName: some-pvc-name @@ -45,7 +45,7 @@ tests: - it: should generate correct spec with volumeSnapshotClass set: volumeSnapshots: - - name: example1 + example1: enabled: true volumeSnapshotClassName: some-class source: @@ -63,20 +63,10 @@ tests: volumeSnapshotContentName: some-name # Failures - - it: should fail without name - set: - volumeSnapshots: - - enabled: true - source: - volumeSnapshotContentName: some-name - asserts: - - failedTemplate: - errorMessage: Volume Snapshot - Expected non empty [name] - - it: should fail without source object set: volumeSnapshots: - - name: example1 + example1: enabled: true asserts: - failedTemplate: @@ -85,7 +75,7 @@ tests: - it: should fail without a valid source set: volumeSnapshots: - - name: example1 + example1: enabled: true source: invalid: invalid @@ -96,7 +86,7 @@ tests: - it: should fail with more than one valid source set: volumeSnapshots: - - name: example1 + example1: enabled: true source: volumeSnapshotContentName: some-name @@ -105,7 +95,6 @@ tests: - failedTemplate: errorMessage: Volume Snapshot - Expected exactly one of the valid source types [volumeSnapshotContentName, persistentVolumeClaimName]. Found [2] - - it: should fail with empty enabled set: volumeSnapshots: diff --git a/library/common/templates/spawner/_volumeSnapshot.tpl b/library/common/templates/spawner/_volumeSnapshot.tpl index 74f1aaba..4d477391 100644 --- a/library/common/templates/spawner/_volumeSnapshot.tpl +++ b/library/common/templates/spawner/_volumeSnapshot.tpl @@ -6,14 +6,14 @@ {{- define "tc.v1.common.spawner.volumesnapshot" -}} {{- $fullname := include "tc.v1.common.lib.chart.names.fullname" $ -}} - {{- range $idx, $volumesnapshot := .Values.volumeSnapshots -}} + {{- range $name, $volumesnapshot := .Values.volumeSnapshots -}} {{- $enabled := false -}} {{- if hasKey $volumesnapshot "enabled" -}} {{- if not (kindIs "invalid" $volumesnapshot.enabled) -}} {{- $enabled = $volumesnapshot.enabled -}} {{- else -}} - {{- fail (printf "Volume Snapshot - Expected the defined key [enabled] in [volumeSnapshots.%v] to not be empty" $idx) -}} + {{- fail (printf "Volume Snapshot - Expected the defined key [enabled] in [volumeSnapshots.%v] to not be empty" $name) -}} {{- end -}} {{- end -}} @@ -33,14 +33,10 @@ {{/* Create a copy of the volumesnapshot */}} {{- $objectData := (mustDeepCopy $volumesnapshot) -}} - {{- if not $objectData.name -}} - {{- fail "Volume Snapshot - Expected non empty [name]" -}} - {{- end -}} - - {{- $objectName := (printf "%s-%s" $fullname $volumesnapshot.name) -}} + {{- $objectName := (printf "%s-%s" $fullname $name) -}} {{- if hasKey $objectData "expandObjectName" -}} {{- if not $objectData.expandObjectName -}} - {{- $objectName = $volumesnapshot.name -}} + {{- $objectName = $name -}} {{- end -}} {{- end -}} @@ -51,7 +47,7 @@ {{/* Set the name of the volumesnapshot */}} {{- $_ := set $objectData "name" $objectName -}} - {{- $_ := set $objectData "shortName" $volumesnapshot.name -}} + {{- $_ := set $objectData "shortName" $name -}} {{/* Call class to create the object */}} {{- include "tc.v1.common.class.volumesnapshot" (dict "rootCtx" $ "objectData" $objectData) -}} diff --git a/library/common/templates/values/lists/_volumeSnapshotList.tpl b/library/common/templates/values/lists/_volumeSnapshotList.tpl new file mode 100644 index 00000000..0bcf0c16 --- /dev/null +++ b/library/common/templates/values/lists/_volumeSnapshotList.tpl @@ -0,0 +1,18 @@ +{{- define "tc.v1.common.values.volumeSnapshotList" -}} + {{- $rootCtx := . -}} + + {{- range $idx, $volSnapValues := $rootCtx.Values.volumeSnapshotsList -}} + + {{- $name := (printf "vs-list-%s" (toString $idx)) -}} + + {{- with $volSnapValues.name -}} + {{- $name = . -}} + {{- end -}} + + {{- if not (hasKey $rootCtx.Values "volumeSnapshots") -}} + {{- $_ := set $rootCtx.Values "volumeSnapshots" dict -}} + {{- end -}} + + {{- $_ := set $rootCtx.Values.volumeSnapshots $name $volSnapValues -}} + {{- end -}} +{{- end -}} diff --git a/library/common/values.yaml b/library/common/values.yaml index 7187b36d..bb52c228 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -322,10 +322,11 @@ persistenceList: [] deviceList: [] -volumeSnapshotClass: [] -volumeSnapshots: [] +volumeSnapshotClass: {} +volumeSnapshots: {} +volumeSnapshotsList: {} # volumeSnapshots: -# - name: "mycustomsnapshot" +# mysnapshot: # volumeSnapshotClassName: "mycustomsnapshot" (optional) # source: # # pick one