From e1fd7d864d60a492bec05996afca77595e2e8a70 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Fri, 2 Dec 2022 13:26:11 +0200 Subject: [PATCH] cleanup probes --- .../1.0.0/templates/lib/container/_probes.tpl | 98 ++++++++----------- .../lib/container/probeUtils/_custom.tpl | 1 + .../lib/container/probeUtils/_exec.tpl | 1 + .../lib/container/probeUtils/_grpc.tpl | 1 + .../lib/container/probeUtils/_httpGet.tpl | 1 + .../lib/container/probeUtils/_tcp.tpl | 1 + .../lib/container/probeUtils/_timeouts.tpl | 22 +++++ .../lib/container/probeUtils/_udp.tpl | 1 + 8 files changed, 67 insertions(+), 59 deletions(-) create mode 100644 library/common/1.0.0/templates/lib/container/probeUtils/_timeouts.tpl diff --git a/library/common/1.0.0/templates/lib/container/_probes.tpl b/library/common/1.0.0/templates/lib/container/_probes.tpl index efae3abf48..adf303b858 100644 --- a/library/common/1.0.0/templates/lib/container/_probes.tpl +++ b/library/common/1.0.0/templates/lib/container/_probes.tpl @@ -3,91 +3,71 @@ {{- $primarySeriviceName := (include "ix.v1.common.lib.util.service.primary" .) -}} {{/* Get the name of the primary service, if any */}} {{- $primaryService := get .Values.service $primarySeriviceName -}} {{/* Get service values of the primary service, if any */}} {{- $primaryPort := "" -}} + {{- $defaultProbeType := .Values.global.defaults.defaultProbeType -}} {{- if $primaryService -}} {{- $primaryPort = get $primaryService.ports (include "ix.v1.common.lib.util.service.ports.primary" (dict "values" $primaryService "svcName" $primarySeriviceName)) -}} {{- end -}} - {{- $defaultProbeType := .Values.global.defaults.defaultProbeType -}} - {{- range $probeName, $probe := .Values.probes -}} {{- if not (has $probeName (list "liveness" "readiness" "startup")) -}} {{- fail (printf "Invalid probe name (%s). Valid options are (liveness, readiness, startup)" $probeName) -}} {{- end -}} - {{- $probeType := $defaultProbeType -}} + {{- $probeType := "" -}} {{- if $probe.enabled -}} - {{/* Prepare a temp Probe to pass in the probe definition function */}} - {{- $tmpProbe := dict -}} - {{- $_ := set $tmpProbe "name" $probeName -}} - {{- $_ := set $tmpProbe "spec" $probe.spec }} -{{ $probeName }}Probe: - {{- if $probe.custom -}} {{/* Allows to add a custom definition on the probe */}} - {{- include "ix.v1.common.container.probes.custom" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} + {{- if $probe.custom -}} + {{ $probeType = "CUSTOM" }} {{- else if eq $probe.type "EXEC" -}} - {{- $_ := set $tmpProbe "type" $probe.type -}} - {{- $_ := set $tmpProbe "command" $probe.command -}} - {{- include "ix.v1.common.container.probes.exec" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} + {{ $probeType = "EXEC" }} {{- else -}} {{- if and $primaryService $primaryPort -}} {{- if $probe.type -}} {{- if eq $probe.type "AUTO" -}} {{- $probeType = $primaryPort.protocol -}} {{- else -}} - {{- if not (has $probe.type (list "TCP" "HTTP" "HTTPS" "GRPC")) -}} + {{- if not (has $probe.type (list "TCP" "HTTP" "HTTPS" "GRPC" "UDP")) -}} {{- fail (printf "Invalid probe type (%s) on probe (%s)" $probe.type $probeName) -}} {{- end -}} {{- $probeType = $probe.type -}} {{- end -}} - {{- end -}} - - {{- $_ := set $tmpProbe "type" $probeType -}} - - {{- $probePort := $primaryPort.port -}} - {{- if $probe.port -}} - {{- $probePort = (tpl ($probe.port | toString) $) -}} - {{- else if $primaryPort.targetPort -}} - {{- $probePort = $primaryPort.targetPort -}} - {{- end -}} - - {{- $_ := set $tmpProbe "port" $probePort -}} - - {{- if has $probeType (list "HTTPS" "HTTP") -}} - {{- $_ := set $tmpProbe "path" $probe.path -}} - {{- $_ := set $tmpProbe "httpHeaders" $probe.httpHeaders }} - {{- include "ix.v1.common.container.probes.httpGet" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} - {{- else if (eq $probeType "TCP") }} - {{- include "ix.v1.common.container.probes.tcp" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} - {{- else if (eq $probeType "GRPC") }} - {{- include "ix.v1.common.container.probes.grpc" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} - {{- else if (eq $probeType "UDP") }} - {{- include "ix.v1.common.container.probes.udp" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} + {{- else -}} + {{- $probeType := $defaultProbeType -}} {{- end -}} {{- else -}} {{- fail (printf "Only custom probes are allowed when service is disabled (%s)" $probeName) -}} {{- end -}} {{- end -}} + + {{- $probePort := $primaryPort.port -}} + {{- if $probe.port -}} + {{- $probePort = (tpl ($probe.port | toString) $) -}} + {{- else if $primaryPort.targetPort -}} + {{- $probePort = $primaryPort.targetPort -}} + {{- end -}} + + {{- $tmpProbe := dict -}}{{/* Prepare a temp Probe to pass in the probe definition function */}} + {{- $_ := set $tmpProbe "name" $probeName -}} + {{- $_ := set $tmpProbe "spec" $probe.spec -}} + {{- $_ := set $tmpProbe "type" $probeType -}} + {{- $_ := set $tmpProbe "port" $probePort }} +{{ $probeName }}Probe: + {{- if has $probeType (list "HTTPS" "HTTP") -}} + {{- $_ := set $tmpProbe "path" $probe.path -}} + {{- $_ := set $tmpProbe "httpHeaders" $probe.httpHeaders -}} + {{- include "ix.v1.common.container.probes.httpGet" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} + {{- else if (eq $probeType "TCP") -}} + {{- include "ix.v1.common.container.probes.tcp" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} + {{- else if (eq $probeType "GRPC") -}} + {{- include "ix.v1.common.container.probes.grpc" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} + {{- else if (eq $probeType "EXEC") -}} + {{- $_ := set $tmpProbe "command" $probe.command -}} + {{- include "ix.v1.common.container.probes.exec" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} + {{- else if (eq $probeType "CUSTOM") -}} + {{- include "ix.v1.common.container.probes.custom" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} + {{- else if (eq $probeType "UDP") -}} + {{- include "ix.v1.common.container.probes.udp" (dict "probe" $tmpProbe "root" $) | trim | nindent 2 }} + {{- end -}} + {{- end -}} {{- end -}} {{- end -}} - -{{- define "ix.v1.common.container.probes.timeouts" -}} - {{- $probeSpec := .probeSpec -}} - {{- $probeName := .probeName -}} - {{/* ints are usually parsed as floats in helm */}} - {{- if not (has (kindOf $probeSpec.initialDelaySeconds) (list "float64" "int")) -}} - {{- fail (printf " cannot be empty in probe (%s)" $probeName) -}} - {{- end -}} - {{- if not (has (kindOf $probeSpec.failureThreshold) (list "float64" "int")) -}} - {{- fail (printf " cannot be empty in probe (%s)" $probeName) -}} - {{- end -}} - {{- if not (has (kindOf $probeSpec.timeoutSeconds) (list "float64" "int")) -}} - {{- fail (printf " cannot be empty in probe (%s)" $probeName) -}} - {{- end -}} - {{- if not (has (kindOf $probeSpec.periodSeconds) (list "float64" "int")) -}} - {{- fail (printf " cannot be empty in probe (%s)" $probeName) -}} - {{- end }} -initialDelaySeconds: {{ $probeSpec.initialDelaySeconds }} -failureThreshold: {{ $probeSpec.failureThreshold }} -timeoutSeconds: {{ $probeSpec.timeoutSeconds }} -periodSeconds: {{ $probeSpec.periodSeconds }} -{{- end -}} diff --git a/library/common/1.0.0/templates/lib/container/probeUtils/_custom.tpl b/library/common/1.0.0/templates/lib/container/probeUtils/_custom.tpl index 701e6c2eb9..a80e2d6583 100644 --- a/library/common/1.0.0/templates/lib/container/probeUtils/_custom.tpl +++ b/library/common/1.0.0/templates/lib/container/probeUtils/_custom.tpl @@ -1,3 +1,4 @@ +{{/* Returns a custom defined for the probe */}} {{- define "ix.v1.common.container.probes.custom" -}} {{- $probe := .probe -}} {{- $root := .root -}} diff --git a/library/common/1.0.0/templates/lib/container/probeUtils/_exec.tpl b/library/common/1.0.0/templates/lib/container/probeUtils/_exec.tpl index f050efb40f..51d34e425f 100644 --- a/library/common/1.0.0/templates/lib/container/probeUtils/_exec.tpl +++ b/library/common/1.0.0/templates/lib/container/probeUtils/_exec.tpl @@ -1,3 +1,4 @@ +{{/* Returns exec for the probe */}} {{- define "ix.v1.common.container.probes.exec" -}} {{- $probe := .probe -}} {{- $root := .root -}} diff --git a/library/common/1.0.0/templates/lib/container/probeUtils/_grpc.tpl b/library/common/1.0.0/templates/lib/container/probeUtils/_grpc.tpl index 709706913f..7667f346b8 100644 --- a/library/common/1.0.0/templates/lib/container/probeUtils/_grpc.tpl +++ b/library/common/1.0.0/templates/lib/container/probeUtils/_grpc.tpl @@ -1,3 +1,4 @@ +{{/* Returns grpc for the probe */}} {{- define "ix.v1.common.container.probes.grpc" -}} {{- $probe := .probe -}} {{- $root := .root -}} diff --git a/library/common/1.0.0/templates/lib/container/probeUtils/_httpGet.tpl b/library/common/1.0.0/templates/lib/container/probeUtils/_httpGet.tpl index e769454ed4..730335a0b3 100644 --- a/library/common/1.0.0/templates/lib/container/probeUtils/_httpGet.tpl +++ b/library/common/1.0.0/templates/lib/container/probeUtils/_httpGet.tpl @@ -1,3 +1,4 @@ +{{/* Returns http for the probe */}} {{- define "ix.v1.common.container.probes.httpGet" -}} {{- $probe := .probe -}} {{- $root := .root -}} diff --git a/library/common/1.0.0/templates/lib/container/probeUtils/_tcp.tpl b/library/common/1.0.0/templates/lib/container/probeUtils/_tcp.tpl index c08cfa86a3..a1ebeecc53 100644 --- a/library/common/1.0.0/templates/lib/container/probeUtils/_tcp.tpl +++ b/library/common/1.0.0/templates/lib/container/probeUtils/_tcp.tpl @@ -1,3 +1,4 @@ +{{/* Returns tcp for the probe */}} {{- define "ix.v1.common.container.probes.tcp" -}} {{- $probe := .probe -}} {{- $root := .root -}} diff --git a/library/common/1.0.0/templates/lib/container/probeUtils/_timeouts.tpl b/library/common/1.0.0/templates/lib/container/probeUtils/_timeouts.tpl new file mode 100644 index 0000000000..e9c0de0e25 --- /dev/null +++ b/library/common/1.0.0/templates/lib/container/probeUtils/_timeouts.tpl @@ -0,0 +1,22 @@ +{{/* Returns the timeouts for the probe */}} +{{- define "ix.v1.common.container.probes.timeouts" -}} + {{- $probeSpec := .probeSpec -}} + {{- $probeName := .probeName -}} + {{/* ints are usually parsed as floats in helm */}} + {{- if not (has (kindOf $probeSpec.initialDelaySeconds) (list "float64" "int")) -}} + {{- fail (printf " cannot be empty in probe (%s)" $probeName) -}} + {{- end -}} + {{- if not (has (kindOf $probeSpec.failureThreshold) (list "float64" "int")) -}} + {{- fail (printf " cannot be empty in probe (%s)" $probeName) -}} + {{- end -}} + {{- if not (has (kindOf $probeSpec.timeoutSeconds) (list "float64" "int")) -}} + {{- fail (printf " cannot be empty in probe (%s)" $probeName) -}} + {{- end -}} + {{- if not (has (kindOf $probeSpec.periodSeconds) (list "float64" "int")) -}} + {{- fail (printf " cannot be empty in probe (%s)" $probeName) -}} + {{- end }} +initialDelaySeconds: {{ $probeSpec.initialDelaySeconds }} +failureThreshold: {{ $probeSpec.failureThreshold }} +timeoutSeconds: {{ $probeSpec.timeoutSeconds }} +periodSeconds: {{ $probeSpec.periodSeconds }} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/container/probeUtils/_udp.tpl b/library/common/1.0.0/templates/lib/container/probeUtils/_udp.tpl index c6e572ce07..ab053fa6d7 100644 --- a/library/common/1.0.0/templates/lib/container/probeUtils/_udp.tpl +++ b/library/common/1.0.0/templates/lib/container/probeUtils/_udp.tpl @@ -1,3 +1,4 @@ +{{/* Returns udp for the probe */}} {{- define "ix.v1.common.container.probes.udp" -}} {{- fail "UDP Probes are not supported. Please use a different probe type or disable probes." -}} {{- end -}}