init work for ixVols

This commit is contained in:
Stavros kois
2022-12-06 18:57:08 +02:00
parent 1b75d26554
commit 3c17c3bd46
2 changed files with 37 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
{{- define "ix.v1.common.controller.volumes.hostPath.validation" -}}
{{- if $root.Values.global.defaults.validateHostPaths -}} {{/* TODO: global or per volume flag? */}}
{{- $incomingData := .incoming -}} {{/* TODO: change variable name... temp implementation */}}
{{- $allowed_paths := (list "mnt" "sys" "dev" "cluster") -}}
{{- $errorMessage := (printf "Invalid hostPath (%s). Allowed hostPaths are valid paths under a given pool. e.g. /mnt/POOL/DATASET, /mnt/POOL/DATASET/DIRECTORY" $incomingData) -}}
{{- $hostPath := splitList "/" $incomingData -}} {{/* Split the path into a list */}}
{{- $hostPath := (mustWithout $hostPath "") -}} {{/* Drop any list items with empty strings */}}
{{- $pathStart := (index $hostPath 0) -}}
{{- if not (mustHas ($pathStart $allowed_paths)) -}}
{{- fail $errorMessage -}}
{{- else if eq $pathStart "mnt" -}}
{{- if lt (len $hostPath) 3 -}}
{{- fail $errorMessage -}}
{{- end -}}
{{- else if eq $pathStart "cluster" -}}
{{- if lt (len $hostPath) 2 -}}
{{- fail $errorMessage -}}
{{- else if eq (index $hostPath 1) "ctdb_shared_vol" -}}
{{- fail $errorMessage -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* TODO: unittests */}}

View File

@@ -1,7 +1,18 @@
{{- define "ix.v1.common.controller.volumes.ixVols" -}}
{{- $index := .index -}}
{{- $vol := .volume -}}
{{- $root := .root }}
{{- $root := .root -}}
{{- if not $vol.datasetName -}}
{{- fail (printf "Item (%s) is set as ixVolume type, but has no Dataset Name defined" $index) -}}
{{- end -}}
{{- if not (mustHas $vol.datasetName $root.ixVolumes) -}} {{/* Make sure the resolved datasetName is included in ixVolumes */}}
{{- fail (printf "Dataset Name on item (%s) does not exist in ixVolumes list" $index) -}}
{{- end }}
- name: {{ $index }}
hostPath:
path: {{ required (printf "hostPath not set on item %s" $index) $vol.hostPath }}
{{- with $vol.hostPathType }}
type: {{ tpl . $root }}
{{- end -}}
{{- end -}}
{{/* TODO: unittests */}}