Skip to content

Commit

Permalink
chore: add default ingress cost tag
Browse files Browse the repository at this point in the history
  • Loading branch information
nealyip committed Aug 9, 2024
1 parent 1c9c17f commit 7d829d6
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/test-cronjob-chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
push:
paths:
- cronjob/**
- simple/**
- .github/workflows/**
pull_request:
paths:
- cronjob/**
- simple/**
- .github/workflows/**

jobs:
Expand Down Expand Up @@ -37,3 +39,7 @@ jobs:
- name: Run cronjob chart tests
run: |
helm unittest cronjob
- name: Run simple chart tests
run: |
helm unittest simple
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.20.1
version: 0.21.0
appVersion: 0.0.1
tillerVersion: ">=2.14.3"
5 changes: 5 additions & 0 deletions simple/templates/_ingress_multiple.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ metadata:
{{- if and (not (index $ref.annotations "alb.ingress.kubernetes.io/ssl-policy")) (index $ref.annotations "alb.ingress.kubernetes.io/load-balancer-name") }}
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 }}
{{- end }}
{{- end }}
spec:
{{- if $ref.tls }}
tls:
Expand Down
5 changes: 5 additions & 0 deletions simple/templates/_ingress_single.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ metadata:
{{- if and (not (index .Values.ingress.annotations "alb.ingress.kubernetes.io/ssl-policy")) (index .Values.ingress.annotations "alb.ingress.kubernetes.io/load-balancer-name") }}
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 }}
{{- end }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
Expand Down
47 changes: 47 additions & 0 deletions simple/tests/ingress_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
suite: Ingress Test
templates:
- ingress.yaml
tests:
- it: should render alb with a cost tag annotation
values:
- ./values/simple/ingress_alb.yaml
asserts:
- isSubset:
path: metadata.annotations
content:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/tags: businessid=00123

- it: should render alb multiple ingress with a cost tag annotation with
values:
- ./values/simple/ingress_alb_multiple.yaml
asserts:
- isSubset:
path: metadata.annotations
content:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/tags: businessid=00123

- it: should keep original alb.ingress.kubernetes.io/tags from values
values:
- ./values/simple/ingress_alb.yaml
set:
ingress:
annotations:
alb.ingress.kubernetes.io/tags: businessid=00456
asserts:
- isSubset:
path: metadata.annotations
content:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/tags: businessid=00456

- it: should not render alb with a cost tag annotation
values:
- ./values/simple/ingress_nginx.yaml
asserts:
- isNotSubset:
path: metadata.annotations
content:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/tags: businessid=00123
20 changes: 20 additions & 0 deletions simple/tests/values/simple/ingress_alb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
businessid: "00123"
deployment:
containers:
app:
image:
repository: nginx
tag: latest
ingress:
annotations:
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]'
alb.ingress.kubernetes.io/scheme: internet-facing
kubernetes.io/ingress.class: alb
rules:
- http:
paths:
- backend:
serviceName: app
servicePort: use-annotation
path: /*
name: app
22 changes: 22 additions & 0 deletions simple/tests/values/simple/ingress_alb_multiple.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
businessid: "00123"
deployment:
containers:
app:
image:
repository: nginx
tag: latest
EnableMutilpleIngress: true
ingress:
nginx:
annotations:
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]'
alb.ingress.kubernetes.io/scheme: internet-facing
kubernetes.io/ingress.class: alb
rules:
- http:
paths:
- backend:
serviceName: app
servicePort: use-annotation
path: /*
name: app
18 changes: 18 additions & 0 deletions simple/tests/values/simple/ingress_nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
businessid: "00123"
deployment:
containers:
app:
image:
repository: nginx
tag: latest
ingress:
annotations:
nginx.ingress.kubernetes.io/backend-protocol: HTTP
rules:
- http:
paths:
- backend:
serviceName: app
servicePort: use-annotation
path: /*
name: app

0 comments on commit 7d829d6

Please sign in to comment.