cleanup probes

This commit is contained in:
Stavros kois
2022-12-02 13:26:11 +02:00
parent 28d2eddac7
commit e1fd7d864d
8 changed files with 67 additions and 59 deletions

View File

@@ -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 "<initialDelaySeconds> cannot be empty in probe (%s)" $probeName) -}}
{{- end -}}
{{- if not (has (kindOf $probeSpec.failureThreshold) (list "float64" "int")) -}}
{{- fail (printf "<failureThreshold> cannot be empty in probe (%s)" $probeName) -}}
{{- end -}}
{{- if not (has (kindOf $probeSpec.timeoutSeconds) (list "float64" "int")) -}}
{{- fail (printf "<timeoutSeconds> cannot be empty in probe (%s)" $probeName) -}}
{{- end -}}
{{- if not (has (kindOf $probeSpec.periodSeconds) (list "float64" "int")) -}}
{{- fail (printf "<periodSeconds> cannot be empty in probe (%s)" $probeName) -}}
{{- end }}
initialDelaySeconds: {{ $probeSpec.initialDelaySeconds }}
failureThreshold: {{ $probeSpec.failureThreshold }}
timeoutSeconds: {{ $probeSpec.timeoutSeconds }}
periodSeconds: {{ $probeSpec.periodSeconds }}
{{- end -}}

View File

@@ -1,3 +1,4 @@
{{/* Returns a custom defined for the probe */}}
{{- define "ix.v1.common.container.probes.custom" -}}
{{- $probe := .probe -}}
{{- $root := .root -}}

View File

@@ -1,3 +1,4 @@
{{/* Returns exec for the probe */}}
{{- define "ix.v1.common.container.probes.exec" -}}
{{- $probe := .probe -}}
{{- $root := .root -}}

View File

@@ -1,3 +1,4 @@
{{/* Returns grpc for the probe */}}
{{- define "ix.v1.common.container.probes.grpc" -}}
{{- $probe := .probe -}}
{{- $root := .root -}}

View File

@@ -1,3 +1,4 @@
{{/* Returns http for the probe */}}
{{- define "ix.v1.common.container.probes.httpGet" -}}
{{- $probe := .probe -}}
{{- $root := .root -}}

View File

@@ -1,3 +1,4 @@
{{/* Returns tcp for the probe */}}
{{- define "ix.v1.common.container.probes.tcp" -}}
{{- $probe := .probe -}}
{{- $root := .root -}}

View File

@@ -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 "<initialDelaySeconds> cannot be empty in probe (%s)" $probeName) -}}
{{- end -}}
{{- if not (has (kindOf $probeSpec.failureThreshold) (list "float64" "int")) -}}
{{- fail (printf "<failureThreshold> cannot be empty in probe (%s)" $probeName) -}}
{{- end -}}
{{- if not (has (kindOf $probeSpec.timeoutSeconds) (list "float64" "int")) -}}
{{- fail (printf "<timeoutSeconds> cannot be empty in probe (%s)" $probeName) -}}
{{- end -}}
{{- if not (has (kindOf $probeSpec.periodSeconds) (list "float64" "int")) -}}
{{- fail (printf "<periodSeconds> cannot be empty in probe (%s)" $probeName) -}}
{{- end }}
initialDelaySeconds: {{ $probeSpec.initialDelaySeconds }}
failureThreshold: {{ $probeSpec.failureThreshold }}
timeoutSeconds: {{ $probeSpec.timeoutSeconds }}
periodSeconds: {{ $probeSpec.periodSeconds }}
{{- end -}}

View File

@@ -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 -}}