Skip to content

Commit 319a8d8

Browse files
committed
Adjusted ingress middleware.
1 parent 97e5213 commit 319a8d8

File tree

6 files changed

+82
-44
lines changed

6 files changed

+82
-44
lines changed

charts/eoapi/templates/networking/ingress-browser.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ metadata:
2020
nginx.ingress.kubernetes.io/rewrite-target: /browser/$2
2121
nginx.ingress.kubernetes.io/use-regex: "true"
2222
{{- end }}
23-
# Temporary annotations for Traefik until uvicorn support real prefix in ASGI: https://github.com/encode/uvicorn/discussions/2490
23+
# Traefik configuration - services handle their own root paths
2424
{{- if eq .Values.ingress.className "traefik" }}
2525
traefik.ingress.kubernetes.io/router.entrypoints: web
26-
traefik.ingress.kubernetes.io/router.middlewares: {{ $.Release.Namespace }}-{{ $.Release.Name }}-strip-prefix-middleware@kubernetescrd
2726
{{- end }}
2827
spec:
2928
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{{- if and .Values.stac.enabled .Values.ingress.enabled (or (not (hasKey .Values.stac "ingress")) .Values.stac.ingress.enabled) }}
2+
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion }}
3+
apiVersion: networking.k8s.io/v1
4+
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion }}
5+
apiVersion: networking.k8s.io/v1beta1
6+
{{- else }}
7+
apiVersion: extensions/v1beta1
8+
{{- end }}
9+
kind: Ingress
10+
metadata:
11+
name: {{ .Release.Name }}-ingress-stac
12+
labels:
13+
app: {{ .Release.Name }}-ingress-stac
14+
annotations:
15+
{{- if .Values.ingress.annotations }}
16+
{{ toYaml .Values.ingress.annotations | indent 4 }}
17+
{{- end }}
18+
# STAC uses stac-auth-proxy which handles its own path manipulation
19+
{{- if eq .Values.ingress.className "traefik" }}
20+
traefik.ingress.kubernetes.io/router.entrypoints: web
21+
{{- end }}
22+
{{- if eq .Values.ingress.className "nginx" }}
23+
nginx.ingress.kubernetes.io/rewrite-target: /$2
24+
nginx.ingress.kubernetes.io/use-regex: "true"
25+
{{- end }}
26+
spec:
27+
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
28+
ingressClassName: {{ .Values.ingress.className }}
29+
{{- end }}
30+
rules:
31+
{{- if .Values.ingress.hosts }}
32+
{{- range .Values.ingress.hosts }}
33+
- host: {{ . }}
34+
http:
35+
paths:
36+
- pathType: {{ if eq $.Values.ingress.className "nginx" }}ImplementationSpecific{{ else }}Prefix{{ end }}
37+
path: {{ $.Values.stac.ingress.path }}{{ if eq $.Values.ingress.className "nginx" }}(/|$)(.*){{ end }}
38+
backend:
39+
service:
40+
{{- if index $.Values "stac-auth-proxy" "enabled" }}
41+
name: {{ $.Release.Name }}-stac-auth-proxy
42+
{{- else }}
43+
name: {{ $.Release.Name }}-stac
44+
{{- end }}
45+
port:
46+
number: {{ $.Values.service.port }}
47+
{{- end }}
48+
{{- else }}
49+
- {{- if .Values.ingress.host }}
50+
host: {{ .Values.ingress.host }}
51+
{{- end }}
52+
http:
53+
paths:
54+
- pathType: {{ if eq .Values.ingress.className "nginx" }}ImplementationSpecific{{ else }}Prefix{{ end }}
55+
path: {{ .Values.stac.ingress.path }}{{ if eq .Values.ingress.className "nginx" }}(/|$)(.*){{ end }}
56+
backend:
57+
service:
58+
{{- if index .Values "stac-auth-proxy" "enabled" }}
59+
name: {{ .Release.Name }}-stac-auth-proxy
60+
{{- else }}
61+
name: {{ .Release.Name }}-stac
62+
{{- end }}
63+
port:
64+
number: {{ .Values.service.port }}
65+
{{- end }}
66+
{{- end }}

charts/eoapi/templates/networking/ingress.yaml

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ metadata:
1919
{{- if .Values.ingress.annotations }}
2020
{{ toYaml .Values.ingress.annotations | indent 4 }}
2121
{{- end }}
22-
# Temporary annotations for Traefik until uvicorn support real prefix in ASGI: https://github.com/encode/uvicorn/discussions/2490
22+
# Traefik stripPrefix middleware for services that need path stripping (excludes STAC)
2323
{{- if eq .Values.ingress.className "traefik" }}
2424
traefik.ingress.kubernetes.io/router.entrypoints: web
2525
traefik.ingress.kubernetes.io/router.middlewares: {{ $.Release.Namespace }}-{{ $.Release.Name }}-strip-prefix-middleware@kubernetescrd
@@ -44,19 +44,7 @@ spec:
4444
number: {{ $.Values.service.port }}
4545
{{- end }}
4646

47-
{{- if and $.Values.stac.enabled (or (not (hasKey $.Values.stac "ingress")) $.Values.stac.ingress.enabled) }}
48-
- pathType: {{ if eq $.Values.ingress.className "nginx" }}ImplementationSpecific{{ else }}Prefix{{ end }}
49-
path: {{ $.Values.stac.ingress.path }}{{ if eq $.Values.ingress.className "nginx" }}(/|$)(.*){{ end }}
50-
backend:
51-
service:
52-
{{- if index $.Values "stac-auth-proxy" "enabled" }}
53-
name: {{ $.Release.Name }}-stac-auth-proxy
54-
{{- else }}
55-
name: {{ $.Release.Name }}-stac
56-
{{- end }}
57-
port:
58-
number: {{ $.Values.service.port }}
59-
{{- end }}
47+
6048

6149
{{- if and $.Values.vector.enabled (or (not (hasKey $.Values.vector "ingress")) $.Values.vector.ingress.enabled) }}
6250
- pathType: {{ if eq $.Values.ingress.className "nginx" }}ImplementationSpecific{{ else }}Prefix{{ end }}
@@ -114,19 +102,7 @@ spec:
114102
number: {{ .Values.service.port }}
115103
{{- end }}
116104

117-
{{- if and .Values.stac.enabled (or (not (hasKey .Values.stac "ingress")) .Values.stac.ingress.enabled) }}
118-
- pathType: {{ if eq .Values.ingress.className "nginx" }}ImplementationSpecific{{ else }}Prefix{{ end }}
119-
path: {{ .Values.stac.ingress.path }}{{ if eq .Values.ingress.className "nginx" }}(/|$)(.*){{ end }}
120-
backend:
121-
service:
122-
{{- if index .Values "stac-auth-proxy" "enabled" }}
123-
name: {{ .Release.Name }}-stac-auth-proxy
124-
{{- else }}
125-
name: {{ .Release.Name }}-stac
126-
{{- end }}
127-
port:
128-
number: {{ .Values.service.port }}
129-
{{- end }}
105+
130106

131107
{{- if and .Values.vector.enabled (or (not (hasKey .Values.vector "ingress")) .Values.vector.ingress.enabled) }}
132108
- pathType: {{ if eq .Values.ingress.className "nginx" }}ImplementationSpecific{{ else }}Prefix{{ end }}

charts/eoapi/templates/networking/traefik-middleware.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- if and .Values.ingress.enabled (eq .Values.ingress.className "traefik") }}
2-
apiVersion: traefik.io/v1alpha1
2+
apiVersion: traefik.containo.us/v1alpha1
33
kind: Middleware
44
metadata:
55
name: {{ .Release.Name }}-strip-prefix-middleware

charts/eoapi/tests/ingress_tests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
suite: unified ingress tests
22
templates:
3-
- templates/services/ingress.yaml
3+
- templates/networking/ingress.yaml
44
tests:
55
- it: "vector ingress with nginx controller"
66
set:
@@ -56,7 +56,7 @@ tests:
5656
path: metadata.annotations
5757
value:
5858
traefik.ingress.kubernetes.io/router.entrypoints: web
59-
traefik.ingress.kubernetes.io/router.middlewares: NAMESPACE-RELEASE-NAME-strip-prefix-middleware@kubernetescrd
59+
traefik.ingress.kubernetes.io/router.middlewares: RELEASE-NAME-strip-prefix-middleware@kubernetescrd
6060
- equal:
6161
path: spec.ingressClassName
6262
value: "traefik"
@@ -150,7 +150,7 @@ tests:
150150
path: metadata.annotations
151151
value:
152152
traefik.ingress.kubernetes.io/router.entrypoints: web
153-
traefik.ingress.kubernetes.io/router.middlewares: NAMESPACE-RELEASE-NAME-strip-prefix-middleware@kubernetescrd
153+
traefik.ingress.kubernetes.io/router.middlewares: RELEASE-NAME-strip-prefix-middleware@kubernetescrd
154154

155155
- it: "multiple hosts with nginx controller"
156156
set:

charts/eoapi/tests/stac-auth-proxy-ingress_test.yaml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
suite: test stac-auth-proxy ingress routing
22
templates:
3-
- networking/ingress.yaml
3+
- networking/ingress-stac.yaml
44

55
tests:
66
- it: should route ingress to stac-auth-proxy when enabled
@@ -23,7 +23,7 @@ tests:
2323
name: RELEASE-NAME-stac-auth-proxy
2424
port:
2525
number: 8080
26-
template: networking/ingress.yaml
26+
template: networking/ingress-stac.yaml
2727

2828
- it: should route ingress directly to stac when auth-proxy is disabled
2929
set:
@@ -45,20 +45,17 @@ tests:
4545
name: RELEASE-NAME-stac
4646
port:
4747
number: 8080
48-
template: networking/ingress.yaml
48+
template: networking/ingress-stac.yaml
4949

50-
- it: should not create stac routes when stac is disabled
50+
- it: should not create stac ingress when stac is disabled
5151
set:
5252
ingress.enabled: true
5353
stac.enabled: false
5454
stac-auth-proxy.enabled: true
5555
asserts:
56-
- notContains:
57-
path: spec.rules[0].http.paths
58-
any: true
59-
content:
60-
path: /stac(/|$)(.*)
61-
template: networking/ingress.yaml
56+
- hasDocuments:
57+
count: 0
58+
template: networking/ingress-stac.yaml
6259

6360
- it: should route correctly with experimental profile
6461
values:
@@ -76,4 +73,4 @@ tests:
7673
name: RELEASE-NAME-stac-auth-proxy
7774
port:
7875
number: 8080
79-
template: networking/ingress.yaml
76+
template: networking/ingress-stac.yaml

0 commit comments

Comments
 (0)