diff --git a/simple/Chart.yaml b/simple/Chart.yaml index 30f8a0e..eb3db48 100644 --- a/simple/Chart.yaml +++ b/simple/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 description: Helm chart with simple deployment/service template name: simple -version: 0.21.1 +version: 0.21.2 appVersion: 0.0.1 tillerVersion: ">=2.14.3" diff --git a/simple/templates/_ingress_multiple.tpl b/simple/templates/_ingress_multiple.tpl index 934e385..82732f3 100644 --- a/simple/templates/_ingress_multiple.tpl +++ b/simple/templates/_ingress_multiple.tpl @@ -13,13 +13,22 @@ metadata: {{ $key }}: {{ $value }} {{- end }} annotations: -{{ toYaml $ref.annotations | indent 4 }} + {{- $omittedAnnotations := omit $ref.annotations "alb.ingress.kubernetes.io/tags" }} +{{ toYaml $omittedAnnotations | indent 4 }} {{- if and (not (index $ref.annotations "alb.ingress.kubernetes.io/ssl-policy")) (index $ref.annotations "alb.ingress.kubernetes.io/load-balancer-name") (index $ref.annotations "alb.ingress.kubernetes.io/certificate-arn") }} alb.ingress.kubernetes.io/ssl-policy: "ELBSecurityPolicy-TLS13-1-2-2021-06" {{- end }} {{- if eq (index $ref.annotations "kubernetes.io/ingress.class") "alb" }} {{- if not (index $ref.annotations "alb.ingress.kubernetes.io/tags") }} alb.ingress.kubernetes.io/tags: {{ printf "businessid=%s" $businessid | quote }} + {{- else }} + {{- $tags := index $ref.annotations "alb.ingress.kubernetes.io/tags" }} + {{- if not (regexMatch "businessid=[^,]+" $tags) }} + {{- $newTags := printf "%s,businessid=%s" $tags $businessid | quote }} + alb.ingress.kubernetes.io/tags: {{ $newTags }} + {{- else }} + alb.ingress.kubernetes.io/tags: {{ $tags }} + {{- end }} {{- end }} {{- end }} spec: diff --git a/simple/templates/_ingress_single.tpl b/simple/templates/_ingress_single.tpl index 71a2c4d..9e4a2c3 100644 --- a/simple/templates/_ingress_single.tpl +++ b/simple/templates/_ingress_single.tpl @@ -9,13 +9,22 @@ metadata: {{ $key }}: {{ $value }} {{- end }} annotations: -{{ toYaml .Values.ingress.annotations | indent 4 }} + {{- $omittedAnnotations := omit .Values.ingress.annotations "alb.ingress.kubernetes.io/tags" }} +{{ toYaml $omittedAnnotations | indent 4 }} {{- if and (not (index .Values.ingress.annotations "alb.ingress.kubernetes.io/ssl-policy")) (index .Values.ingress.annotations "alb.ingress.kubernetes.io/load-balancer-name") (index .Values.ingress.annotations "alb.ingress.kubernetes.io/certificate-arn") }} alb.ingress.kubernetes.io/ssl-policy: "ELBSecurityPolicy-TLS13-1-2-2021-06" {{- end }} {{- if eq (index .Values.ingress.annotations "kubernetes.io/ingress.class") "alb" }} {{- if not (index .Values.ingress.annotations "alb.ingress.kubernetes.io/tags") }} alb.ingress.kubernetes.io/tags: {{ printf "businessid=%s" .Values.businessid | quote }} + {{- else }} + {{- $tags := index .Values.ingress.annotations "alb.ingress.kubernetes.io/tags" }} + {{- if not (regexMatch "businessid=[^,]+" $tags) }} + {{- $newTags := printf "%s,businessid=%s" $tags .Values.businessid | quote }} + alb.ingress.kubernetes.io/tags: {{ $newTags }} + {{- else }} + alb.ingress.kubernetes.io/tags: {{ $tags }} + {{- end }} {{- end }} {{- end }} spec: diff --git a/simple/tests/ingress_test.yaml b/simple/tests/ingress_test.yaml index 989cdc7..967cf3a 100644 --- a/simple/tests/ingress_test.yaml +++ b/simple/tests/ingress_test.yaml @@ -35,6 +35,21 @@ tests: content: kubernetes.io/ingress.class: alb alb.ingress.kubernetes.io/tags: businessid=00456 + + - it: should keep original alb.ingress.kubernetes.io/tags from values for multiple ingresses + values: + - ./values/simple/ingress_alb_multiple.yaml + set: + ingress: + nginx: + annotations: + alb.ingress.kubernetes.io/tags: businessid=00456 + asserts: + - isSubset: + path: metadata.annotations + content: + alb.ingress.kubernetes.io/tags: businessid=00456 + kubernetes.io/ingress.class: alb - it: should not render alb with a cost tag annotation values: @@ -45,3 +60,32 @@ tests: content: kubernetes.io/ingress.class: alb alb.ingress.kubernetes.io/tags: businessid=00123 + + - it: should append businessid tag annotation when other tags exist + values: + - ./values/simple/ingress_alb.yaml + set: + ingress: + annotations: + alb.ingress.kubernetes.io/tags: Environment=production + asserts: + - isSubset: + path: metadata.annotations + content: + kubernetes.io/ingress.class: alb + alb.ingress.kubernetes.io/tags: Environment=production,businessid=00123 + + - it: should append businessid tag annotation when other tags exist for multiple ingresses + values: + - ./values/simple/ingress_alb_multiple.yaml + set: + ingress: + nginx: + annotations: + alb.ingress.kubernetes.io/tags: Environment=production + asserts: + - isSubset: + path: metadata.annotations + content: + alb.ingress.kubernetes.io/tags: Environment=production,businessid=00123 + kubernetes.io/ingress.class: alb \ No newline at end of file