Skip to content

Commit 299aa26

Browse files
feat(cf-common): add ingress tpl (#8)
* feat(cf-common): add ingress tpl
1 parent 23c2590 commit 299aa26

File tree

12 files changed

+488
-4
lines changed

12 files changed

+488
-4
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v4.2.0
44
hooks:
5-
- id: check-yaml
65
- id: end-of-file-fixer
76
exclude: &exclude_pattern 'README.md'
87
- id: trailing-whitespace

charts/cf-common-test/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Codefresh library chart - test chart - not for deployment!
3030
| extraResources | list | `[]` | |
3131
| global | object | `{}` | |
3232
| hpa | object | `{}` | |
33+
| ingress | object | `{}` | |
3334
| initContainers | list | `[]` | |
3435
| nodeSelector | object | `{}` | |
3536
| pdb | object | `{}` | |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{- include "cf-common.ingress" . -}}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: ingress error handler
3+
templates:
4+
- templates/ingress.yaml
5+
tests:
6+
- it: Test no service name specified
7+
set:
8+
ingress:
9+
main:
10+
enabled: true
11+
hosts:
12+
- host: host.domain.local
13+
paths:
14+
- path: /path
15+
service:
16+
port: 80
17+
asserts:
18+
- failedTemplate:
19+
errorMessage: "service.name is required for ingress main!"
20+
21+
- it: Test no service port specified
22+
set:
23+
ingress:
24+
main:
25+
enabled: true
26+
hosts:
27+
- host: host.domain.local
28+
paths:
29+
- path: /path
30+
service:
31+
name: svc-test
32+
asserts:
33+
- failedTemplate:
34+
errorMessage: "service.port is required for ingress main!"
35+
36+
- it: Test tls as invalid type
37+
values:
38+
- values.yaml
39+
set:
40+
ingress:
41+
main:
42+
tls:
43+
secretName: secret-example-tls
44+
hosts:
45+
- host.domain.local
46+
asserts:
47+
- failedTemplate:
48+
errorMessage: "ingress.main.tls must be a list!"
49+
50+
- it: Test hosts as invalid type
51+
values:
52+
- values.yaml
53+
set:
54+
ingress:
55+
main:
56+
hosts:
57+
host: host.domain.local
58+
paths:
59+
- path: /path
60+
asserts:
61+
- failedTemplate:
62+
errorMessage: "ingress.main.hosts must be a list!"
63+
64+
- it: Test paths as invalid type
65+
values:
66+
- values.yaml
67+
set:
68+
ingress:
69+
main:
70+
enabled: true
71+
hosts:
72+
- host: host.domain.local
73+
paths:
74+
path: /path
75+
pathType: ImplementationSpecific
76+
asserts:
77+
- failedTemplate:
78+
errorMessage: "ingress.main.hosts[].paths must be a list!"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: ingress metadata
3+
templates:
4+
- templates/ingress.yaml
5+
tests:
6+
- it: Test Ingress default metadata
7+
values:
8+
- values.yaml
9+
asserts:
10+
- hasDocuments:
11+
count: 1
12+
- isKind:
13+
of: Ingress
14+
- isNull:
15+
path: metadata.annotations
16+
- equal:
17+
path: metadata.labels
18+
value:
19+
app.kubernetes.io/instance: RELEASE-NAME
20+
app.kubernetes.io/managed-by: Helm
21+
app.kubernetes.io/name: cf-common-test
22+
helm.sh/chart: cf-common-test-0.0.0
23+
- equal:
24+
path: metadata.name
25+
value: RELEASE-NAME-cf-common-test-main
26+
27+
- it: Test Ingress custom metadata
28+
values:
29+
- values.yaml
30+
set:
31+
ingress:
32+
main:
33+
labels:
34+
alice: bob
35+
annotations:
36+
foo: bar
37+
asserts:
38+
- hasDocuments:
39+
count: 1
40+
- isKind:
41+
of: Ingress
42+
- equal:
43+
path: metadata.annotations
44+
value:
45+
foo: bar
46+
- equal:
47+
path: metadata.labels
48+
value:
49+
app.kubernetes.io/instance: RELEASE-NAME
50+
app.kubernetes.io/managed-by: Helm
51+
app.kubernetes.io/name: cf-common-test
52+
helm.sh/chart: cf-common-test-0.0.0
53+
alice: bob
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: ingress spec
3+
templates:
4+
- templates/ingress.yaml
5+
tests:
6+
- it: Test host and path
7+
values:
8+
- values.yaml
9+
asserts:
10+
- equal:
11+
path: spec.rules[0].host
12+
value: host.domain.local
13+
- equal:
14+
path: spec.rules[0].http.paths[0].path
15+
value: /path
16+
17+
- it: Test service and port
18+
values:
19+
- values.yaml
20+
asserts:
21+
- equal:
22+
path: spec.rules[0].http.paths[0].backend.service.name
23+
value: svc-test
24+
- equal:
25+
path: spec.rules[0].http.paths[0].backend.service.port.number
26+
value: 8080
27+
28+
- it: Test ingress with template
29+
values:
30+
- values.yaml
31+
set:
32+
global:
33+
appUrl: mydomain.example.io
34+
apiPath: /api
35+
apiAddr: svc-test-tpl
36+
apiPort: 8081
37+
ingress:
38+
main:
39+
enabled: false
40+
tpl:
41+
enabled: true
42+
hosts:
43+
- host: "{{ .Values.global.appUrl }}"
44+
paths:
45+
- path: "{{ .Values.global.apiPath }}"
46+
service:
47+
name: "{{ .Values.global.apiAddr }}"
48+
port: "{{ .Values.global.apiPort }}"
49+
asserts:
50+
- hasDocuments:
51+
count: 1
52+
- isKind:
53+
of: Ingress
54+
- equal:
55+
path: spec.rules[0].host
56+
value: mydomain.example.io
57+
- equal:
58+
path: spec.rules[0].http.paths[0].path
59+
value: /api
60+
- equal:
61+
path: spec.rules[0].http.paths[0].backend.service.name
62+
value: svc-test-tpl
63+
- equal:
64+
path: spec.rules[0].http.paths[0].backend.service.port.number
65+
value: 8081
66+
67+
- it: Test with no ingressClassName
68+
values:
69+
- values.yaml
70+
asserts:
71+
- isNull:
72+
path: spec.ingressClassName
73+
74+
- it: Test with ingressClassName
75+
values:
76+
- values.yaml
77+
set:
78+
ingress:
79+
main:
80+
ingressClassName: nginx
81+
asserts:
82+
- equal:
83+
path: spec.ingressClassName
84+
value: nginx
85+
86+
- it: Test with no tls
87+
values:
88+
- values.yaml
89+
asserts:
90+
- isNull:
91+
path: spec.tls
92+
93+
- it: Test with tls enabled
94+
values:
95+
- values.yaml
96+
set:
97+
ingress:
98+
main:
99+
tls:
100+
- secretName: secret-example-tls
101+
hosts:
102+
- host.domain.local
103+
asserts:
104+
- contains:
105+
path: spec.tls
106+
content:
107+
secretName: secret-example-tls
108+
hosts:
109+
- host.domain.local
110+
111+
- it: Test with tls enabled with template
112+
values:
113+
- values.yaml
114+
set:
115+
global:
116+
appUrl: mydomain.example.io
117+
secretName: secret-example-tls-tpl
118+
ingress:
119+
main:
120+
tls:
121+
- secretName: "{{ .Values.global.secretName }}"
122+
hosts:
123+
- "{{ .Values.global.appUrl }}"
124+
asserts:
125+
- contains:
126+
path: spec.tls
127+
content:
128+
secretName: secret-example-tls-tpl
129+
hosts:
130+
- mydomain.example.io
131+
132+
- it: Test with multiple ingress
133+
values:
134+
- values.yaml
135+
set:
136+
ingress:
137+
second:
138+
enabled: true
139+
hosts:
140+
- host: host.domain.local
141+
paths:
142+
- path: /another/path
143+
pathType: ImplementationSpecific
144+
service:
145+
name: svc-test
146+
port: 8081
147+
asserts:
148+
- hasDocuments:
149+
count: 2
150+
- isKind:
151+
of: Ingress
152+
documentIndex: 0
153+
- isKind:
154+
of: Ingress
155+
documentIndex: 1
156+
157+
- it: Test multiple paths
158+
values:
159+
- values.yaml
160+
set:
161+
ingress:
162+
main:
163+
hosts:
164+
- host: host.domain.local
165+
paths:
166+
- path: /path/one
167+
service:
168+
name: svc-test-one
169+
port: 8080
170+
- path: /path/two
171+
service:
172+
name: svc-test-two
173+
port: 8081
174+
asserts:
175+
- lengthEqual:
176+
path: spec.rules[0].http.paths
177+
count: 2
178+
179+
- it: Test multiple hosts
180+
values:
181+
- values.yaml
182+
set:
183+
ingress:
184+
main:
185+
hosts:
186+
- host: host-one.domain.local
187+
paths:
188+
- path: /path/one
189+
service:
190+
name: svc-test-one
191+
port: 8080
192+
- host: host-two.domain.local
193+
paths:
194+
- path: /path/two
195+
service:
196+
name: svc-test-two
197+
port: 8081
198+
asserts:
199+
- lengthEqual:
200+
path: spec.rules
201+
count: 2
202+
203+
- it: Test with no ingresses
204+
values:
205+
- values.yaml
206+
set:
207+
ingress:
208+
main:
209+
enabled: false
210+
asserts:
211+
- hasDocuments:
212+
count: 0
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# mock ingress values
2+
ingress:
3+
main:
4+
enabled: true
5+
labels: {}
6+
annotations: {}
7+
ingressClassName: ""
8+
hosts:
9+
- host: host.domain.local
10+
paths:
11+
- path: /path
12+
pathType: ImplementationSpecific
13+
service:
14+
name: svc-test
15+
port: 8080
16+
tls: []

charts/cf-common-test/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ secrets: {}
1313

1414
services: {}
1515

16+
ingress: {}
17+
1618
hpa: {}
1719

1820
pdb: {}

charts/cf-common/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: v0.0.0
33
description: Codefresh library chart
44
name: cf-common
5-
version: 0.0.7
5+
version: 0.0.8
66
type: library
77
keywords:
88
- codefresh

0 commit comments

Comments
 (0)