This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
{{/* Returns automountServiceAccountToken */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.automountServiceAccountToken" (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.pod.automountServiceAccountToken" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $automount := false -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- if (kindIs "bool" $rootCtx.Values.podOptions.automountServiceAccountToken) -}}
|
||||
{{- $automount = $rootCtx.Values.podOptions.automountServiceAccountToken -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pod's option */}}
|
||||
{{- if (kindIs "bool" $objectData.podSpec.automountServiceAccountToken) -}}
|
||||
{{- $automount = $objectData.podSpec.automountServiceAccountToken -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $automount -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,62 @@
|
||||
{{/* Returns Container */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.container" (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.pod.container" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $imageObj := fromJson (include "tc.v1.common.lib.container.imageSelector" (dict "rootCtx" $rootCtx "objectData" $objectData)) -}}
|
||||
{{- $termination := fromJson (include "tc.v1.common.lib.container.termination" (dict "rootCtx" $rootCtx "objectData" $objectData)) }}
|
||||
- name: {{ $objectData.name }}
|
||||
image: {{ printf "%s:%s" $imageObj.repository $imageObj.tag }}
|
||||
imagePullPolicy: {{ $imageObj.pullPolicy }}
|
||||
tty: {{ $objectData.tty | default false }}
|
||||
stdin: {{ $objectData.stdin | default false }}
|
||||
{{- with (include "tc.v1.common.lib.container.command" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
|
||||
command:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end -}}
|
||||
{{- with (include "tc.v1.common.lib.container.args" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
|
||||
args:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end -}}
|
||||
{{- with $termination.messagePath }}
|
||||
terminationMessagePath: {{ . }}
|
||||
{{- end -}}
|
||||
{{- with $termination.messagePolicy }}
|
||||
terminationMessagePolicy: {{ . }}
|
||||
{{- end -}}
|
||||
{{- with (include "tc.v1.common.lib.container.lifecycle" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
|
||||
lifecycle:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end -}}
|
||||
{{- with (include "tc.v1.common.lib.container.ports" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
|
||||
ports:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end -}}
|
||||
{{- with (include "tc.v1.common.lib.container.volumeMount" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
|
||||
volumeMounts:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end -}}
|
||||
{{- include "tc.v1.common.lib.container.probes" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 -}}
|
||||
{{- with (include "tc.v1.common.lib.container.resources" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
|
||||
resources:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end }}
|
||||
securityContext:
|
||||
{{- include "tc.v1.common.lib.container.securityContext" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 4 }}
|
||||
{{- /* Create a dict for storing env's so it can be checked for dupes */ -}}
|
||||
{{- $_ := set $objectData "envDupe" dict -}}
|
||||
{{- with (include "tc.v1.common.lib.container.envFrom" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
|
||||
envFrom:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end }}
|
||||
env:
|
||||
{{- include "tc.v1.common.lib.container.fixedEnv" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 4 -}}
|
||||
{{- include "tc.v1.common.lib.container.env" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 4 -}}
|
||||
{{- include "tc.v1.common.lib.container.envList" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 4 -}}
|
||||
{{- $_ := unset $objectData "envDupe" -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,31 @@
|
||||
{{/* Containers */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.containerSpawner" (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.pod.containerSpawner" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- include "tc.v1.common.lib.container.primaryValidation" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
|
||||
{{- range $containerName, $containerValues := $objectData.podSpec.containers -}}
|
||||
{{- if $containerValues.enabled -}}
|
||||
{{- $container := (mustDeepCopy $containerValues) -}}
|
||||
{{- $name := include "tc.v1.common.lib.chart.names.fullname" $rootCtx -}}
|
||||
{{- if not $container.primary -}}
|
||||
{{- $name = printf "%s-%s" $name $containerName -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $_ := set $container "name" $name -}}
|
||||
{{- $_ := set $container "shortName" $containerName -}}
|
||||
{{- $_ := set $container "podShortName" $objectData.shortName -}}
|
||||
{{- $_ := set $container "podPrimary" $objectData.primary -}}
|
||||
{{- $_ := set $container "podType" $objectData.type -}}
|
||||
{{/* Created from the pod.securityContext, used by fixedEnv */}}
|
||||
{{- $_ := set $container "calculatedFSGroup" $objectData.podSpec.calculatedFSGroup -}}
|
||||
{{- include "tc.v1.common.lib.pod.container" (dict "rootCtx" $rootCtx "objectData" $container) | trim | nindent 0 -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
90
helm-charts/dashy/charts/common/templates/lib/pod/_dns.tpl
Normal file
90
helm-charts/dashy/charts/common/templates/lib/pod/_dns.tpl
Normal file
@@ -0,0 +1,90 @@
|
||||
{{/* Returns DNS Policy and Config */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.dns" (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.pod.dns" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $policy := "ClusterFirst" -}}
|
||||
{{- $config := dict -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- with $rootCtx.Values.podOptions.dnsPolicy -}}
|
||||
{{- $policy = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $rootCtx.Values.podOptions.dnsConfig -}}
|
||||
{{- $config = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pod's option */}}
|
||||
{{- with $objectData.podSpec.dnsPolicy -}}
|
||||
{{- $policy = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $objectData.podSpec.dnsConfig -}}
|
||||
{{- $config = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Expand policy */}}
|
||||
{{- $policy = (tpl $policy $rootCtx) -}}
|
||||
|
||||
{{/* If hostNetwork is enabled, then use ClusterFirstWithHostNet */}}
|
||||
{{- $hostNet := include "tc.v1.common.lib.pod.hostNetwork" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
{{- if or (and (kindIs "string" $hostNet) (eq $hostNet "true")) (and (kindIs "bool" $hostNet) $hostNet) -}}
|
||||
{{- $policy = "ClusterFirstWithHostNet" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $policies := (list "ClusterFirst" "ClusterFirstWithHostNet" "Default" "None") -}}
|
||||
{{- if not (mustHas $policy $policies) -}}
|
||||
{{- fail (printf "Expected <dnsPolicy> to be one of [%s], but got [%s]" (join ", " $policies) $policy) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* When policy is set to None all keys are required */}}
|
||||
{{- if eq $policy "None" -}}
|
||||
|
||||
{{- range $key := (list "nameservers" "searches" "options") -}}
|
||||
{{- if not (get $config $key) -}}
|
||||
{{- fail (printf "Expected non-empty <dnsConfig.%s> with <dnsPolicy> set to [None]." $key) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end }}
|
||||
dnsPolicy: {{ $policy }}
|
||||
{{- if or $config.nameservers $config.options $config.searches }}
|
||||
dnsConfig:
|
||||
{{- with $config.nameservers -}}
|
||||
{{- if gt (len .) 3 -}}
|
||||
{{- fail (printf "Expected no more than [3] <dnsConfig.nameservers>, but got [%v]" (len .)) -}}
|
||||
{{- end }}
|
||||
nameservers:
|
||||
{{- range . }}
|
||||
- {{ tpl . $rootCtx }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $config.searches -}}
|
||||
{{- if gt (len .) 6 -}}
|
||||
{{- fail (printf "Expected no more than [6] <dnsConfig.searches>, but got [%v]" (len .)) -}}
|
||||
{{- end }}
|
||||
searches:
|
||||
{{- range . }}
|
||||
- {{ tpl . $rootCtx }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $config.options }}
|
||||
options:
|
||||
{{- range . }}
|
||||
- name: {{ tpl .name $rootCtx }}
|
||||
{{- with .value }}
|
||||
value: {{ tpl . $rootCtx | quote }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,24 @@
|
||||
{{/* Returns enableServiceLinks */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.enableServiceLinks" (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.pod.enableServiceLinks" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $enableServiceLinks := false -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- if (kindIs "bool" $rootCtx.Values.podOptions.enableServiceLinks) -}}
|
||||
{{- $enableServiceLinks = $rootCtx.Values.podOptions.enableServiceLinks -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pod's option */}}
|
||||
{{- if (kindIs "bool" $objectData.podSpec.enableServiceLinks) -}}
|
||||
{{- $enableServiceLinks = $objectData.podSpec.enableServiceLinks -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $enableServiceLinks -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,37 @@
|
||||
{{/* Returns Host Aliases */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.hostAliases" (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.pod.hostAliases" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $aliases := list -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- with $rootCtx.Values.podOptions.hostAliases -}}
|
||||
{{- $aliases = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pod's option */}}
|
||||
{{- with $objectData.podSpec.hostAliases -}}
|
||||
{{- $aliases = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- range $aliases -}}
|
||||
{{- if not .ip -}}
|
||||
{{- fail (printf "Expected non-empty <ip> value on <hostAliases>.") -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not .hostnames -}}
|
||||
{{- fail (printf "Expected non-empty <hostames> list on <hostAliases>.") -}}
|
||||
{{- end }}
|
||||
- ip: {{ tpl .ip $rootCtx }}
|
||||
hostnames:
|
||||
{{- range .hostnames }}
|
||||
- {{ tpl . $rootCtx }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,24 @@
|
||||
{{/* Returns Host Network */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.hostNetwork" (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.pod.hostNetwork" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $hostNet := false -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- if (kindIs "bool" $rootCtx.Values.podOptions.hostNetwork) -}}
|
||||
{{- $hostNet = $rootCtx.Values.podOptions.hostNetwork -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pod's option */}}
|
||||
{{- if (kindIs "bool" $objectData.podSpec.hostNetwork) -}}
|
||||
{{- $hostNet = $objectData.podSpec.hostNetwork -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $hostNet -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,24 @@
|
||||
{{/* Returns Host PID */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.hostPID" (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.pod.hostPID" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $hostPID := false -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- if (kindIs "bool" $rootCtx.Values.podOptions.hostPID) -}}
|
||||
{{- $hostPID = $rootCtx.Values.podOptions.hostPID -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pods option */}}
|
||||
{{- if (kindIs "bool" $objectData.podSpec.hostPID) -}}
|
||||
{{- $hostPID = $objectData.podSpec.hostPID -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $hostPID -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,22 @@
|
||||
{{/* Returns Host Name */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.hostname" (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.pod.hostname" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $hostname := "" -}}
|
||||
|
||||
{{- with $objectData.podSpec.hostname -}}
|
||||
{{- $hostname = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $hostname -}}
|
||||
{{- include "tc.v1.common.lib.chart.names.validation" (dict "name" $hostname) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $hostname -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,38 @@
|
||||
{{/* Returns Image Pull Secret List */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.imagePullSecret" (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.pod.imagePullSecret" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $imgPullSecrets := list -}}
|
||||
|
||||
{{- range $name, $imgPull := $rootCtx.Values.imagePullSecret -}}
|
||||
{{- $pullName := (printf "%s-%s" (include "tc.v1.common.lib.chart.names.fullname" $rootCtx) $name) -}}
|
||||
|
||||
{{- if $imgPull.enabled -}}
|
||||
{{/* If targetSelectAll is true */}}
|
||||
{{- if $imgPull.targetSelectAll -}}
|
||||
{{- $imgPullSecrets = mustAppend $imgPullSecrets $pullName -}}
|
||||
|
||||
{{/* Else if targetSelector is a list */}}
|
||||
{{- else if (kindIs "slice" $imgPull.targetSelector) -}}
|
||||
{{- if (mustHas $objectData.shortName $imgPull.targetSelector) -}}
|
||||
{{- $imgPullSecrets = mustAppend $imgPullSecrets $pullName -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* If not targetSelectAll or targetSelector, but is the primary pod */}}
|
||||
{{- else if $objectData.primary -}}
|
||||
{{- $imgPullSecrets = mustAppend $imgPullSecrets $pullName -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- range $imgPullSecrets }}
|
||||
- name: {{ . }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,91 @@
|
||||
{{/* Init Containers */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.initContainerSpawner" (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.pod.initContainerSpawner" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $initContainers := (dict "system" list
|
||||
"init" list
|
||||
"install" list
|
||||
"upgrade" list) -}}
|
||||
|
||||
{{- $types := (list "system" "init" "install" "upgrade") -}}
|
||||
|
||||
{{- $mergedContainers := $objectData.podSpec.initContainers -}}
|
||||
|
||||
{{- range $containerName, $containerValues := $mergedContainers -}}
|
||||
|
||||
{{- $enabled := $containerValues.enabled -}}
|
||||
{{- if kindIs "string" $enabled -}}
|
||||
{{- $enabled = tpl $enabled $rootCtx -}}
|
||||
|
||||
{{/* After tpl it becomes a string, not a bool */}}
|
||||
{{- if eq $enabled "true" -}}
|
||||
{{- $enabled = true -}}
|
||||
{{- else if eq $enabled "false" -}}
|
||||
{{- $enabled = false -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $enabled -}}
|
||||
|
||||
{{- if not ($containerValues.type) -}}
|
||||
{{- fail "InitContainer - Expected non-empty <type>" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $containerType := tpl $containerValues.type $rootCtx -}}
|
||||
{{- if not (mustHas $containerType $types) -}}
|
||||
{{- fail (printf "InitContainer - Expected <type> to be one of [%s], but got [%s]" (join ", " $types) $containerType) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $container := (mustDeepCopy $containerValues) -}}
|
||||
{{- $name := printf "%s-%s-%s" (include "tc.v1.common.lib.chart.names.fullname" $rootCtx) $containerType $containerName -}}
|
||||
|
||||
{{- $_ := set $container "name" $name -}}
|
||||
{{- $_ := set $container "shortName" $containerName -}}
|
||||
{{- $_ := set $container "podShortName" $objectData.shortName -}}
|
||||
{{- $_ := set $container "podPrimary" $objectData.primary -}}
|
||||
{{- $_ := set $container "podType" $objectData.type -}}
|
||||
|
||||
{{/* Remove keys that do not apply on init containers */}}
|
||||
{{- $_ := set $container "lifecycle" dict -}}
|
||||
{{- $_ := set $container "probes" dict -}}
|
||||
{{/* Template expects probes dict defined even if enabled */}}
|
||||
{{- $_ := set $container.probes "liveness" (dict "enabled" false) -}}
|
||||
{{- $_ := set $container.probes "readiness" (dict "enabled" false) -}}
|
||||
{{- $_ := set $container.probes "startup" (dict "enabled" false) -}}
|
||||
|
||||
{{/* Created from the pod.securityContext, used by fixedEnv */}}
|
||||
{{- $_ := set $container "calculatedFSGroup" $objectData.podSpec.calculatedFSGroup -}}
|
||||
|
||||
{{/* Append to list of containers based on type */}}
|
||||
{{- $tempContainers := (get $initContainers $containerType) -}}
|
||||
{{- $_ := set $initContainers $containerType (mustAppend $tempContainers $container) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $rootCtx.Release.IsInstall -}}
|
||||
{{- range $container := (get $initContainers "install") -}}
|
||||
{{- include "tc.v1.common.lib.pod.container" (dict "rootCtx" $rootCtx "objectData" $container) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $rootCtx.Release.IsUpgrade -}}
|
||||
{{- range $container := (get $initContainers "upgrade") -}}
|
||||
{{- include "tc.v1.common.lib.pod.container" (dict "rootCtx" $rootCtx "objectData" $container) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- range $container := (get $initContainers "system") -}}
|
||||
{{- include "tc.v1.common.lib.pod.container" (dict "rootCtx" $rootCtx "objectData" $container) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- range $container := (get $initContainers "init") -}}
|
||||
{{- include "tc.v1.common.lib.pod.container" (dict "rootCtx" $rootCtx "objectData" $container) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,33 @@
|
||||
{{/* Returns Node Selector */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.nodeSelector" (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.pod.nodeSelector" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $selectors := dict -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- with $rootCtx.Values.podOptions.nodeSelector -}}
|
||||
{{- $selectors = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pods option */}}
|
||||
{{- with $objectData.podSpec.nodeSelector -}}
|
||||
{{- $selectors = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and (include "tc.v1.common.lib.util.stopAll" $rootCtx) (eq $objectData.type "DaemonSet") }}
|
||||
"non-existing": "true"
|
||||
{{ else }}
|
||||
{{- range $k, $v := $selectors -}}
|
||||
{{- if not $v -}}
|
||||
{{- else }}
|
||||
{{ $k }}: {{ tpl $v $rootCtx }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,117 @@
|
||||
{{/* Returns Pod Security Context */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.securityContext" (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.pod.securityContext" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if not $rootCtx.Values.securityContext.pod -}}
|
||||
{{- fail "Pod - Expected non-empty <.Values.securityContext.pod>" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- $secContext := mustDeepCopy $rootCtx.Values.securityContext.pod -}}
|
||||
|
||||
{{/* Override with pods option */}}
|
||||
{{- with $objectData.podSpec.securityContext -}}
|
||||
{{- $secContext = mustMergeOverwrite $secContext . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $gpuAdded := false -}}
|
||||
{{- range $GPUValues := $rootCtx.Values.scaleGPU -}}
|
||||
{{/* If there is a selector and pod is selected */}}
|
||||
{{- if $GPUValues.targetSelector -}}
|
||||
{{- if mustHas $objectData.shortName ($GPUValues.targetSelector | keys) -}}
|
||||
{{- $gpuAdded = true -}}
|
||||
{{- end -}}
|
||||
{{/* If there is not a selector, but pod is primary */}}
|
||||
{{- else if $objectData.primary -}}
|
||||
{{- $gpuAdded = true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $deviceGroups := (list 5 10 20 24) -}}
|
||||
{{- $deviceAdded := false -}}
|
||||
{{- range $persistenceName, $persistenceValues := $rootCtx.Values.persistence -}}
|
||||
{{- if $persistenceValues.enabled -}}
|
||||
{{- if eq $persistenceValues.type "device" -}}
|
||||
{{- if $persistenceValues.targetSelectAll -}}
|
||||
{{- $deviceAdded = true -}}
|
||||
{{- else if $persistenceValues.targetSelector -}}
|
||||
{{- if mustHas $objectData.shortName ($persistenceValues.targetSelector | keys) -}}
|
||||
{{- $deviceAdded = true -}}
|
||||
{{- end -}}
|
||||
{{- else if $objectData.podPrimary -}}
|
||||
{{- $deviceAdded = true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $gpuAdded -}}
|
||||
{{- $_ := set $secContext "supplementalGroups" (concat $secContext.supplementalGroups (list 44 107)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $deviceAdded -}}
|
||||
{{- $_ := set $secContext "supplementalGroups" (concat $secContext.supplementalGroups $deviceGroups) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $_ := set $secContext "supplementalGroups" (concat $secContext.supplementalGroups (list 568)) -}}
|
||||
|
||||
{{- if not (deepEqual $secContext.supplementalGroups (mustUniq $secContext.supplementalGroups)) -}}
|
||||
{{- fail (printf "Pod - Expected <supplementalGroups> to have only unique values, but got [%s]" (join ", " $secContext.supplementalGroups)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $portRange := fromJson (include "tc.v1.common.lib.helpers.securityContext.getPortRange" (dict "rootCtx" $rootCtx "objectData" $objectData)) -}}
|
||||
{{/* If a container wants to bind a port <= 1024 change the unprivileged_port_start */}}
|
||||
{{- if and $portRange.low (le (int $portRange.low) 1024) -}}
|
||||
{{/* That sysctl is not supported when hostNet is enabled */}}
|
||||
{{- if ne (include "tc.v1.common.lib.pod.hostNetwork" (dict "rootCtx" $rootCtx "objectData" $objectData)) "true" -}}
|
||||
{{- $_ := set $secContext "sysctls" (mustAppend $secContext.sysctls (dict "name" "net.ipv4.ip_unprivileged_port_start" "value" (printf "%v" $portRange.low))) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if or (kindIs "invalid" $secContext.fsGroup) (eq (toString $secContext.fsGroup) "") -}}
|
||||
{{- fail "Pod - Expected non-empty <fsGroup>" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Used by the fixedEnv template */}}
|
||||
{{- $_ := set $objectData.podSpec "calculatedFSGroup" $secContext.fsGroup -}}
|
||||
|
||||
{{- if not $secContext.fsGroupChangePolicy -}}
|
||||
{{- fail "Pod - Expected non-empty <fsGroupChangePolicy>" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $policies := (list "Always" "OnRootMismatch") -}}
|
||||
{{- if not (mustHas $secContext.fsGroupChangePolicy $policies) -}}
|
||||
{{- fail (printf "Pod - Expected <fsGroupChangePolicy> to be one of [%s], but got [%s]" (join ", " $policies) $secContext.fsGroupChangePolicy) -}}
|
||||
{{- end }}
|
||||
fsGroup: {{ include "tc.v1.common.helper.makeIntOrNoop" $secContext.fsGroup }}
|
||||
fsGroupChangePolicy: {{ $secContext.fsGroupChangePolicy }}
|
||||
{{- with $secContext.supplementalGroups }}
|
||||
supplementalGroups:
|
||||
{{- range . }}
|
||||
- {{ include "tc.v1.common.helper.makeIntOrNoop" . }}
|
||||
{{- end -}}
|
||||
{{- else }}
|
||||
supplementalGroups: []
|
||||
{{- end -}}
|
||||
{{- with $secContext.sysctls }}
|
||||
sysctls:
|
||||
{{- range . }}
|
||||
{{- if not .name -}}
|
||||
{{- fail "Pod - Expected non-empty <name> in <sysctls>" -}}
|
||||
{{- end -}}
|
||||
{{- if not .value -}}
|
||||
{{- fail "Pod - Expected non-empty <value> in <sysctls>" -}}
|
||||
{{- end }}
|
||||
- name: {{ tpl .name $rootCtx | quote }}
|
||||
value: {{ tpl .value $rootCtx | quote }}
|
||||
{{- end -}}
|
||||
{{- else }}
|
||||
sysctls: []
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,24 @@
|
||||
{{/* Returns Priority Class Name */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.priorityClassName" (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.pod.priorityClassName" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $className := "" -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- with $rootCtx.Values.podOptions.priorityClassName -}}
|
||||
{{- $className = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pod's option */}}
|
||||
{{- with $objectData.podSpec.priorityClassName -}}
|
||||
{{- $className = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $className -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,34 @@
|
||||
{{/* Returns Restart Policy */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.restartPolicy" (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.pod.restartPolicy" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $policy := "Always" -}}
|
||||
|
||||
{{/* Initialize from the "defaults" */}}
|
||||
{{- with $rootCtx.Values.podOptions.restartPolicy -}}
|
||||
{{- $policy = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override from the pod values, if defined */}}
|
||||
{{- with $objectData.podSpec.restartPolicy -}}
|
||||
{{- $policy = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $policies := (list "Never" "Always" "OnFailure") -}}
|
||||
{{- if not (mustHas $policy $policies) -}}
|
||||
{{- fail (printf "Expected <restartPolicy to be one of [%s] but got [%s]" (join ", " $policies) $policy) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $types := (list "Deployment" "DaemonSet" "StatefulSet") -}}
|
||||
{{- if and (ne "Always" $policy) (mustHas $objectData.type $types) -}}
|
||||
{{- fail (printf "Expected <restartPolicy to be [Always] for [%s] but got [%s]" $objectData.type $policy) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $policy -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,57 @@
|
||||
{{/* Returns Runtime Class Name */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.runtimeClassName" (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.pod.runtimeClassName" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $runtime := "" -}}
|
||||
|
||||
{{/* Initialize from the "defaults" */}}
|
||||
{{- with $rootCtx.Values.podOptions.runtimeClassName -}}
|
||||
{{- $runtime = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override from the pod values, if defined */}}
|
||||
{{- with $objectData.podSpec.runtimeClassName -}}
|
||||
{{- $runtime = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if hasKey $rootCtx.Values.global "ixChartContext" -}}
|
||||
{{- if $rootCtx.Values.global.ixChartContext.addNvidiaRuntimeClass -}}
|
||||
|
||||
{{- range $rootCtx.Values.scaleGPU -}}
|
||||
{{- if .gpu -}} {{/* Make sure it has a value... */}}
|
||||
{{- $gpuAssigned := false -}}
|
||||
|
||||
{{- range $k, $v := .gpu -}}
|
||||
{{- if $v -}} {{/* Make sure value is not "0" or "" */}}
|
||||
{{- $gpuAssigned = true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $gpuAssigned -}}
|
||||
{{- if (kindIs "map" .targetSelector) -}}
|
||||
{{- range $podName, $containers := .targetSelector -}}
|
||||
{{- if eq $objectData.shortName $podName -}} {{/* If the pod is selected */}}
|
||||
{{- $runtime = $rootCtx.Values.global.ixChartContext.nvidiaRuntimeClassName -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- else if $objectData.primary -}}
|
||||
|
||||
{{/* If the pod is primary and no targetSelector is given, assign to primary */}}
|
||||
{{- $runtime = $rootCtx.Values.global.ixChartContext.nvidiaRuntimeClassName -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $runtime -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,24 @@
|
||||
{{/* Returns Scheduler Name */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.schedulerName" (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.pod.schedulerName" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $scheduler := "" -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- with $rootCtx.Values.podOptions.schedulerName -}}
|
||||
{{- $scheduler = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pod's option */}}
|
||||
{{- with $objectData.podSpec.schedulerName -}}
|
||||
{{- $scheduler = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $scheduler -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,48 @@
|
||||
{{/* Returns Service Account Name */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.serviceAccountName" (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.pod.serviceAccountName" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $saName := "default" -}}
|
||||
{{- $saNameCount := 0 -}}
|
||||
|
||||
{{- range $name, $serviceAccount := $rootCtx.Values.serviceAccount -}}
|
||||
{{- $tempName := include "tc.v1.common.lib.chart.names.fullname" $rootCtx -}}
|
||||
|
||||
{{- if not $serviceAccount.primary -}}
|
||||
{{- $tempName = (printf "%s-%s" $tempName $name) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $serviceAccount.enabled -}}
|
||||
{{/* If targetSelectAll is true */}}
|
||||
{{- if $serviceAccount.targetSelectAll -}}
|
||||
{{- $saName = $tempName -}}
|
||||
{{- $saNameCount = add1 $saNameCount -}}
|
||||
|
||||
{{/* Else if targetSelector is a list */}}
|
||||
{{- else if (kindIs "slice" $serviceAccount.targetSelector) -}}
|
||||
{{- if (mustHas $objectData.shortName $serviceAccount.targetSelector) -}}
|
||||
{{- $saName = $tempName -}}
|
||||
{{- $saNameCount = add1 $saNameCount -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* If not targetSelectAll or targetSelector, but is the primary pod */}}
|
||||
{{- else if $objectData.primary -}}
|
||||
{{- $saName = $tempName -}}
|
||||
{{- $saNameCount = add1 $saNameCount -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if gt $saNameCount 1 -}}
|
||||
{{- fail (printf "Expected at most 1 ServiceAccount to be assigned on a pod [%s]. But [%v] were assigned" $objectData.shortName $saNameCount) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $saName -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,24 @@
|
||||
{{/* Returns Share Process Namespace */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.shareProcessNamespace" (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.pod.shareProcessNamespace" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $shareProcessNamespace := false -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- if (kindIs "bool" $rootCtx.Values.podOptions.shareProcessNamespace) -}}
|
||||
{{- $shareProcessNamespace = $rootCtx.Values.podOptions.shareProcessNamespace -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pods option */}}
|
||||
{{- if (kindIs "bool" $objectData.podSpec.shareProcessNamespace) -}}
|
||||
{{- $shareProcessNamespace = $objectData.podSpec.shareProcessNamespace -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $shareProcessNamespace -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,29 @@
|
||||
{{/* Returns Termination Grace Period Seconds */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.terminationGracePeriodSeconds" (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.pod.terminationGracePeriodSeconds" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $gracePeriod := "" -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- with $rootCtx.Values.podOptions.terminationGracePeriodSeconds -}}
|
||||
{{- $gracePeriod = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pod's option */}}
|
||||
{{- with $objectData.podSpec.terminationGracePeriodSeconds -}}
|
||||
{{- $gracePeriod = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Expand tpl */}}
|
||||
{{- if (kindIs "string" $gracePeriod) -}}
|
||||
{{- $gracePeriod = tpl $gracePeriod $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $gracePeriod -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,67 @@
|
||||
{{/* Returns Tolerations */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.tolerations" (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.pod.tolerations" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $tolerations := list -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- with $rootCtx.Values.podOptions.tolerations -}}
|
||||
{{- $tolerations = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override from the "pod" option */}}
|
||||
{{- with $objectData.podSpec.tolerations -}}
|
||||
{{- $tolerations = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- range $tolerations -}}
|
||||
{{/* Expand values */}}
|
||||
{{- $operator := (tpl (.operator | default "") $rootCtx) -}}
|
||||
{{- $key := (tpl (.key | default "") $rootCtx) -}}
|
||||
{{- $value := (tpl (.value | default "") $rootCtx) -}}
|
||||
{{- $effect := (tpl (.effect | default "") $rootCtx) -}}
|
||||
{{- $tolSeconds := .tolerationSeconds -}}
|
||||
|
||||
{{- $operators := (list "Exists" "Equal") -}}
|
||||
{{- if not (mustHas $operator $operators) -}}
|
||||
{{- fail (printf "Expected <tolerations.operator> to be one of [%s] but got [%s]" (join ", " $operators) $operator) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and (eq $operator "Equal") (or (not $key) (not $value)) -}}
|
||||
{{- fail "Expected non-empty <tolerations.key> and <tolerations.value> with <tolerations.operator> set to [Equal]" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and (eq $operator "Exists") $value -}}
|
||||
{{- fail (printf "Expected empty <tolerations.value> with <tolerations.operator> set to [Exists], but got [%s]" $value) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $effects := (list "NoExecute" "NoSchedule" "PreferNoSchedule") -}}
|
||||
{{- if and $effect (not (mustHas $effect $effects)) -}}
|
||||
{{- fail (printf "Expected <tolerations.effect> to be one of [%s], but got [%s]" (join ", " $effects) $effect) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and (not (kindIs "invalid" $tolSeconds)) (not (mustHas (kindOf $tolSeconds) (list "int" "int64" "float64"))) -}}
|
||||
{{- fail (printf "Expected <tolerations.tolerationSeconds> to be a number, but got [%v]" $tolSeconds) -}}
|
||||
{{- end }}
|
||||
- operator: {{ $operator }}
|
||||
{{- with $key }}
|
||||
key: {{ $key }}
|
||||
{{- end -}}
|
||||
{{- with $effect }}
|
||||
effect: {{ $effect }}
|
||||
{{- end -}}
|
||||
{{- with $value }}
|
||||
value: {{ . }}
|
||||
{{- end -}}
|
||||
{{- if (mustHas (kindOf $tolSeconds) (list "int" "int64" "float64")) }}
|
||||
tolerationSeconds: {{ $tolSeconds }}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,44 @@
|
||||
{{/* Returns topologySpreadConstraints */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.topologySpreadConstraints" (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.pod.topologySpreadConstraints" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $constraints := list -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- with $rootCtx.Values.podOptions.topologySpreadConstraints -}}
|
||||
{{- $constraints = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override with pods option */}}
|
||||
{{- with $objectData.podSpec.topologySpreadConstraints -}}
|
||||
{{- $constraints = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and ( or ( eq $objectData.type "Deployment" ) ( eq $objectData.type "StatefulSet" )) $rootCtx.Values.podOptions.defaultSpread -}}
|
||||
- maxSkew: 1
|
||||
whenUnsatisfiable: ScheduleAnyway
|
||||
topologyKey: "truecharts.org/rack"
|
||||
labelSelector:
|
||||
matchLabels:
|
||||
{{- include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.name) | indent 6 }}
|
||||
nodeAffinityPolicy: Honor
|
||||
nodeTaintsPolicy: Honor
|
||||
- maxSkew: 1
|
||||
whenUnsatisfiable: ScheduleAnyway
|
||||
topologyKey: "kubernetes.io/hostname"
|
||||
labelSelector:
|
||||
matchLabels:
|
||||
{{- include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.name) | indent 6 }}
|
||||
nodeAffinityPolicy: Honor
|
||||
nodeTaintsPolicy: Honor
|
||||
{{- end -}}
|
||||
{{ with $constraints }}
|
||||
{{ . | toYaml | indent 0 }}
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,68 @@
|
||||
{{/* Returns Volumes */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.volumes" (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.pod.volumes" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- range $name, $persistenceValues := $rootCtx.Values.persistence -}}
|
||||
{{- if $persistenceValues.enabled -}}
|
||||
{{- $persistence := (mustDeepCopy $persistenceValues) -}}
|
||||
{{- $_ := set $persistence "shortName" $name -}}
|
||||
|
||||
{{- $selected := false -}}
|
||||
|
||||
{{/* If set to true, define volume */}}
|
||||
{{- if $persistence.targetSelectAll -}}
|
||||
{{- $selected = true -}}
|
||||
|
||||
{{/* If the pod is the autopermission */}}
|
||||
{{- else if eq $objectData.shortName "autopermissions" -}}
|
||||
{{- if $persistence.autoPermissions -}}
|
||||
{{- if $persistence.autoPermissions.enabled -}}
|
||||
{{- $selected = true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* If targetSelector is set, check if pod is selected */}}
|
||||
{{- else if $persistence.targetSelector -}}
|
||||
{{- if (mustHas $objectData.shortName (keys $persistence.targetSelector)) -}}
|
||||
{{- $selected = true -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* If no targetSelector is set or targetSelectAll, check if pod is primary */}}
|
||||
{{- else if $objectData.primary -}}
|
||||
{{- $selected = true -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* If pod selected */}}
|
||||
{{- if $selected -}}
|
||||
{{/* Define the volume based on type */}}
|
||||
{{- $type := ($persistence.type | default $rootCtx.Values.fallbackDefaults.persistenceType) -}}
|
||||
|
||||
{{- if eq "pvc" $type -}}
|
||||
{{- include "tc.v1.common.lib.pod.volume.pvc" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- else if eq "ixVolume" $type -}}
|
||||
{{- include "tc.v1.common.lib.pod.volume.ixVolume" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- else if eq "hostPath" $type -}}
|
||||
{{- include "tc.v1.common.lib.pod.volume.hostPath" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- else if eq "secret" $type -}}
|
||||
{{- include "tc.v1.common.lib.pod.volume.secret" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- else if eq "configmap" $type -}}
|
||||
{{- include "tc.v1.common.lib.pod.volume.configmap" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- else if eq "emptyDir" $type -}}
|
||||
{{- include "tc.v1.common.lib.pod.volume.emptyDir" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- else if eq "nfs" $type -}}
|
||||
{{- include "tc.v1.common.lib.pod.volume.nfs" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- else if eq "device" $type -}}
|
||||
{{- include "tc.v1.common.lib.pod.volume.device" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,70 @@
|
||||
{{/* Returns ConfigMap Volume */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.volume.configmap" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data to be used to render the volume.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.pod.volume.configmap" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if not $objectData.objectName -}}
|
||||
{{- fail "Persistence - Expected non-empty <objectName> on <configmap> type" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $objectName := tpl $objectData.objectName $rootCtx -}}
|
||||
{{- $expandName := true -}}
|
||||
{{- if kindIs "bool" $objectData.expandObjectName -}}
|
||||
{{- $expandName = $objectData.expandObjectName -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $expandName -}}
|
||||
{{- $object := (get $rootCtx.Values.configmap $objectName) -}}
|
||||
{{- if and (not $object) (not $objectData.optional) -}}
|
||||
{{- fail (printf "Persistence - Expected configmap [%s] defined in <objectName> to exist" $objectName) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $objectName = (printf "%s-%s" (include "tc.v1.common.lib.chart.names.fullname" $rootCtx) $objectName) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $optional := false -}}
|
||||
{{- if hasKey $objectData "optional" -}}
|
||||
{{- if not (kindIs "bool" $objectData.optional) -}}
|
||||
{{- fail (printf "Persistence - Expected <optional> to be [bool], but got [%s]" (kindOf $objectData.optional)) -}}
|
||||
{{- end -}}
|
||||
{{- $optional = $objectData.optional -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $defMode := "" -}}
|
||||
{{- if (and $objectData.defaultMode (not (kindIs "string" $objectData.defaultMode))) -}}
|
||||
{{- fail (printf "Persistence - Expected <defaultMode> to be [string], but got [%s]" (kindOf $objectData.defaultMode)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $objectData.defaultMode -}}
|
||||
{{- $defMode = tpl $objectData.defaultMode $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $defMode (not (mustRegexMatch "^[0-9]{4}$" $defMode)) -}}
|
||||
{{- fail (printf "Persistence - Expected <defaultMode> to have be in format of [\"0777\"], but got [%q]" $defMode) -}}
|
||||
{{- end }}
|
||||
- name: {{ $objectData.shortName }}
|
||||
configMap:
|
||||
name: {{ $objectName }}
|
||||
{{- with $defMode }}
|
||||
defaultMode: {{ . }}
|
||||
{{- end }}
|
||||
optional: {{ $optional }}
|
||||
{{- with $objectData.items }}
|
||||
items:
|
||||
{{- range . -}}
|
||||
{{- if not .key -}}
|
||||
{{- fail "Persistence - Expected non-empty <items.key>" -}}
|
||||
{{- end -}}
|
||||
{{- if not .path -}}
|
||||
{{- fail "Persistence - Expected non-empty <items.path>" -}}
|
||||
{{- end }}
|
||||
- key: {{ tpl .key $rootCtx }}
|
||||
path: {{ tpl .path $rootCtx }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,53 @@
|
||||
{{/* Returns device (hostPath) Volume */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.volume.device" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data to be used to render the volume.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.pod.volume.device" -}}
|
||||
{{- $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 <device> type" -}}
|
||||
{{- end -}}
|
||||
{{- $hostPath := tpl $objectData.hostPath $rootCtx -}}
|
||||
|
||||
{{- if not (hasPrefix "/" $hostPath) -}}
|
||||
{{- fail "Persistence - Expected <hostPath> to start with a forward slash [/] on <device> type" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $charDevices := (list "tty") -}}
|
||||
{{- if not $hostPathType -}}
|
||||
{{- range $char := $charDevices -}}
|
||||
{{- if hasPrefix (printf "/dev/%v" $char) $hostPath -}}
|
||||
{{- $hostPathType = "CharDevice" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $blockDevices := (list "sd" "hd" "nvme") -}}
|
||||
{{- if not $hostPathType -}}
|
||||
{{- range $block := $blockDevices -}}
|
||||
{{- if hasPrefix (printf "/dev/%v" $block) $hostPath -}}
|
||||
{{- $hostPathType = "BlockDevice" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- 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 -}}
|
||||
@@ -0,0 +1,43 @@
|
||||
{{/* Returns emptyDir Volume */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.volume.emptyDir" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data to be used to render the volume.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.pod.volume.emptyDir" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $medium := "" -}}
|
||||
{{- $size := "" -}}
|
||||
{{- with $objectData.medium -}}
|
||||
{{- $medium = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
{{- with $objectData.size -}}
|
||||
{{- $size = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $size -}}
|
||||
{{/* Size: https://regex101.com/r/NNPV2D/1 */}}
|
||||
{{- if not (mustRegexMatch "^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$" (toString $size)) -}}
|
||||
{{- $formats := "(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)" -}}
|
||||
{{- fail (printf "Persistence Expected <size> to have one of the following formats [%s], but got [%s]" $formats $size) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $medium (ne $medium "Memory") -}}
|
||||
{{- fail (printf "Persistence - Expected [medium] to be one of [\"\", Memory], but got [%s] on <emptyDir> type" $medium) -}}
|
||||
{{- end }}
|
||||
- name: {{ $objectData.shortName }}
|
||||
{{- if or $medium $size }}
|
||||
emptyDir:
|
||||
{{- if $medium }}
|
||||
medium: {{ $medium }}
|
||||
{{- end -}}
|
||||
{{- if $size }}
|
||||
sizeLimit: {{ $size }}
|
||||
{{- end -}}
|
||||
{{- else }}
|
||||
emptyDir: {}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,35 @@
|
||||
{{/* Returns hostPath Volume */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.volume.hostPath" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data to be used to render the volume.
|
||||
*/}}
|
||||
{{- define "tc.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 -}}
|
||||
@@ -0,0 +1,56 @@
|
||||
{{/* Returns ixVolume Volume */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.volume.ixVolume" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data to be used to render the volume.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.pod.volume.ixVolume" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $hostPathType := "" -}}
|
||||
{{- if $objectData.hostPathType -}}
|
||||
{{- $hostPathType = tpl $objectData.hostPathType $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not $objectData.datasetName -}}
|
||||
{{- fail "Persistence - Expected non-empty <datasetName> on <ixVolume> type" -}}
|
||||
{{- end -}}
|
||||
{{- $datasetName := tpl $objectData.datasetName $rootCtx -}}
|
||||
|
||||
{{- if not $rootCtx.Values.ixVolumes -}}
|
||||
{{- fail "Persistence - Expected non-empty <ixVolumes> in values on <ixVolume> type" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $hostPath := "" -}}
|
||||
{{- $found := false -}}
|
||||
{{- range $idx, $normalizedHostPath := $rootCtx.Values.ixVolumes -}}
|
||||
{{- if eq $datasetName (base $normalizedHostPath.hostPath) -}}
|
||||
{{- $found = true -}}
|
||||
{{- $hostPath = $normalizedHostPath.hostPath -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not $found -}} {{/* If we go over the ixVolumes and we dont find a match, fail */}}
|
||||
{{- $datasets := list -}}
|
||||
{{- range $rootCtx.Values.ixVolumes -}}
|
||||
{{- $datasets = mustAppend $datasets (base .hostPath) -}}
|
||||
{{- end -}}
|
||||
{{- fail (printf "Persistence - Expected <datasetName> [%s] to exist on <ixVolumes> list, but list contained [%s] on <ixVolume> type" $datasetName (join ", " $datasets)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not (hasPrefix "/" $hostPath) -}}
|
||||
{{- fail "Persistence - Expected normalized path from <ixVolumes> to start with a forward slash [/] on <ixVolume> 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 -}}
|
||||
@@ -0,0 +1,27 @@
|
||||
{{/* Returns NFS Volume */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.volume.nfs" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data to be used to render the volume.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.pod.volume.nfs" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if not $objectData.path -}}
|
||||
{{- 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" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not $objectData.server -}}
|
||||
{{- fail "Persistence - Expected non-empty <server> on <nfs> type" -}}
|
||||
{{- end }}
|
||||
- name: {{ $objectData.shortName }}
|
||||
nfs:
|
||||
path: {{ $path }}
|
||||
server: {{ tpl $objectData.server $rootCtx }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,18 @@
|
||||
{{/* Returns PVC Volume */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.volume.pvc" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data to be used to render the volume.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.pod.volume.pvc" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $pvcName := (printf "%s-%s" (include "tc.v1.common.lib.chart.names.fullname" $rootCtx) $objectData.shortName) -}}
|
||||
{{- with $objectData.existingClaim -}}
|
||||
{{- $pvcName = tpl . $rootCtx -}}
|
||||
{{- end }}
|
||||
- name: {{ $objectData.shortName }}
|
||||
persistentVolumeClaim:
|
||||
claimName: {{ $pvcName }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,71 @@
|
||||
{{/* Returns Secret Volume */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.pod.volume.secret" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data to be used to render the volume.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.pod.volume.secret" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if not $objectData.objectName -}}
|
||||
{{- fail "Persistence - Expected non-empty <objectName> on <secret> type" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $objectName := tpl $objectData.objectName $rootCtx -}}
|
||||
{{- $expandName := true -}}
|
||||
{{- if kindIs "bool" $objectData.expandObjectName -}}
|
||||
{{- $expandName = $objectData.expandObjectName -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $expandName -}}
|
||||
{{- $object := (get $rootCtx.Values.secret $objectName) -}}
|
||||
{{- $certObject := (get $rootCtx.Values.scaleCertificate $objectName) -}}
|
||||
{{- if and (not $object) (not $certObject) (not $objectData.optional) -}}
|
||||
{{- fail (printf "Persistence - Expected secret [%s] defined in <objectName> to exist" $objectName) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $objectName = (printf "%s-%s" (include "tc.v1.common.lib.chart.names.fullname" $rootCtx) $objectName) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $optional := false -}}
|
||||
{{- if hasKey $objectData "optional" -}}
|
||||
{{- if not (kindIs "bool" $objectData.optional) -}}
|
||||
{{- fail (printf "Persistence - Expected <optional> to be [bool], but got [%s]" (kindOf $objectData.optional)) -}}
|
||||
{{- end -}}
|
||||
{{- $optional = $objectData.optional -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $defMode := "" -}}
|
||||
{{- if (and $objectData.defaultMode (not (kindIs "string" $objectData.defaultMode))) -}}
|
||||
{{- fail (printf "Persistence - Expected <defaultMode> to be [string], but got [%s]" (kindOf $objectData.defaultMode)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $objectData.defaultMode -}}
|
||||
{{- $defMode = tpl $objectData.defaultMode $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $defMode (not (mustRegexMatch "^[0-9]{4}$" $defMode)) -}}
|
||||
{{- fail (printf "Persistence - Expected <defaultMode> to have be in format of [\"0777\"], but got [%q]" $defMode) -}}
|
||||
{{- end }}
|
||||
- name: {{ $objectData.shortName }}
|
||||
secret:
|
||||
secretName: {{ $objectName }}
|
||||
{{- with $defMode }}
|
||||
defaultMode: {{ . }}
|
||||
{{- end }}
|
||||
optional: {{ $optional }}
|
||||
{{- with $objectData.items }}
|
||||
items:
|
||||
{{- range . -}}
|
||||
{{- if not .key -}}
|
||||
{{- fail "Persistence - Expected non-empty <items.key>" -}}
|
||||
{{- end -}}
|
||||
{{- if not .path -}}
|
||||
{{- fail "Persistence - Expected non-empty <items.path>" -}}
|
||||
{{- end }}
|
||||
- key: {{ tpl .key $rootCtx }}
|
||||
path: {{ tpl .path $rootCtx }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user