From 792bad48b059bbce655a681b851d035c5c857445 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Fri, 25 Nov 2022 14:48:42 +0200 Subject: [PATCH] simplify protocol validation --- .../1.0.0/templates/lib/container/_ports.tpl | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/library/common/1.0.0/templates/lib/container/_ports.tpl b/library/common/1.0.0/templates/lib/container/_ports.tpl index 00338bdddb..bb84a7c813 100644 --- a/library/common/1.0.0/templates/lib/container/_ports.tpl +++ b/library/common/1.0.0/templates/lib/container/_ports.tpl @@ -16,29 +16,29 @@ can be dynamically configured via an env var. {{- end -}} {{/* Render the list of ports */}} -{{- if $ports }} -{{- range $_ := $ports }} - {{- if .enabled }} +{{- if $ports -}} + {{- range $_ := $ports }} + {{- if .enabled }} - name: {{ tpl .name $ }} - {{- if not .port }} - {{- fail (printf "Port is required on enabled services. Service (%s)" .name) }} - {{- end }} - {{- if and .targetPort (kindIs "string" .targetPort) }} - {{- fail (printf "This common library does not support named ports for targetPort. port name (%s), targetPort (%s)" .name .targetPort) }} - {{- end }} + {{- if not .port -}} + {{- fail (printf "Port is required on enabled services. Service (%s)" .name) -}} + {{- end -}} + {{- if and .targetPort (kindIs "string" .targetPort) -}} + {{- fail (printf "This common library does not support named ports for targetPort. port name (%s), targetPort (%s)" .name .targetPort) -}} + {{- end }} containerPort: {{ default .port .targetPort }} - {{- with .protocol }} - {{- if has . (list "HTTP" "HTTPS" "TCP") }} - protocol: TCP - {{- else if (eq . "UDP") }} - protocol: UDP - {{- else }} - {{- fail (printf "Not valid (%s)" .) }} - {{- end }} - {{- else }} {{/* If no protocol is given, default to TCP */}} - protocol: TCP - {{- end }} - {{- end }} -{{- end }} + {{- $protocol := "TCP" -}} + {{- with .protocol -}} + {{- if has . (list "HTTP" "HTTPS" "TCP") -}} + {{- $protocol = "TCP" -}} + {{- else if (eq . "UDP") -}} + {{- $protocol = "UDP" -}} + {{- else -}} + {{- fail (printf "Not valid (%s)" .) -}} + {{- end }} + protocol: {{ $protocol }} + {{- end -}} + {{- end -}} + {{- end -}} {{- end -}} {{- end -}}