Skip to content

Commit 47dccca

Browse files
committed
Added support for Kubernetes Gateway API
1 parent 58d72b6 commit 47dccca

File tree

8 files changed

+130
-5
lines changed

8 files changed

+130
-5
lines changed

charts/generic-service/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ app:
112112
| `ingress.cors.allowCredentials` | `true` | Indicates whether the caller is allowed to send the actual request (not the preflight) using credentials |
113113
| `ingress.cors.exposeHeaders` | `[]` | List of HTTP headers that the browsers are allowed to access |
114114
| `ingress.class` | | The ingress controller to use (not applicable if `ingress.istio.enabled`) |
115-
| `ingress.annotations` | `{}` | Annotations for `Ingress` or `VirtualService` resource |
115+
| `ingress.gateway.namespace` | | The namespace containing the `Gateway` to use |
116+
| `ingress.gateway.name` | | The name of the `Gateway` to use (creates an `HTTPRoute` instead of an `Ingress` when set) |
117+
| `ingress.annotations` | `{}` | Annotations for `Ingress`, `HTTPRoute` or `VirtualService` resource |
116118
| `ingress.headless` | `false` | Creates an additional `Service` with the suffix `-headless` that directly exposes Pod IPs |
117119
| `ingress.headlessExposesAll` | `false` | Exposes all replicas, including unready ones, via the `-headless` `Service` |
118120
| `ingress.nodeLocal` | `false` | Creates an additional `Service` with the suffix `-local` that only routes to pods on the same node |
@@ -122,6 +124,8 @@ app:
122124
| `ingress.istio.httpHeaders` | `{}` | Custom HTTP response headers |
123125
| `ingress.istio.retries` | `{}` | [Istio retry policy](https://istio.io/docs/reference/config/networking/virtual-service/#HTTPRetry) |
124126
| `ingress.extra.*.class` | same as `ingress.class` | Additional ingress controller to use (not applicable if `ingress.istio.enabled`) |
127+
| `ingress.extra.*.gateway.namespace` | | The namespace containing the `Gateway` to use |
128+
| `ingress.extra.*.gateway.name` | | The name of the `Gateway` to use (creates an `HTTPRoute` instead of an `Ingress` when set) |
125129
| `ingress.extra.*.port` | same as `ingress.port` | Additional container port ingress traffic is routed to (not applicable if `ingress.istio.enabled`) |
126130
| `ingress.extra.*.protocol` | `http` | The protocol used for the port (e.g., `http`, `https`, `h2c`, `grpc`, `http2`/`h2` or `grpcs`) |
127131
| `ingress.extra.*.timeoutSeconds` | | Number of seconds after which to timeout waiting for response from service; -1 for infinite |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Ingress gateway test
2+
3+
image:
4+
repository: jwilder/whoami
5+
tag: latest
6+
7+
ingress:
8+
enabled: true
9+
port: 8000
10+
timeoutSeconds: 5
11+
domains: ['example.com']
12+
gateway:
13+
name: my-gateway
14+
extra:
15+
other-port:
16+
port: 1337
17+
domains: ['custom-port.example.com']
18+
annotations:
19+
key: value
20+
protocol: grpc
21+
timeoutSeconds: 5
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{{- if and .Values.ingress.enabled .Values.ingress.extra }}
2+
{{- range $name, $extra := .Values.ingress.extra }}
3+
{{- $gateway := deepCopy $.Values.ingress.gateway | mustMerge ($extra.gateway | default dict) }}
4+
{{- if $gateway.name }}
5+
6+
apiVersion: gateway.networking.k8s.io/v1beta1
7+
kind: HTTPRoute
8+
metadata:
9+
name: {{ include "generic-service.fullname" $ }}-{{ $name }}
10+
labels: {{- include "generic-service.default-labels" $ | nindent 4 }}
11+
annotations:
12+
{{- $merged := deepCopy ($.Values.ingress.annotations | default dict) | mustMerge ($extra.annotations | default dict) }}
13+
{{- range $mname, $mvalue := $merged }}
14+
{{- if ne $mvalue "nil" }}
15+
{{- dict $mname $mvalue | toYaml | nindent 4 }}
16+
{{- end }}
17+
{{- end }}
18+
19+
spec:
20+
parentRefs:
21+
- {{ $gateway | toYaml | nindent 6 }}
22+
23+
hostnames: {{ $extra.domains | toYaml | nindent 4 }}
24+
25+
rules:
26+
{{- range ($extra.paths | default (list "/")) }}
27+
- matches:
28+
- path:
29+
value: {{ . | quote }}
30+
{{- if or $extra.timeoutSeconds $.Values.ingress.timeoutSeconds }}
31+
timeouts:
32+
backendRequest: {{ $extra.timeoutSeconds | default $.Values.ingress.timeoutSeconds }}s
33+
{{- end }}
34+
backendRefs:
35+
- name: {{ include "generic-service.fullname" $ }}
36+
port: {{ $extra.port | default $.Values.ingress.port }}
37+
{{- end }}
38+
---
39+
{{- end }}
40+
{{- end }}
41+
{{- end }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{{- if and .Values.ingress.enabled .Values.ingress.gateway.name }}
2+
3+
apiVersion: gateway.networking.k8s.io/v1beta1
4+
kind: HTTPRoute
5+
metadata:
6+
name: {{ include "generic-service.fullname" . }}
7+
labels: {{- include "generic-service.top-level-labels" . | nindent 4 }}
8+
annotations: {{ .Values.ingress.annotations | toYaml | nindent 4 }}
9+
10+
spec:
11+
parentRefs:
12+
- {{ .Values.ingress.gateway | toYaml | nindent 6 }}
13+
14+
hostnames: {{ .Values.ingress.domains | toYaml | nindent 4 }}
15+
16+
rules:
17+
{{- range ($.Values.ingress.paths | default (list "/")) }}
18+
- matches:
19+
- path:
20+
value: {{ . | quote }}
21+
{{- if $.Values.ingress.timeoutSeconds }}
22+
timeouts:
23+
backendRequest: {{ $.Values.ingress.timeoutSeconds }}s
24+
{{- end }}
25+
backendRefs:
26+
- name: {{ include "generic-service.fullname" $ }}
27+
port: {{ $.Values.ingress.port }}
28+
{{- end }}
29+
30+
{{- end }}

charts/generic-service/templates/ingress-extra.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{{- if and (and .Values.ingress.enabled .Values.ingress.extra) (not .Values.ingress.istio.enabled) }}
22
{{- range $name, $extra := .Values.ingress.extra }}
3-
{{- if $extra.domains }}
4-
{{ $class := $extra.class | default $.Values.ingress.class }}
3+
{{- $class := $extra.class | default $.Values.ingress.class }}
54
{{ $timeout := $extra.timeoutSeconds | default $.Values.ingress.timeoutSeconds }}
5+
{{- if and $extra.domains (or $class (and (not $extra.gateway) (not $.Values.ingress.gateway.name))) }}
66

77
apiVersion: networking.k8s.io/v1
88
kind: Ingress

charts/generic-service/templates/ingress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and (and .Values.ingress.enabled .Values.ingress.domains) (not .Values.ingress.istio.enabled) }}
1+
{{- if and (and .Values.ingress.enabled .Values.ingress.domains) (and (not .Values.ingress.istio.enabled) (or .Values.ingress.class (not .Values.ingress.gateway.name))) }}
22

33
apiVersion: networking.k8s.io/v1
44
kind: Ingress

charts/generic-service/values.schema.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,23 @@
589589
"type": "string",
590590
"description": "The ingress controller to use (not applicable if ingress.istio.enabled)"
591591
},
592+
"gateway": {
593+
"type": "object",
594+
"properties": {
595+
"namespace": {
596+
"type": "string",
597+
"description": "The namespace containing the Gateway to use"
598+
},
599+
"name": {
600+
"type": "string",
601+
"description": "The name of the Gateway to use (creates an HTTPRoute instead of an Ingress when set)"
602+
}
603+
}
604+
},
592605
"annotations": {
593606
"type": "object",
594607
"additionalProperties": {"type": "string"},
595-
"description": "Annotations for Ingress or VirtualService resource"
608+
"description": "Annotations for Ingress, HTTPRoute or VirtualService resource"
596609
},
597610
"headless": {
598611
"type": "boolean",
@@ -648,6 +661,19 @@
648661
"type": "string",
649662
"description": "Additional ingress controller to use (not applicable if ingress.istio.enabled)"
650663
},
664+
"gateway": {
665+
"type": "object",
666+
"properties": {
667+
"namespace": {
668+
"type": "string",
669+
"description": "The namespace containing the Gateway to use"
670+
},
671+
"name": {
672+
"type": "string",
673+
"description": "The name of the Gateway to use (creates an HTTPRoute instead of an Ingress when set)"
674+
}
675+
}
676+
},
651677
"port": {
652678
"type": "integer",
653679
"description": "The container port ingress traffic is routed to; defaults to value of ingress.port if not set"

charts/generic-service/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ ingress:
121121
allowCredentials: true
122122
exposeHeaders: []
123123
class: ''
124+
# gateway:
125+
# namespace:
126+
# name:
124127
annotations: {}
125128
headless: false
126129
headlessExposesAll: false

0 commit comments

Comments
 (0)