diff --git a/library/common-test/tests/service/service_test.yaml b/library/common-test/tests/service/service_test.yaml index 19df8949..8986e6f4 100644 --- a/library/common-test/tests/service/service_test.yaml +++ b/library/common-test/tests/service/service_test.yaml @@ -230,6 +230,26 @@ tests: some_key: value some_key1: value1 + - it: should pass with addAnnotations set to true and overridden metalLBSharedKey + documentIndex: *serviceDoc + set: + addAnnotations: + traefik: true + metallb: true + service: + main: + type: LoadBalancer + metalLBSharedKey: custom-shared-key + ports: + main: + protocol: HTTPS + asserts: + - equal: + path: metadata.annotations + value: + traefik.ingress.kubernetes.io/service.serversscheme: https + metallb.universe.tf/allow-shared-ip: custom-shared-key + - it: should pass with labels documentIndex: *serviceDoc set: diff --git a/library/common/1.0.0/templates/class/_service.tpl b/library/common/1.0.0/templates/class/_service.tpl index 0339a011..20593cf6 100644 --- a/library/common/1.0.0/templates/class/_service.tpl +++ b/library/common/1.0.0/templates/class/_service.tpl @@ -32,13 +32,17 @@ metadata: {{- with (include "ix.v1.common.util.labels.render" (dict "root" $root "labels" $labels) | trim) }} labels: {{- . | nindent 4 }} - {{- end }} + {{- end -}} {{- $additionalAnnotations := dict -}} - {{- if and $root.Values.addAnnotations.traefik (eq ($primaryPort.protocol | default "") "HTTPS") }} + {{- if and $root.Values.addAnnotations.traefik (eq ($primaryPort.protocol | default "") "HTTPS") -}} {{- $_ := set $additionalAnnotations "traefik.ingress.kubernetes.io/service.serversscheme" "https" -}} {{- end -}} - {{- if and $root.Values.addAnnotations.metallb (eq $svcType "LoadBalancer") }} - {{- $_ := set $additionalAnnotations "metallb.universe.tf/allow-shared-ip" (include "ix.v1.common.names.fullname" $root) }} + {{- if and $root.Values.addAnnotations.metallb (eq $svcType "LoadBalancer") -}} + {{- $sharedLBKey := include "ix.v1.common.names.fullname" $root -}} + {{- with $svcValues.metalLBSharedKey -}} + {{- $sharedLBKey = tpl . $root -}} + {{- end -}} + {{- $_ := set $additionalAnnotations "metallb.universe.tf/allow-shared-ip" $sharedLBKey -}} {{- end -}} {{- $annotations := (mustMerge ($svcValues.annotations | default dict) (include "ix.v1.common.annotations" $root | fromYaml) $additionalAnnotations) -}} {{- with (include "ix.v1.common.util.annotations.render" (dict "root" $root "annotations" $annotations) | trim) }}