add hostpath

This commit is contained in:
Stavros kois
2023-02-08 17:32:43 +02:00
parent 4c507b293e
commit 628ff34c0e
7 changed files with 232 additions and 80 deletions

View File

@@ -0,0 +1,108 @@
suite: pod hostPath volume test
templates:
- common.yaml
tests:
- it: should pass with hostPath volume
set:
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
host-vol:
enabled: true
type: hostPath
hostPath: /some-path
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
contains:
path: spec.template.spec.volumes
content:
name: host-vol
hostPath:
path: /some-path
- it: should pass with hostPath volume and type
set:
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
host-vol:
enabled: true
type: hostPath
hostPath: /some-path
hostPathType: DirectoryOrCreate
asserts:
- documentIndex: *deploymentDoc
isKind:
of: Deployment
- documentIndex: *deploymentDoc
contains:
path: spec.template.spec.volumes
content:
name: host-vol
hostPath:
path: /some-path
type: DirectoryOrCreate
# Failures
- it: should fail without hostPath
set:
workload:
some-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
volume1:
enabled: true
type: hostPath
hostPath: ""
asserts:
- failedTemplate:
errorMessage: Persistence - Expected non-empty <hostPath> on <hostPath> type
- it: should fail with relative hostPath
set:
workload:
some-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
volume1:
enabled: true
type: hostPath
hostPath: some-path
asserts:
- failedTemplate:
errorMessage: Persistence - Expected <hostPath> to start with a forward slash [/] on <hostPath> type
- it: should fail with invalid hostPathType
set:
workload:
some-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
volume1:
enabled: true
type: hostPath
hostPath: /some-path
hostPathType: invalid
asserts:
- failedTemplate:
errorMessage: Persistence - Expected <hostPathType> to be one of [DirectoryOrCreate, Directory, FileOrCreate, File, Socket, CharDevice, BlockDevice], but got [invalid]

View File

@@ -1,9 +1,11 @@
suite: pod pvc volume test
suite: pod nfs volume test
templates:
- common.yaml
tests:
- it: should pass with pvc volume
- it: should pass with nfs volume
set:
some_path: /some-path
some_server: some-server
workload:
workload-name1:
enabled: true
@@ -11,9 +13,11 @@ tests:
type: Deployment
podSpec: {}
persistence:
pvc-vol:
nfs-vol:
enabled: true
type: pvc
type: nfs
path: "{{ .Values.some_path }}"
server: "{{ .Values.some_server }}"
asserts:
- documentIndex: &deploymentDoc 0
isKind:
@@ -22,31 +26,60 @@ tests:
contains:
path: spec.template.spec.volumes
content:
name: pvc-vol
persistentVolumeClaim:
claimName: release-name-common-test-pvc-vol
name: nfs-vol
nfs:
path: /some-path
server: some-server
- it: should pass with pvc volume with existing claim
# Failures
- it: should fail without path in nfs
set:
workload:
workload-name1:
some-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
pvc-vol:
volume1:
enabled: true
type: pvc
existingClaim: some-existing-claim
type: nfs
path: ""
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
contains:
path: spec.template.spec.volumes
content:
name: pvc-vol
persistentVolumeClaim:
claimName: some-existing-claim
- failedTemplate:
errorMessage: Persistence - Expected non-empty <path> on <nfs> type
- it: should fail with path not starting with / in nfs
set:
workload:
some-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
volume1:
enabled: true
type: nfs
path: some-relative-path
asserts:
- failedTemplate:
errorMessage: Persistence - Expected <path> to start with a forward slash [/] on <nfs> type
- it: should fail without server in nfs
set:
workload:
some-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
volume1:
enabled: true
type: nfs
path: /some-path
server: ""
asserts:
- failedTemplate:
errorMessage: Persistence - Expected non-empty <server> on <nfs> type

View File

