diff --git a/library/common/1.0.0/templates/class/_service.tpl b/library/common/1.0.0/templates/class/_service.tpl index 3e8bdc1aa1..c943387c2e 100644 --- a/library/common/1.0.0/templates/class/_service.tpl +++ b/library/common/1.0.0/templates/class/_service.tpl @@ -70,31 +70,10 @@ spec: externalTrafficPolicy: {{ . }} {{- end -}} {{- end -}} -{{- if $svcValues.sessionAffinity -}} - {{- include "ix.v1.common.class.serivce.sessionAffinity" (dict "svc" $svcValues "root" $root) | nindent 2 -}} -{{- end -}} -{{- if $svcValues.externalIPs -}} - {{- include "ix.v1.common.class.serivce.externalIPs" (dict "externalIPs" $svcValues.externalIPs "root" $root) | nindent 2 -}} -{{- end -}} +{{- include "ix.v1.common.class.serivce.sessionAffinity" (dict "svc" $svcValues "root" $root) | trim | nindent 2 -}} +{{- include "ix.v1.common.class.serivce.externalIPs" (dict "svc" $svcValues "root" $root) | trim | nindent 2 -}} {{- include "ix.v1.common.class.serivce.publishNotReadyAddresses" (dict "publishNotReadyAddresses" $svcValues.publishNotReadyAddresses) | trim | nindent 2 -}} -{{- if has $svcType (list "ClusterIP" "NodePort" "LoadBalancer") -}} - {{- with $svcValues.ipFamilyPolicy }} - {{- if not (has . (list "SingleStack" "PreferDualStack" "RequireDualStack")) -}} - {{ fail (printf "Invalid option (%s) for . Valid options are SingleStack, PreferDualStack, RequireDualStack" .) -}} - {{- end }} - ipFamilyPolicy: {{ . }} - {{- end -}} - {{- with $svcValues.ipFamilies }} - ipFamilies: - {{- range . }} - {{- $ipFam := tpl . $root -}} - {{- if not (has $ipFam (list "IPv4" "IPv6")) -}} - {{- fail (printf "Invalid option (%s) for . Valid options are IPv4 and IPv6" $ipFam) -}} - {{- end }} - - {{ $ipFam }} - {{- end }} - {{- end -}} -{{- end }} +{{- include "ix.v1.common.class.serivce.ipFamily" (dict "svcType" $svcType "svc" $svcValues "root" $root) | trim | nindent 2 }} ports: {{- range $name, $port := $svcValues.ports }} {{- if $port.enabled }} @@ -127,6 +106,6 @@ spec: {{- end -}} {{- if eq $svcType "ExternalIP" -}} {{- $_ := set $tmpSVC "values" $svcValues -}} - {{- include "ix.v1.common.class.serivce.endpoints" (dict "svc" $tmpSVC "root" $root) }} + {{- include "ix.v1.common.class.serivce.endpoints" (dict "svc" $svcValues "svcName" $svcName "root" $root) }} {{- end -}} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/service/_endpoints.tpl b/library/common/1.0.0/templates/lib/service/_endpoints.tpl index 8d67daff30..8d3668e80f 100644 --- a/library/common/1.0.0/templates/lib/service/_endpoints.tpl +++ b/library/common/1.0.0/templates/lib/service/_endpoints.tpl @@ -1,7 +1,7 @@ {{- define "ix.v1.common.class.serivce.endpoints" -}} {{- $root := .root -}} - {{- $svcName := .svc.name -}} - {{- $svcValues := .svc.values }} + {{- $svcName := .svcName -}} + {{- $svcValues := .svc }} --- apiVersion: {{ include "ix.v1.common.capabilities.endpoints.apiVersion" $root }} diff --git a/library/common/1.0.0/templates/lib/service/_externalIPs.tpl b/library/common/1.0.0/templates/lib/service/_externalIPs.tpl index c63a603a56..d8fd82d9d4 100644 --- a/library/common/1.0.0/templates/lib/service/_externalIPs.tpl +++ b/library/common/1.0.0/templates/lib/service/_externalIPs.tpl @@ -1,8 +1,10 @@ {{- define "ix.v1.common.class.serivce.externalIPs" -}} - {{- $externalIPs := .externalIPs -}} + {{- $svcValues := .svc -}} {{- $root := .root -}} + {{- with $svcValues.externalIPs -}} externalIPs: - {{- range $externalIPs }} + {{- range . }} - {{ tpl . $root }} - {{- end }} + {{- end }} + {{- end -}} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/service/_ipFamily.tpl b/library/common/1.0.0/templates/lib/service/_ipFamily.tpl new file mode 100644 index 0000000000..2edf551854 --- /dev/null +++ b/library/common/1.0.0/templates/lib/service/_ipFamily.tpl @@ -0,0 +1,24 @@ +{{- define "ix.v1.common.class.serivce.ipFamily" -}} +{{- $svcType := .svcType -}} +{{- $svcValues := .svc -}} +{{- $root := .root -}} + + {{- if has $svcType (list "ClusterIP" "NodePort" "LoadBalancer") -}} + {{- with $svcValues.ipFamilyPolicy -}} + {{- if not (has . (list "SingleStack" "PreferDualStack" "RequireDualStack")) -}} + {{- fail (printf "Invalid option (%s) for . Valid options are SingleStack, PreferDualStack, RequireDualStack" .) -}} + {{- end }} +ipFamilyPolicy: {{ . }} + {{- end -}} + {{- with $svcValues.ipFamilies }} +ipFamilies: + {{- range . }} + {{- $ipFam := tpl . $root -}} + {{- if not (has $ipFam (list "IPv4" "IPv6")) -}} + {{- fail (printf "Invalid option (%s) for . Valid options are IPv4 and IPv6" $ipFam) -}} + {{- end }} + - {{ $ipFam }} + {{- end }} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/service/_sessionAffinity.tpl b/library/common/1.0.0/templates/lib/service/_sessionAffinity.tpl index bb78bc8456..38bb588ffb 100644 --- a/library/common/1.0.0/templates/lib/service/_sessionAffinity.tpl +++ b/library/common/1.0.0/templates/lib/service/_sessionAffinity.tpl @@ -1,13 +1,14 @@ {{- define "ix.v1.common.class.serivce.sessionAffinity" -}} - {{- $svc := .svc -}} + {{- $svcValues := .svc -}} {{- $root := .root -}} - - {{- if not (has $svc.sessionAffinity (list "ClientIP" "None")) -}} - {{- fail (printf "Invalid option (%s) for . Valid options are ClientIP and None" $svc.sessionAffinity) -}} - {{- end }} -sessionAffinity: {{ $svc.sessionAffinity }} - {{- if eq $svc.sessionAffinity "ClientIP" -}} - {{- with $svc.sessionAffinityConfig -}} + {{- with $svcValues.sessionAffinity -}} + {{- if not (has . (list "ClientIP" "None")) -}} + {{- fail (printf "Invalid option (%s) for . Valid options are ClientIP and None" .) -}} + {{- end }} +sessionAffinity: {{ . }} + {{- end -}} + {{- if eq $svcValues.sessionAffinity "ClientIP" -}} + {{- with $svcValues.sessionAffinityConfig -}} {{- with .clientIP -}} {{- if hasKey . "timeoutSeconds" -}} {{- $timeout := tpl (toString .timeoutSeconds) $root -}}