diff --git a/library/common-test/tests/lists/persistenceList_test.yaml b/library/common-test/tests/lists/persistenceList_test.yaml new file mode 100644 index 00000000..3771a851 --- /dev/null +++ b/library/common-test/tests/lists/persistenceList_test.yaml @@ -0,0 +1,108 @@ +suite: persistenceList test +templates: + - common.yaml +tests: + - it: should pass with default values + documentIndex: &deploymentDoc 0 + asserts: + - hasDocuments: + count: 3 + - isKind: + of: Deployment + - isNull: + path: spec.template.spec.volume + - isNull: + path: spec.template.spec.containers[0].volumeMounts + + - it: should pass with persistenceList defined + documentIndex: *deploymentDoc + set: + persistenceList: + - enabled: true + type: pvc + mountPath: /some-path + asserts: + - isSubset: + path: spec.template.spec.containers[0] + content: + volumeMounts: + - name: persist-list-0 + mountPath: /some-path + - isSubset: + path: spec.template.spec + content: + volumes: + - name: persist-list-0 + persistentVolumeClaim: + claimName: release-name-common-test-persist-list-0 + + - it: should pass with persistenceList defined + documentIndex: *deploymentDoc + set: + persistenceList: + - enabled: true + type: nfs + server: 10.10.10.100 + path: /nfs/path + mountPath: /some-path + - enabled: true + type: hostPath + mountPath: /some-path + hostPath: /mnt/pool/dataset/dir + asserts: + - isSubset: + path: spec.template.spec.containers[0] + content: + volumeMounts: + - name: persist-list-0 + mountPath: /some-path + - name: persist-list-1 + mountPath: /some-path + - isSubset: + path: spec.template.spec + content: + volumes: + - name: persist-list-0 + nfs: + server: 10.10.10.100 + path: /nfs/path + - name: persist-list-1 + hostPath: + path: /mnt/pool/dataset/dir + + - it: should pass with persistenceList defined as readOnly + documentIndex: *deploymentDoc + set: + persistenceList: + - enabled: true + type: pvc + mountPath: /some-path + readOnly: true + asserts: + - isSubset: + path: spec.template.spec.containers[0] + content: + volumeMounts: + - name: persist-list-0 + mountPath: /some-path + readOnly: true + - isSubset: + path: spec.template.spec + content: + volumes: + - name: persist-list-0 + persistentVolumeClaim: + claimName: release-name-common-test-persist-list-0 + + - it: should pass with persistenceList defined, validateHostPath true and a malicious not allowed path + documentIndex: *deploymentDoc + set: + persistenceList: + - enabled: true + type: hostPath + mountPath: /some-path + hostPath: /mnt + validateHostPath: true + asserts: + - failedTemplate: + errorMessage: Invalid hostPath (/mnt). Allowed hostPaths are valid paths under a given pool. e.g. /mnt/POOL/DATASET, /mnt/POOL/DATASET/DIRECTORY diff --git a/library/common/1.0.0/templates/lib/values/lists/_persistenceList.tpl b/library/common/1.0.0/templates/lib/values/lists/_persistenceList.tpl new file mode 100644 index 00000000..a2d5788a --- /dev/null +++ b/library/common/1.0.0/templates/lib/values/lists/_persistenceList.tpl @@ -0,0 +1,23 @@ +{{- define "ix.v1.common.lib.values.persistenceList" -}} + {{- $root := . -}} + + {{/* Go over the persistence list */}} + {{- range $index, $persistence := $root.Values.persistenceList -}} + {{/* Generate the name */}} + {{- $name := (printf "persist-list-%s" (toString $index)) -}} + + {{- if $persistence.name -}} + {{- $name = $persistence.name -}} + {{- end -}} + + {{/* Make sure a persistence dict exists before trying to add items */}} + {{- if not (hasKey $root.Values "persistence") -}} + {{- $_ := set $root.Values "persistence" dict -}} + {{- end -}} + + {{/* Add the device as a persistence dict, + other templates will take care of the + volume and volumeMounts */}} + {{- $_ := set $root.Values.persistence $name $persistence -}} + {{- end -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/loader/_lists.tpl b/library/common/1.0.0/templates/loader/_lists.tpl index 5381c95b..ba2b2dc1 100644 --- a/library/common/1.0.0/templates/loader/_lists.tpl +++ b/library/common/1.0.0/templates/loader/_lists.tpl @@ -1,5 +1,7 @@ {{- define "ix.v1.common.loader.lists" -}} + {{- include "ix.v1.common.lib.values.persistenceList" . -}} + {{- include "ix.v1.common.lib.values.deviceList" . -}} {{- end -}}