Skip to content

Commit

Permalink
fix: update alb business tag rule
Browse files Browse the repository at this point in the history
  • Loading branch information
chiayu-su committed Aug 22, 2024
1 parent ef659fb commit 734d196
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion simple/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 10 additions & 1 deletion simple/templates/_ingress_multiple.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion simple/templates/_ingress_single.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 44 additions & 0 deletions simple/tests/ingress_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

0 comments on commit 734d196

Please sign in to comment.