mirror of
https://github.com/truenas/charts.git
synced 2024-04-21 15:21:45 +00:00
finish volumes
This commit is contained in:
@@ -29,6 +29,8 @@ tests:
|
||||
|
||||
- it: should pass with hostPath volume and type
|
||||
set:
|
||||
some_path: /some-path
|
||||
some_type: DirectoryOrCreate
|
||||
workload:
|
||||
workload-name1:
|
||||
enabled: true
|
||||
@@ -39,8 +41,8 @@ tests:
|
||||
host-vol:
|
||||
enabled: true
|
||||
type: hostPath
|
||||
hostPath: /some-path
|
||||
hostPathType: DirectoryOrCreate
|
||||
hostPath: "{{ .Values.some_path }}"
|
||||
hostPathType: "{{ .Values.some_type }}"
|
||||
asserts:
|
||||
- documentIndex: *deploymentDoc
|
||||
isKind:
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
suite: pod ixVolume volume test
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: should pass with ixVolume volume
|
||||
set:
|
||||
workload:
|
||||
workload-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
ixVolumes:
|
||||
- /mnt/pool/ix-applications/ix-app
|
||||
persistence:
|
||||
ix-vol:
|
||||
enabled: true
|
||||
type: ixVolume
|
||||
datasetName: ix-app
|
||||
asserts:
|
||||
- documentIndex: &deploymentDoc 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDoc
|
||||
contains:
|
||||
path: spec.template.spec.volumes
|
||||
content:
|
||||
name: ix-vol
|
||||
hostPath:
|
||||
path: /mnt/pool/ix-applications/ix-app
|
||||
|
||||
- it: should pass with hostPath volume and type
|
||||
set:
|
||||
some_dataset: ix-app
|
||||
some_type: DirectoryOrCreate
|
||||
workload:
|
||||
workload-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
ixVolumes:
|
||||
- /mnt/pool/ix-applications/ix-app
|
||||
persistence:
|
||||
ix-vol:
|
||||
enabled: true
|
||||
type: ixVolume
|
||||
datasetName: "{{ .Values.some_dataset }}"
|
||||
hostPathType: "{{ .Values.some_type }}"
|
||||
asserts:
|
||||
- documentIndex: *deploymentDoc
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDoc
|
||||
contains:
|
||||
path: spec.template.spec.volumes
|
||||
content:
|
||||
name: ix-vol
|
||||
hostPath:
|
||||
path: /mnt/pool/ix-applications/ix-app
|
||||
type: DirectoryOrCreate
|
||||
|
||||
# Failures
|
||||
- it: should fail without datasetName
|
||||
set:
|
||||
workload:
|
||||
some-workload:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
persistence:
|
||||
volume1:
|
||||
enabled: true
|
||||
type: ixVolume
|
||||
datasetname: ""
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Persistence - Expected non-empty <datasetName> on <ixVolume> type
|
||||
|
||||
- it: should fail with empty ixVolumes
|
||||
set:
|
||||
workload:
|
||||
some-workload:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
ixVolumes: []
|
||||
persistence:
|
||||
volume1:
|
||||
enabled: true
|
||||
type: ixVolume
|
||||
datasetName: ix-app
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Persistence - Expected non-empty <ixVolumes> in values on <ixVolume> type
|
||||
|
||||
- it: should fail with empty ixVolumes
|
||||
set:
|
||||
workload:
|
||||
some-workload:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
ixVolumes:
|
||||
- /mnt/pool/ix-applications/ix-wrong-app
|
||||
- /mnt/pool/ix-applications/ix-other-app
|
||||
persistence:
|
||||
volume1:
|
||||
enabled: true
|
||||
type: ixVolume
|
||||
datasetName: ix-app
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Persistence - Expected <datasetName> [ix-app] to exist on <ixVolumes> list, but list contained [/mnt/pool/ix-applications/ix-wrong-app, /mnt/pool/ix-applications/ix-other-app] on <ixVolume> type
|
||||
|
||||
- it: should fail with invalid hostPathType
|
||||
set:
|
||||
workload:
|
||||
some-workload:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
ixVolumes:
|
||||
- /mnt/pool/ix-applications/ix-app
|
||||
persistence:
|
||||
volume1:
|
||||
enabled: true
|
||||
type: ixVolume
|
||||
datasetName: ix-app
|
||||
hostPathType: invalid
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Persistence - Expected <hostPathType> to be one of [DirectoryOrCreate, Directory, FileOrCreate, File, Socket, CharDevice, BlockDevice], but got [invalid]
|
||||
@@ -27,6 +27,7 @@
|
||||
| persistence.[volume-name].items.key | `string` | ✅ | ✅ | `""` | Define the key of the configmap/secret |
|
||||
| persistence.[volume-name].items.path | `string` | ✅ | ✅ | `""` | Define the path |
|
||||
| persistence.[volume-name].hostPath | `string` | ✅(On hostPath type) | ✅ | `""` | Define the hostPath |
|
||||
| persistence.[volume-name].datasetName | `string` | ✅(On ixVolume type) | ✅ | `""` | Define the datasetName |
|
||||
| persistence.[volume-name].hostPathType | `string` | ❌ | ✅ | `""` | Define the hostPathType |
|
||||
| persistence.[volume-name].targetSelector.[pod-name] | `dict` | ❌ | ❌ | `{}` | Define a dict named after the pod to define the volume |
|
||||
| persistence.[volume-name].targetSelector.[pod-name].[container-name] | `dict` | ❌ | ❌ | `{}` | Define a dict named after the container to mount the volume |
|
||||
@@ -113,4 +114,10 @@ persistence:
|
||||
type: hostPath
|
||||
hostPath: /path/to/host
|
||||
hostPathType: DirectoryOrCreate
|
||||
|
||||
ix-vol:
|
||||
enabled: true
|
||||
type: ixVolume
|
||||
datasetName: ix-app
|
||||
hostPathType: DirectoryOrCreate
|
||||
```
|
||||
|
||||
@@ -40,6 +40,7 @@ objectData: The object data to be used to render the Pod.
|
||||
{{- if eq "pvc" $type -}}
|
||||
{{- include "ix.v1.common.lib.pod.volume.pvc" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- else if eq "ixVolume" $type -}}
|
||||
{{- include "ix.v1.common.lib.pod.volume.ixVolume" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- else if eq "hostPath" $type -}}
|
||||
{{- include "ix.v1.common.lib.pod.volume.hostPath" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- else if eq "secret" $type -}}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
{{/* Returns ixVolume Volume */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.pod.volume.ixVolume" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the template. It is used to access the global context.
|
||||
objectData: The object data to be used to render the volume.
|
||||
*/}}
|
||||
{{- define "ix.v1.common.lib.pod.volume.ixVolume" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $hostPathType := "" -}}
|
||||
{{- if $objectData.hostPathType -}}
|
||||
{{- $hostPathType = tpl $objectData.hostPathType $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not $objectData.datasetName -}}
|
||||
{{- fail "Persistence - Expected non-empty <datasetName> on <ixVolume> type" -}}
|
||||
{{- end -}}
|
||||
{{- $datasetName := tpl $objectData.datasetName $rootCtx -}}
|
||||
|
||||
{{- if not $rootCtx.Values.ixVolumes -}}
|
||||
{{- fail "Persistence - Expected non-empty <ixVolumes> in values on <ixVolume> type" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $hostPath := "" -}}
|
||||
{{- range $idx, $normalizedHostPath := $rootCtx.Values.ixVolumes -}}
|
||||
{{- if eq $datasetName (base $normalizedHostPath) -}}
|
||||
{{- $hostPath = $normalizedHostPath -}}
|
||||
{{- else -}}
|
||||
{{- fail (printf "Persistence - Expected <datasetName> [%s] to exist on <ixVolumes> list, but list contained [%s] on <ixVolume> type" $datasetName (join ", " $rootCtx.Values.ixVolumes )) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not (hasPrefix "/" $hostPath) -}}
|
||||
{{- fail "Persistence - Expected normalized path from <ixVolumes> to start with a forward slash [/] on <ixVolume> type" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $types := (list "DirectoryOrCreate" "Directory" "FileOrCreate" "File" "Socket" "CharDevice" "BlockDevice") -}}
|
||||
{{- if and $hostPathType (not (mustHas $hostPathType $types)) -}}
|
||||
{{- fail (printf "Persistence - Expected <hostPathType> to be one of [%s], but got [%s]" (join ", " $types) $hostPathType) -}}
|
||||
{{- end }}
|
||||
- name: {{ $objectData.shortName }}
|
||||
hostPath:
|
||||
path: {{ $hostPath }}
|
||||
{{- with $hostPathType }}
|
||||
type: {{ $hostPathType }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user