Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## In Development
* Temporary workaround for #311 to use previous bitnami index from: https://github.com/bitnami/charts/issues/10539 (#312 #318) (by @0xhaven)
* Refactor label definitions to be more consistent by building labels and label selectors in partial helper templates. (#299) (by @cognifloyd)
* Use the correct `apiVersion` for `Ingress` to add support for Kubernetes `v1.22`. (by @arms11)

## v0.100.0
* Switch st2 to `v3.7` as a new default stable version (#274)
Expand Down
22 changes: 22 additions & 0 deletions templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{{- if .Values.ingress.enabled }}
---
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
apiVersion: networking.k8s.io/v1
{{- else }}
apiVersion: networking.k8s.io/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ .Release.Name }}-st2web-ingress
Expand All @@ -20,9 +24,18 @@ spec:
paths:
{{- range .paths }}
- path: {{ default "/*" .path }}
{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests uncovered a bug here. It was missing $ so I added that.

pathType: Prefix
backend:
service:
name: {{ .serviceName }}
port:
number: {{ .servicePort }}
{{- else }}
backend:
serviceName: {{ .serviceName }}
servicePort: {{ .servicePort }}
{{- end }}
{{- end }}
{{- else }}
{{- if required "Missing context '.Values.st2web.service.hostname'!" .Values.st2web.service.hostname }}
Expand All @@ -31,9 +44,18 @@ spec:
http:
paths:
- path: "/"
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
pathType: Prefix
backend:
service:
name: {{ .Release.Name }}-st2web
port:
number: 80
{{- else }}
backend:
serviceName: {{ .Release.Name }}-st2web
servicePort: 80
{{- end }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
Expand Down
183 changes: 183 additions & 0 deletions tests/unit/ingress_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
---
suite: Ingress
templates:
# primary template files
- ingress.yaml

tests:
- it: Ingress not present if disabled
set:
ingress:
enabled: false
asserts:
- hasDocuments:
count: 0

- it: Ingress is present when enabled without hosts (older k8s)
capabilities: &cap_older
majorVersion: 1
minorVersion: 18
apiVersions:
- networking.k8s.io/v1beta1
set:
ingress:
enabled: true
hosts: []
tls: []
st2web:
service:
hostname: &st2web_hostname hostname.domain.tld
release:
name: st2ha
asserts:
- hasDocuments:
count: 1
- equal:
path: kind
value: Ingress
# no ingress.hosts, so only st2web.hostname
- equal: &st2web_rules_host
path: spec.rules[0].host
value: *st2web_hostname
- contains:
path: spec.rules[0].http.paths
count: 1
content:
path: "/"
backend:
serviceName: st2ha-st2web
servicePort: 80
- isNull:
path: spec.rules[0].http.paths[0].pathType

- it: Ingress is present when enabled without hosts (newer k8s)
capabilities: &cap_newer
majorVersion: 1
minorVersion: 19
apiVersions:
- networking.k8s.io/v1 # introduced in 1.19, stable in 1.22
- networking.k8s.io/v1beta1
set:
ingress:
enabled: true
hosts: []
tls: []
st2web:
service:
hostname: *st2web_hostname
release:
name: st2ha
asserts:
- hasDocuments:
count: 1
- equal:
path: kind
value: Ingress
# no ingress.hosts, so only st2web.hostname
- equal: *st2web_rules_host
- contains:
path: spec.rules[0].http.paths
count: 1
content:
path: "/"
pathType: Prefix
backend:
service:
name: st2ha-st2web
port:
number: 80

- it: Ingress is present when enabled with hosts (older k8s)
capabilities: *cap_older
set:
ingress:
enabled: true
hosts: &hosts
- host: *st2web_hostname
paths:
- serviceName: st2ha-st2web
servicePort: 80
- path: /fancy-sensor
serviceName: fancy-sensor
servicePort: 8080
tls: []
st2web:
service:
hostname: *st2web_hostname
release:
name: st2ha
asserts:
- hasDocuments:
count: 1
- equal:
path: kind
value: Ingress
# no ingress.hosts, so only st2web.hostname
- equal: *st2web_rules_host
- equal: &host_path_is_root_glob
path: spec.rules[0].http.paths[0].path
value: "/*"
- isNull:
path: spec.rules[0].http.paths[0].pathType
- equal:
path: spec.rules[0].http.paths[0].backend
value:
serviceName: st2ha-st2web
servicePort: 80

- equal:
path: spec.rules[0].http.paths[1].path
value: "/fancy-sensor"
- isNull:
path: spec.rules[0].http.paths[1].pathType
- equal:
path: spec.rules[0].http.paths[1].backend
value:
serviceName: fancy-sensor
servicePort: 8080

- it: Ingress is present when enabled with hosts (newer k8s)
capabilities: *cap_newer
set:
ingress:
enabled: true
hosts: *hosts
tls: []
st2web:
service:
hostname: *st2web_hostname
release:
name: st2ha
asserts:
- hasDocuments:
count: 1
- equal:
path: kind
value: Ingress
# no ingress.hosts, so only st2web.hostname
- equal: *st2web_rules_host
- equal: *host_path_is_root_glob
- equal:
path: spec.rules[0].http.paths[0].pathType
value: Prefix
- equal:
path: spec.rules[0].http.paths[0].backend
value:
service:
name: st2ha-st2web
port:
number: 80

- equal:
path: spec.rules[0].http.paths[1].path
value: "/fancy-sensor"
- equal:
path: spec.rules[0].http.paths[1].pathType
value: Prefix
- equal:
path: spec.rules[0].http.paths[1].backend
value:
service:
name: fancy-sensor
port:
number: 8080