From 3c17c3bd46d6c406c32ca97b14e5fdc48b52a8a6 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Tue, 6 Dec 2022 18:57:08 +0200 Subject: [PATCH] init work for ixVols --- .../lib/pod/volumes/_hostPathValidation.tpl | 24 +++++++++++++++++++ .../templates/lib/pod/volumes/_ixVols.tpl | 15 ++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 library/common/1.0.0/templates/lib/pod/volumes/_hostPathValidation.tpl diff --git a/library/common/1.0.0/templates/lib/pod/volumes/_hostPathValidation.tpl b/library/common/1.0.0/templates/lib/pod/volumes/_hostPathValidation.tpl new file mode 100644 index 00000000..89fd6a09 --- /dev/null +++ b/library/common/1.0.0/templates/lib/pod/volumes/_hostPathValidation.tpl @@ -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 */}} diff --git a/library/common/1.0.0/templates/lib/pod/volumes/_ixVols.tpl b/library/common/1.0.0/templates/lib/pod/volumes/_ixVols.tpl index 46ae6fc6..7439c559 100644 --- a/library/common/1.0.0/templates/lib/pod/volumes/_ixVols.tpl +++ b/library/common/1.0.0/templates/lib/pod/volumes/_ixVols.tpl @@ -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 */}}