add persistenceList

This commit is contained in:
Stavros kois
2023-01-05 16:30:12 +02:00
parent d0f0017e3f
commit cb9fd7af0a
3 changed files with 133 additions and 0 deletions

View File

@@ -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

View File

@@ -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 -}}

View File

@@ -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 -}}