This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
{{/* Check Env for Duplicates */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.helper.container.envDupeCheck" (dict "rootCtx" $ "objectData" $objectData "source" $source "key" $key) }}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The object data to be used to render the container.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.helper.container.envDupeCheck" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $source := .source -}}
|
||||
{{- $type := .type -}}
|
||||
{{- $key := .key -}}
|
||||
|
||||
{{- $dupeEnv := (get $objectData.envDupe $key) -}}
|
||||
|
||||
{{- if $dupeEnv -}}
|
||||
{{- fail (printf "Container - Environment Variable [%s] in [%s] tried to override the Environment Variable that is already defined in [%s]" $key $source $dupeEnv.source) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $_ := set $objectData.envDupe $key (dict "source" $source) -}}
|
||||
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,59 @@
|
||||
{{/* Returns Lowest and Highest ports assigned to the any container in the pod */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.helpers.securityContext.getPortRange" (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.helpers.securityContext.getPortRange" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{ $portRange := (dict "high" 0 "low" 0) }}
|
||||
|
||||
{{- range $name, $service := $rootCtx.Values.service -}}
|
||||
{{- $selected := false -}}
|
||||
{{/* If service is enabled... */}}
|
||||
{{- if $service.enabled -}}
|
||||
|
||||
{{/* If there is a selector */}}
|
||||
{{- if $service.targetSelector -}}
|
||||
|
||||
{{/* And pod is selected */}}
|
||||
{{- if eq $service.targetSelector $objectData.shortName -}}
|
||||
{{- $selected = true -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- else -}}
|
||||
{{/* If no selector is defined but pod is primary */}}
|
||||
{{- if $objectData.primary -}}
|
||||
{{- $selected = true -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $selected -}}
|
||||
{{- range $name, $portValues := $service.ports -}}
|
||||
{{- if $portValues.enabled -}}
|
||||
|
||||
{{- $portToCheck := ($portValues.targetPort | default $portValues.port) -}}
|
||||
{{- if kindIs "string" $portToCheck -}}
|
||||
{{- $portToCheck = (tpl $portToCheck $rootCtx) | int -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if or (not $portRange.low) (lt ($portToCheck | int) ($portRange.low | int)) -}}
|
||||
{{- $_ := set $portRange "low" $portToCheck -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if or (not $portRange.high) (gt ($portToCheck | int) ($portRange.high | int)) -}}
|
||||
{{- $_ := set $portRange "high" $portToCheck -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{- $portRange | toJson -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,47 @@
|
||||
{{/* Service - Get Selected Pod */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.helpers.getSelectedPodValues" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
objectData: The object data of the service
|
||||
rootCtx: The root context of the chart.
|
||||
*/}}
|
||||
|
||||
{{- define "tc.v1.common.lib.helpers.getSelectedPodValues" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
{{- $caller := .caller -}}
|
||||
|
||||
{{- $podValues := dict -}}
|
||||
{{- with $objectData.targetSelector -}}
|
||||
{{- $podValues = mustDeepCopy (get $rootCtx.Values.workload .) -}}
|
||||
|
||||
{{- if not $podValues -}}
|
||||
{{- fail (printf "%s - Selected pod [%s] is not defined" $caller .) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not $podValues.enabled -}}
|
||||
{{- fail (printf "%s - Selected pod [%s] is not enabled" $caller .) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* While we know the shortName from targetSelector, let's set it explicitly
|
||||
So service can reference this directly, to match the behaviour of a service
|
||||
without targetSelector defined (assumes "use primary") */}}
|
||||
{{- $_ := set $podValues "shortName" . -}}
|
||||
{{- else -}}
|
||||
|
||||
{{/* If no targetSelector is defined, we assume the service is using the primary pod */}}
|
||||
{{/* Also no need to check for multiple primaries here, it's already done on the workload validation */}}
|
||||
{{- range $podName, $pod := $rootCtx.Values.workload -}}
|
||||
{{- if $pod.enabled -}}
|
||||
{{- if $pod.primary -}}
|
||||
{{- $podValues = mustDeepCopy $pod -}}
|
||||
{{/* Set the shortName so service can use this on selector */}}
|
||||
{{- $_ := set $podValues "shortName" $podName -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{/* Return values in Json, to preserve types */}}
|
||||
{{ $podValues | toJson }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,47 @@
|
||||
{{/* Service - Get Selected Service */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.helpers.getSelectedServiceValues" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
objectData: The object data of the service
|
||||
rootCtx: The root context of the chart.
|
||||
*/}}
|
||||
|
||||
{{- define "tc.v1.common.lib.helpers.getSelectedServiceValues" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
{{- $caller := .caller -}}
|
||||
|
||||
{{- $serviceValues := dict -}}
|
||||
{{- with $objectData.targetSelector -}}
|
||||
{{- $serviceValues = mustDeepCopy (get $rootCtx.Values.service .) -}}
|
||||
|
||||
{{- if not $serviceValues -}}
|
||||
{{- fail (printf "%s - Selected service [%s] is not defined" $caller .) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not $serviceValues.enabled -}}
|
||||
{{- fail (printf "%s - Selected service [%s] is not enabled" $caller .) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* While we know the shortName from targetSelector, let's set it explicitly
|
||||
So service can reference this directly, to match the behaviour of a service
|
||||
without targetSelector defined (assumes "use primary") */}}
|
||||
{{- $_ := set $serviceValues "shortName" . -}}
|
||||
{{- else -}}
|
||||
|
||||
{{/* If no targetSelector is defined, we assume the service is using the primary service */}}
|
||||
{{/* Also no need to check for multiple primaries here, it's already done on the service validation */}}
|
||||
{{- range $serviceName, $service := $rootCtx.Values.service -}}
|
||||
{{- if $service.enabled -}}
|
||||
{{- if $service.primary -}}
|
||||
{{- $serviceValues = mustDeepCopy $service -}}
|
||||
{{/* Set the shortName so service can use this on selector */}}
|
||||
{{- $_ := set $serviceValues "shortName" $serviceName -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{/* Return values in Json, to preserve types */}}
|
||||
{{ $serviceValues | toJson }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,21 @@
|
||||
{{- define "tc.v1.common.helper.makeIntOrNoop" -}}
|
||||
{{- $value := . -}}
|
||||
|
||||
{{/*
|
||||
- Ints in Helm can be either int, int64 or float64.
|
||||
- Values that start with zero should not be converted
|
||||
to int again as this will strip leading zeros.
|
||||
- Numbers converted to E notation by Helm will
|
||||
always contain the "e" character. So we only
|
||||
convert those.
|
||||
*/}}
|
||||
{{- if and
|
||||
(mustHas (kindOf $value) (list "int" "int64" "float64"))
|
||||
(not (hasPrefix "0" ($value | toString)))
|
||||
(contains "e" ($value | toString | lower))
|
||||
-}}
|
||||
{{- $value | int -}}
|
||||
{{- else -}}
|
||||
{{- $value -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user