浏览代码

Merge pull request #15093 from ghalliday/issue26094

HPCC-26094 Improve plane checking and add support for subPath

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 4 年之前
父节点
当前提交
f36168fd73

+ 39 - 22
helm/hpcc/templates/_helpers.tpl

@@ -150,8 +150,12 @@ storage:
   {{- if not $plane.labels }}
     labels:
     - data
-  {{- end }}
-{{ toYaml (omit $plane "name" "pvc" "storageClass" "storageSize") | indent 4 }}
+  {{- end -}}
+  {{- $planeYaml := omit $plane "name" "pvc" "storageClass" "storageSize" "subPath" -}}
+  {{- if $plane.subPath -}}
+   {{- $_ := set $planeYaml "prefix" (printf "%s/%s" $planeYaml.prefix $plane.subPath) -}}
+  {{- end -}}
+    {{- toYaml $planeYaml | nindent 4 }}
  {{- end }}
 {{- end }}
 {{- /* Add implicit planes if data or spill storage plane not specified*/ -}}
@@ -265,21 +269,25 @@ to addVolumeMounts so that if a plane can be used for multiple purposes then dup
 {{- $storage := (.root.Values.storage | default dict) -}}
 {{- $planes := ($storage.planes | default list) -}}
 {{- $includeLabels := .includeLabels | default list -}}
+{{- $previousMounts := dict -}}
 {{- range $plane := $planes -}}
  {{- if or ($plane.pvc) (hasKey $plane "storageClass") -}}
-  {{- $mountpath := $plane.prefix -}}
-  {{- $matchedLabels := include "hpcc.doesStorageLabelsMatch" (dict "plane" $plane "includeLabels" $includeLabels) }}
-  {{ if ne $matchedLabels "" }}
-   {{- $num := int ( $plane.numDevices | default 1 ) -}}
-   {{- if le $num 1 }}
+  {{- if not (hasKey $previousMounts $plane.prefix) -}}
+   {{- $mountpath := $plane.prefix -}}
+   {{- $matchedLabels := include "hpcc.doesStorageLabelsMatch" (dict "plane" $plane "includeLabels" $includeLabels) }}
+   {{- if ne $matchedLabels "" }}
+    {{- $num := int ( $plane.numDevices | default 1 ) -}}
+    {{- if le $num 1 }}
 - name: {{ lower $plane.name }}-pv
   mountPath: {{ $mountpath | quote }}
-   {{- else }}
-    {{- range $elem := untilStep 1 (int (add $num 1)) 1 }}
+    {{- else }}
+     {{- range $elem := untilStep 1 (int (add $num 1)) 1 }}
 - name: {{ lower $plane.name }}-pv-many-{{- $elem }}
   mountPath: {{ printf "%s/d%d" $mountpath $elem | quote }}
+     {{- end }}
     {{- end }}
    {{- end }}
+   {{- $_ := set $previousMounts $plane.prefix true -}}
   {{- end }}
  {{- end }}
 {{- end }}
@@ -317,23 +325,28 @@ The plane will generate a volume if it matches either an includeLabel or an incl
 {{- $planes := ($storage.planes | default list) -}}
 {{- $includeLabels := .includeLabels | default list -}}
 {{- $includeNames := .includeNames | default list -}}
+{{- $previousMounts := dict -}}
 {{- range $plane := $planes -}}
  {{- if or ($plane.pvc) (hasKey $plane "storageClass") -}}
-  {{- $matchedLabels := include "hpcc.doesStorageLabelsMatch" (dict "plane" $plane "includeLabels" $includeLabels) -}}
-  {{- if or ($matchedLabels) (has $plane.name $includeNames) }}
-   {{- $pvc := hasKey $plane "pvc" | ternary $plane.pvc (printf "%s-%s-pvc" (include "hpcc.fullname" $) $plane.name) -}}
-   {{- $num := int ( $plane.numDevices | default 1 ) -}}
-   {{- if le $num 1 }}
+  {{- if not (hasKey $previousMounts $plane.prefix) -}}
+   {{- $mountpath := $plane.prefix -}}
+   {{- $matchedLabels := include "hpcc.doesStorageLabelsMatch" (dict "plane" $plane "includeLabels" $includeLabels) -}}
+   {{- if or ($matchedLabels) (has $plane.name $includeNames) }}
+    {{- $pvc := hasKey $plane "pvc" | ternary $plane.pvc (printf "%s-%s-pvc" (include "hpcc.fullname" $) $plane.name) -}}
+    {{- $num := int ( $plane.numDevices | default 1 ) -}}
+    {{- if le $num 1 }}
 - name: {{ lower $plane.name }}-pv
   persistentVolumeClaim:
     claimName: {{ $pvc }}
-   {{- else }}
-    {{- range $elem := until $num }}
+    {{- else }}
+     {{- range $elem := until $num }}
 - name: {{ lower $plane.name }}-pv-many-{{- add $elem 1 }}
   persistentVolumeClaim:
     claimName: {{ $pvc }}-{{- add $elem 1 }}
-    {{- end }}
-   {{- end -}}
+     {{- end }}
+    {{- end -}}
+   {{- end }}
+   {{- $_ := set $previousMounts $plane.prefix true -}}
   {{- end }}
  {{- end }}
 {{- end -}}
@@ -1069,11 +1082,15 @@ Pass in dict with root, label.  optional name to restrict it to a single name.
 {{- define "hpcc.addPVCsFromPlanes" }}
 {{- $storage := (.Values.storage | default dict) }}
 {{- $planes := ($storage.planes | default list) -}}
+{{- $previousMounts := dict -}}
 {{- range $plane := $planes -}}
-{{- if (hasKey $plane "storageClass") }}
-{{- $pvcname := (printf "%s-pvc" $plane.name) -}}
-{{- include "hpcc.addPVC" (dict "root" $ "name" $pvcname "me" $plane) }}
-{{- end }}
+ {{- if (hasKey $plane "storageClass") -}}
+  {{- if not (hasKey $previousMounts $plane.prefix) -}}
+   {{- $pvcname := (printf "%s-pvc" $plane.name) -}}
+   {{- include "hpcc.addPVC" (dict "root" $ "name" $pvcname "me" $plane) }}
+   {{- $_ := set $previousMounts $plane.prefix true -}}
+ {{- end }}
+ {{- end }}
 {{- end }}
 {{- end -}}
 

+ 19 - 4
helm/hpcc/templates/storage.yaml

@@ -21,11 +21,26 @@
 ##############################################################################
 
 */}}
-{{- include "hpcc.addPVCsFromPlanes" . }}
+{{- /* check planes are unique, have valid names, and do not define the mount in multiple ways */ -}}
 {{- $storage := (.Values.storage | default dict) }}
 {{- $planes := ($storage.planes | default list) -}}
+{{- $previousPlanes := dict -}}
+{{- $previousMounts := dict -}}
 {{- range $plane := $planes -}}
-{{- if (ne (lower $plane.name) $plane.name) -}}
-{{- required (printf "Name of storage plane '%s' must not contain upper case" $plane.name) nil -}}
-{{- end -}}
+ {{- if (ne (lower $plane.name) $plane.name) -}}
+  {{- required (printf "Name of storage plane '%s' must not contain upper case" $plane.name) nil -}}
+ {{- end -}}
+ {{- if hasKey $previousPlanes $plane.name -}}
+  {{- required (printf "Storage plane '%s' is defined more than once" $plane.name) nil -}}
+ {{- end -}}
+ {{- $_ := set $previousPlanes $plane.name true -}}
+ {{- $rawPlane := omit $plane "name" "labels" -}}
+ {{- if hasKey $previousMounts $plane.prefix -}}
+  {{- /* Should this restrict if has a pvc or a storage class? */ -}}
+  {{- if not (deepEqual (get $previousMounts $plane.prefix) $rawPlane) -}}
+    {{- required (printf "Multiple incompatible planes refer to prefix '%s'" $plane.prefix) nil -}}
+  {{- end -}}
+ {{- end -}}
+ {{- $_ := set $previousMounts $plane.prefix $rawPlane -}}
 {{- end -}}
+{{- include "hpcc.addPVCsFromPlanes" . }}

+ 4 - 0
helm/hpcc/values.schema.json

@@ -413,6 +413,10 @@
           "description": "either the path for a local mount, or the url prefix",
           "type": "string"
         },
+        "subPath": {
+          "description": "optional subdirectory within the mount directory",
+          "type": "string"
+        },
         "secret": {
           "description": "optional name of any secret required to access this storage plane",
           "type": "string"

+ 1 - 0
helm/hpcc/values.yaml

@@ -117,6 +117,7 @@ storage:
   planes:
   #   name: <required>
   #   prefix: <path>                        # Root directory for accessing the plane (if pvc defined), or url to access plane.
+  #   subPath: <relative-path>              # Optional sub directory within <prefix> to use as the root directory
   #   pvc: <name>                           # The name of the persistant volume claim
   #   numDevices: 1                         # number of devices that are part of the plane
   #   replication: nullptr                  # a list or single item indicating which planes the data should be replicated onto

+ 27 - 0
testing/helm/errtests/dupmount.yaml

@@ -0,0 +1,27 @@
+storage:
+  planes:
+  - name: dali
+    storageClass: ""
+    storageSize: 1Gi
+    prefix: "/var/lib/HPCCSystems/dalistorage"
+    labels: [ "dali" ]
+  - name: sasha
+    storageClass: ""
+    storageSize: 1Gi
+    prefix: "/var/lib/HPCCSystems/sashastorage"
+    labels: [ "sasha" ]
+  - name: dll
+    storageClass: ""
+    storageSize: 1Gi
+    prefix: "/var/lib/HPCCSystems/queries"
+    labels: [ "dll" ]
+  - name: data
+    storageClass: ""
+    storageSize: 1Gi
+    prefix: "/var/lib/HPCCSystems/hpcc-data"
+    labels: [ "data" ]
+  - name: mydropzone
+    storageClass: ""
+    storageSize: 3Gi
+    prefix: "/var/lib/HPCCSystems/queries"
+    labels: [ "lz" ]

+ 27 - 0
testing/helm/errtests/dupplane.yaml

@@ -0,0 +1,27 @@
+storage:
+  planes:
+  - name: dali
+    storageClass: ""
+    storageSize: 1Gi
+    prefix: "/var/lib/HPCCSystems/dalistorage"
+    labels: [ "dali" ]
+  - name: sasha
+    storageClass: ""
+    storageSize: 1Gi
+    prefix: "/var/lib/HPCCSystems/sashastorage"
+    labels: [ "sasha" ]
+  - name: dll
+    storageClass: ""
+    storageSize: 1Gi
+    prefix: "/var/lib/HPCCSystems/queries"
+    labels: [ "dll" ]
+  - name: data
+    storageClass: ""
+    storageSize: 1Gi
+    prefix: "/var/lib/HPCCSystems/hpcc-data"
+    labels: [ "data" ]
+  - name: data
+    storageClass: ""
+    storageSize: 1Gi
+    prefix: "/var/lib/HPCCSystems/dropzone"
+    labels: [ "lz" ]