helm-charts/charts/library/common/templates/lib/container/fields/_probes.tpl
Bernd Schorgers 8b33237e27
feat(common): Release library 3.7.0 (#377)
Signed-off-by: solidDoWant <fred.heinecke@yahoo.com>
Co-authored-by: Patrick Collins <Patricol@users.noreply.github.com>
Co-authored-by: Patrick Collins <patrick.collins@gainbridge.io>
Co-authored-by: Lawrence Gil <larrywtf609@gmail.com>
Co-authored-by: solidDoWant <fred.heinecke@yahoo.com>
2025-02-07 20:03:04 +01:00

91 lines
4.2 KiB
Smarty

{{/*
Probes used by the container.
*/}}
{{- define "bjw-s.common.lib.container.field.probes" -}}
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $controllerObject := $ctx.controllerObject -}}
{{- $containerObject := $ctx.containerObject -}}
{{- /* Default to empty dict */ -}}
{{- $enabledProbes := dict -}}
{{- range $probeName, $probeValues := $containerObject.probes -}}
{{- /* Disable probe by default, but allow override */ -}}
{{- $probeEnabled := false -}}
{{- if hasKey $probeValues "enabled" -}}
{{- $probeEnabled = $probeValues.enabled -}}
{{- end -}}
{{- if $probeEnabled -}}
{{- $probeDefinition := dict -}}
{{- if $probeValues.custom -}}
{{- $parsedProbeSpec := tpl ($probeValues.spec | toYaml) $rootContext -}}
{{- $probeDefinition = $parsedProbeSpec | fromYaml -}}
{{- else -}}
{{- $probeSpec := dig "spec" dict $probeValues -}}
{{- $primaryService := include "bjw-s.common.lib.service.primaryForController" (dict "rootContext" $rootContext "controllerIdentifier" $controllerObject.identifier) | fromYaml -}}
{{- $primaryServiceDefaultPort := dict -}}
{{- if $primaryService -}}
{{- $primaryServiceDefaultPort = include "bjw-s.common.lib.service.primaryPort" (dict "rootContext" $rootContext "serviceObject" $primaryService) | fromYaml -}}
{{- end -}}
{{- if $primaryServiceDefaultPort -}}
{{- $probeType := "" -}}
{{- if eq $probeValues.type "AUTO" -}}
{{- $probeType = $primaryServiceDefaultPort.protocol -}}
{{- else -}}
{{- $probeType = $probeValues.type | default "TCP" -}}
{{- end -}}
{{- $_ := set $probeDefinition "initialDelaySeconds" (include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" $probeSpec.initialDelaySeconds "default" 0) | int) -}}
{{- $_ := set $probeDefinition "failureThreshold" (include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" $probeSpec.failureThreshold "default" 3) | int) -}}
{{- $_ := set $probeDefinition "timeoutSeconds" (include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" $probeSpec.timeoutSeconds "default" 1) | int) -}}
{{- $_ := set $probeDefinition "periodSeconds" (include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" $probeSpec.periodSeconds "default" 10) | int) -}}
{{- $probeHeader := "" -}}
{{- if or ( eq $probeType "HTTPS" ) ( eq $probeType "HTTP" ) -}}
{{- $probeHeader = "httpGet" -}}
{{- $_ := set $probeDefinition $probeHeader (
dict
"path" $probeValues.path
"scheme" $probeType
)
-}}
{{- else if (eq $probeType "GRPC") -}}
{{- $probeHeader = "grpc" -}}
{{- $_ := set $probeDefinition $probeHeader dict -}}
{{- if $probeValues.service -}}
{{- $_ := set (index $probeDefinition $probeHeader) "service" $probeValues.service -}}
{{- end -}}
{{- else -}}
{{- $probeHeader = "tcpSocket" -}}
{{- $_ := set $probeDefinition $probeHeader dict -}}
{{- end -}}
{{- if $probeValues.port -}}
{{- if kindIs "float64" $probeValues.port -}}
{{- $_ := set (index $probeDefinition $probeHeader) "port" $probeValues.port -}}
{{- else if kindIs "string" $probeValues.port -}}
{{- $_ := set (index $probeDefinition $probeHeader) "port" (tpl ( $probeValues.port | toString ) $rootContext) -}}
{{- end -}}
{{- else if $primaryServiceDefaultPort.targetPort -}}
{{- $_ := set (index $probeDefinition $probeHeader) "port" $primaryServiceDefaultPort.targetPort -}}
{{- else -}}
{{- $_ := set (index $probeDefinition $probeHeader) "port" ($primaryServiceDefaultPort.port | toString | atoi ) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $probeDefinition -}}
{{- $_ := set $enabledProbes (printf "%sProbe" $probeName) $probeDefinition -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- with $enabledProbes -}}
{{- . | toYaml -}}
{{- end -}}
{{- end -}}