mirror of
https://github.com/truenas/charts.git
synced 2026-06-17 15:38:49 +08:00
add persistenceList
This commit is contained in:
108
library/common-test/tests/lists/persistenceList_test.yaml
Normal file
108
library/common-test/tests/lists/persistenceList_test.yaml
Normal 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
|
||||
@@ -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 -}}
|
||||
@@ -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 -}}
|
||||
|
||||
Reference in New Issue
Block a user