@@ -1,11 +1,9 @@
suite: pod nfs volume test
suite: pod pvc volume test
templates:
- common.yaml
tests:
- it: should pass with nfs volume
- it: should pass with pvc volume
set:
some_path: /some-path
some_server: some-server
workload:
workload-name1:
enabled: true
@@ -13,11 +11,9 @@ tests:
type: Deployment
podSpec: {}
persistence:
nfs-vol:
pvc-vol:
enabled: true
type: nfs
path: "{{ .Values.some_path }}"
server: "{{ .Values.some_server }}"
type: pvc
asserts:
- documentIndex: &deploymentDoc 0
isKind:
@@ -26,60 +22,31 @@ tests:
contains:
path: spec.template.spec.volumes
content:
name: nfs-vol
nfs:
path: /some-path
server: some-server
name: pvc-vol
persistentVolumeClaim:
claimName: release-name-common-test-pvc-vol
# Failures
- it: should fail without path in nfs
- it: should pass with pvc volume with existing claim
set:
workload:
some-workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
volume1:
pvc-vol:
enabled: true
type: nfs
path: ""
type: pvc
existingClaim: some-existing-claim
asserts:
- failedTemplate:
errorMessage: Persistence - Expected non-empty [path] on <nfs> type
- it: should fail with path not starting with / in nfs
set:
workload:
some-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
volume1:
enabled: true
type: nfs
path: some-relative-path
asserts:
- failedTemplate:
errorMessage: Persistence - Expected [path] to start with a forward slash [/] on <nfs> type
- it: should fail without server in nfs
set:
workload:
some-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
volume1:
enabled: true
type: nfs
path: /some-path
server: ""
asserts:
- failedTemplate:
errorMessage: Persistence - Expected non-empty [server] on <nfs> type
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
contains:
path: spec.template.spec.volumes
content:
name: pvc-vol
persistentVolumeClaim:
claimName: some-existing-claim

View File

@@ -26,6 +26,8 @@
| persistence.[volume-name].items | `list` | ❌ | ❌ | `[]` | Define a list of items for configmap/secret |
| 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].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 |
| persistence.[volume-name].targetSelector.[pod-name].[container-name].mountPath | `string` | ❌ | ✅ | `[volume-name].mountPath` | Define the mountPath for the container |
@@ -105,4 +107,10 @@ persistence:
path: path1
- key: key2
path: path2
hostpath-vol:
enabled: true
type: hostPath
hostPath: /path/to/host
hostPathType: DirectoryOrCreate
```

View File

@@ -41,6 +41,7 @@ objectData: The object data to be used to render the Pod.
{{- include "ix.v1.common.lib.pod.volume.pvc" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
{{- else if eq "ixVolume" $type -}}
{{- 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 -}}
{{- include "ix.v1.common.lib.pod.volume.secret" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
{{- else if eq "configmap" $type -}}

View File

@@ -0,0 +1,35 @@
{{/* Returns hostPath Volume */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.pod.volume.hostPath" (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.hostPath" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- $hostPathType := "" -}}
{{- if $objectData.hostPathType -}}
{{- $hostPathType = tpl $objectData.hostPathType $rootCtx -}}
{{- end -}}
{{- if not $objectData.hostPath -}}
{{- fail "Persistence - Expected non-empty <hostPath> on <hostPath> type" -}}
{{- end -}}
{{- $hostPath := tpl $objectData.hostPath $rootCtx -}}
{{- if not (hasPrefix "/" $hostPath) -}}
{{- fail "Persistence - Expected <hostPath> to start with a forward slash [/] on <hostPath> 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 -}}

View File

@@ -9,16 +9,16 @@ objectData: The object data to be used to render the volume.
{{- $objectData := .objectData -}}
{{- if not $objectData.path -}}
{{- fail "Persistence - Expected non-empty [path] on <nfs> type" -}}
{{- fail "Persistence - Expected non-empty <path> on <nfs> type" -}}
{{- end -}}
{{- $path := tpl $objectData.path $rootCtx -}}
{{- if not (hasPrefix "/" $path) -}}
{{- fail "Persistence - Expected [path] to start with a forward slash [/] on <nfs> type" -}}
{{- fail "Persistence - Expected <path> to start with a forward slash [/] on <nfs> type" -}}
{{- end -}}
{{- if not $objectData.server -}}
{{- fail "Persistence - Expected non-empty [server] on <nfs> type" -}}
{{- fail "Persistence - Expected non-empty <server> on <nfs> type" -}}
{{- end }}
- name: {{ $objectData.shortName }}
nfs: