This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
{{/* PVC - Access Modes */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pvc.accessModes" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data of the pvc
|
||||
*/}}
|
||||
|
||||
{{- define "tc.v1.common.lib.pvc.accessModes" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
{{- $caller := .caller -}}
|
||||
|
||||
{{- $accessModes := $objectData.accessModes -}}
|
||||
|
||||
{{- if kindIs "string" $accessModes -}}
|
||||
{{- $accessModes = (list $accessModes) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not $accessModes -}}
|
||||
{{- $accessModes = $rootCtx.Values.fallbackDefaults.accessModes -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $validAccessModes := (list "ReadWriteOnce" "ReadOnlyMany" "ReadWriteMany" "ReadWriteOncePod") -}}
|
||||
|
||||
{{- range $accessModes -}}
|
||||
{{- $mode := tpl . $rootCtx -}}
|
||||
{{- if not (mustHas $mode $validAccessModes) -}}
|
||||
{{- fail (printf "%s - Expected <accessModes> entry to be one of [%s], but got [%s]" $caller (join ", " $validAccessModes) $mode) -}}
|
||||
{{- end }}
|
||||
- {{ $mode }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,54 @@
|
||||
{{/* PVC - Storage Class Name */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.storage.storageClassName" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data of the pvc
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.storage.storageClassName" -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $caller := .caller -}}
|
||||
|
||||
{{/*
|
||||
If storageClass is defined on the objectData:
|
||||
* "-" returns "", which means requesting a PV without class
|
||||
* "SCALE-ZFS" returns the value set on Values.global.ixChartContext.storageClassName
|
||||
(*) "SCALE-SMB" returns the value set on Values.global.ixChartContext.smbStorageClassName (Example for the future)
|
||||
* Else return the original defined storageClass
|
||||
|
||||
Else if we are in an ixChartContext, always return the storageClassName defined on the ixChartContext
|
||||
|
||||
Else if there is a storageClass defined in Values.fallbackDefaults.storageClass, return this
|
||||
|
||||
In any other case, return nothing
|
||||
*/}}
|
||||
|
||||
{{- $className := "" -}}
|
||||
{{- if $objectData.storageClass -}}
|
||||
{{- $storageClass := (tpl $objectData.storageClass $rootCtx) -}}
|
||||
|
||||
{{- if eq "-" $storageClass -}}
|
||||
{{- $className = "\"\"" -}}
|
||||
{{- else if eq "SCALE-ZFS" $storageClass -}}
|
||||
{{- if not $rootCtx.Values.global.ixChartContext.storageClassName -}}
|
||||
{{- fail (printf "%s - Expected non-empty <global.ixChartContext.storageClassName> on [SCALE-ZFS] storageClass" $caller) -}}
|
||||
{{- end -}}
|
||||
{{- $className = tpl $rootCtx.Values.global.ixChartContext.storageClassName $rootCtx -}}
|
||||
{{- else -}}
|
||||
{{- $className = tpl $storageClass $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- else if $rootCtx.Values.global.ixChartContext -}}
|
||||
{{- if not $rootCtx.Values.global.ixChartContext.storageClassName -}}
|
||||
{{- fail (printf "%s - Expected non-empty <global.ixChartContext.storageClassName>" $caller) -}}
|
||||
{{- end -}}
|
||||
{{- $className = tpl $rootCtx.Values.global.ixChartContext.storageClassName $rootCtx -}}
|
||||
|
||||
{{- else if $rootCtx.Values.fallbackDefaults.storageClass -}}
|
||||
|
||||
{{- $className = tpl $rootCtx.Values.fallbackDefaults.storageClass $rootCtx -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{- $className -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,39 @@
|
||||
{{/* PVC Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.persistence.validation" (dict "objectData" $objectData) -}}
|
||||
objectData:
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The pvc object.
|
||||
*/}}
|
||||
|
||||
{{- define "tc.v1.common.lib.persistence.validation" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $types := (list "pvc" "emptyDir" "nfs" "hostPath" "ixVolume" "secret" "configmap" "device") -}}
|
||||
{{- if not (mustHas $objectData.type $types) -}}
|
||||
{{- fail (printf "Persistence - Expected <type> to be one of [%s], but got [%s]" (join ", " $types) $objectData.type) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $objectData.targetSelector (not (kindIs "map" $objectData.targetSelector)) -}}
|
||||
{{- fail (printf "Persistence - Expected <targetSelector> to be [dict], but got [%s]" (kindOf $objectData.targetSelector)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{/* VCT Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.vct.validation" (dict "objectData" $objectData) -}}
|
||||
objectData:
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The vct object.
|
||||
*/}}
|
||||
|
||||
{{- define "tc.v1.common.lib.vct.validation" -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if and $objectData.targetSelector (not (kindIs "map" $objectData.targetSelector)) -}}
|
||||
{{- fail (printf "Volume Claim Templates - Expected <targetSelector> to be [dict], but got [%s]" (kindOf $objectData.targetSelector)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,66 @@
|
||||
{{/* Returns Volume Claim Templates */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.storage.volumeClaimTemplates" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data to be used to render the Pod.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.storage.volumeClaimTemplates" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- range $name, $vctValues := $rootCtx.Values.volumeClaimTemplates -}}
|
||||
|
||||
{{- if $vctValues.enabled -}}
|
||||
{{- $vct := (mustDeepCopy $vctValues) -}}
|
||||
|
||||
{{- $selected := false -}}
|
||||
{{- $_ := set $vct "shortName" $name -}}
|
||||
|
||||
{{- include "tc.v1.common.lib.vct.validation" (dict "objectData" $vct) -}}
|
||||
{{- include "tc.v1.common.lib.chart.names.validation" (dict "name" $vct.shortName) -}}
|
||||
{{- include "tc.v1.common.lib.metadata.validation" (dict "objectData" $vct "caller" "Volume Claim Templates") -}}
|
||||
|
||||
{{/* If targetSelector is set, check if pod is selected */}}
|
||||
{{- if $vct.targetSelector -}}
|
||||
{{- if (mustHas $objectData.shortName (keys $vct.targetSelector)) -}}
|
||||
{{- $selected = true -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* If no targetSelector is set or targetSelectAll, check if pod is primary */}}
|
||||
{{- else -}}
|
||||
{{- if $objectData.primary -}}
|
||||
{{- $selected = true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* If pod selected */}}
|
||||
{{- if $selected -}}
|
||||
{{- $vctSize := $rootCtx.Values.fallbackDefaults.vctSize -}}
|
||||
{{- with $vct.size -}}
|
||||
{{- $vctSize = tpl . $rootCtx -}}
|
||||
{{- end }}
|
||||
- metadata:
|
||||
name: {{ $vct.shortName }}
|
||||
{{- $labels := $vct.labels | default dict -}}
|
||||
{{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }}
|
||||
labels:
|
||||
{{- . | nindent 6 }}
|
||||
{{- end -}}
|
||||
{{- $annotations := $vct.annotations | default dict -}}
|
||||
{{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
|
||||
annotations:
|
||||
{{- . | nindent 6 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- with (include "tc.v1.common.lib.storage.storageClassName" (dict "rootCtx" $rootCtx "objectData" $vct "caller" "Volume Claim Templates") | trim) }}
|
||||
storageClassName: {{ . }}
|
||||
{{- end }}
|
||||
accessModes:
|
||||
{{- include "tc.v1.common.lib.pvc.accessModes" (dict "rootCtx" $rootCtx "objectData" $vct "caller" "Volume Claim Templates") | trim | nindent 6 }}
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ $vctSize }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user