Skip to content

Commit f3ceeca

Browse files
authored
feature: the example plugin ships Gateway API routes beside its Ingress install (#4)
1 parent 84659ed commit f3ceeca

8 files changed

Lines changed: 195 additions & 0 deletions

File tree

‎k8s/gateway/http/httproute.yaml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Both of the shared Gateway's listeners: a proxy may forward to the node over
2+
# HTTP on 80 or HTTPS on 443.
3+
apiVersion: gateway.networking.k8s.io/v1
4+
kind: HTTPRoute
5+
metadata:
6+
name: example-plugin
7+
namespace: 5stack
8+
spec:
9+
parentRefs:
10+
- name: traefik-gateway
11+
namespace: traefik
12+
sectionName: web
13+
- name: traefik-gateway
14+
namespace: traefik
15+
sectionName: websecure
16+
hostnames:
17+
- ${EXAMPLE_PLUGIN_DOMAIN}
18+
rules:
19+
- matches:
20+
- path:
21+
type: PathPrefix
22+
value: /
23+
backendRefs:
24+
- name: example-plugin
25+
port: 80
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
# For panels that route through Traefik and the Gateway API, behind a reverse
5+
# proxy: the base without its Ingress, served by an HTTPRoute on the panel's
6+
# shared Gateway. k8s/overlays stays the install for panels on ingress-nginx.
7+
resources:
8+
- ../../base
9+
- httproute.yaml
10+
11+
patches:
12+
- patch: |-
13+
$patch: delete
14+
apiVersion: networking.k8s.io/v1
15+
kind: Ingress
16+
metadata:
17+
name: example-plugin
18+
namespace: 5stack
19+
20+
replacements:
21+
- source:
22+
kind: ConfigMap
23+
name: example-plugin-config
24+
fieldPath: data.EXAMPLE_PLUGIN_DOMAIN
25+
targets:
26+
- select:
27+
kind: HTTPRoute
28+
name: example-plugin
29+
fieldPaths:
30+
- spec.hostnames.0

‎k8s/gateway/https/certificate.yaml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# The plugin's own certificate.
2+
#
3+
# Not an entry added to the panel's shared 5stack-ssl cert: the panel rebuilds
4+
# that one from its own overlay on every ./update.sh, so anything a plugin added
5+
# there would be silently dropped on the next panel update.
6+
#
7+
# The Issuer is the namespaced Issuer the panel install creates when the site
8+
# terminates TLS itself. If yours is named something else, change issuerRef —
9+
# nothing else in this overlay depends on the name.
10+
#
11+
# ${EXAMPLE_PLUGIN_DOMAIN} is substituted by the replacement in
12+
# kustomization.yaml, from the same file the ingress host comes from.
13+
apiVersion: cert-manager.io/v1
14+
kind: Certificate
15+
metadata:
16+
name: example-plugin-ssl
17+
namespace: 5stack
18+
spec:
19+
secretName: example-plugin-ssl
20+
# Matches the panel's cert cadence: 90d lifetime, renewed with 10d to spare.
21+
duration: 2160h
22+
renewBefore: 240h
23+
dnsNames:
24+
- ${EXAMPLE_PLUGIN_DOMAIN}
25+
issuerRef:
26+
name: 5stack-issuer
27+
kind: Issuer

‎k8s/gateway/https/gateway.yaml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: example-plugin
5+
namespace: 5stack
6+
spec:
7+
gatewayClassName: traefik
8+
listeners:
9+
- name: https
10+
hostname: ${EXAMPLE_PLUGIN_DOMAIN}
11+
protocol: HTTPS
12+
port: 8443
13+
tls:
14+
mode: Terminate
15+
certificateRefs:
16+
- name: example-plugin-ssl
17+
allowedRoutes:
18+
namespaces:
19+
from: Same

‎k8s/gateway/https/httproute.yaml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: example-plugin
5+
namespace: 5stack
6+
spec:
7+
parentRefs:
8+
- name: example-plugin
9+
sectionName: https
10+
hostnames:
11+
- ${EXAMPLE_PLUGIN_DOMAIN}
12+
rules:
13+
- matches:
14+
- path:
15+
type: PathPrefix
16+
value: /
17+
backendRefs:
18+
- name: example-plugin
19+
port: 80
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# No port on the redirect: browsers come back on 443 whatever HTTPS port the
2+
# node uses.
3+
apiVersion: gateway.networking.k8s.io/v1
4+
kind: HTTPRoute
5+
metadata:
6+
name: example-plugin-https-redirect
7+
namespace: 5stack
8+
spec:
9+
parentRefs:
10+
- name: traefik-gateway
11+
namespace: traefik
12+
sectionName: web
13+
hostnames:
14+
- ${EXAMPLE_PLUGIN_DOMAIN}
15+
rules:
16+
- filters:
17+
- type: RequestRedirect
18+
requestRedirect:
19+
scheme: https
20+
statusCode: 308
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
# For panels that route through Traefik and the Gateway API and terminate TLS
5+
# themselves: the plugin's own HTTPS listener on its cert-manager certificate,
6+
# and plain HTTP on the shared listener redirected to it. That listener is
7+
# also where cert-manager's HTTP-01 solver answers.
8+
resources:
9+
- ../../base
10+
- certificate.yaml
11+
- gateway.yaml
12+
- httproute.yaml
13+
- https-redirect.yaml
14+
15+
patches:
16+
- patch: |-
17+
$patch: delete
18+
apiVersion: networking.k8s.io/v1
19+
kind: Ingress
20+
metadata:
21+
name: example-plugin
22+
namespace: 5stack
23+
24+
replacements:
25+
- source:
26+
kind: ConfigMap
27+
name: example-plugin-config
28+
fieldPath: data.EXAMPLE_PLUGIN_DOMAIN
29+
targets:
30+
- select:
31+
kind: Certificate
32+
name: example-plugin-ssl
33+
fieldPaths:
34+
- spec.dnsNames.0
35+
- select:
36+
kind: Gateway
37+
name: example-plugin
38+
fieldPaths:
39+
- spec.listeners.0.hostname
40+
- select:
41+
kind: HTTPRoute
42+
name: example-plugin
43+
fieldPaths:
44+
- spec.hostnames.0
45+
- select:
46+
kind: HTTPRoute
47+
name: example-plugin-https-redirect
48+
fieldPaths:
49+
- spec.hostnames.0

‎public/5stack-plugin.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
"http": "k8s/overlays/http",
1515
"https": "k8s/overlays/https"
1616
},
17+
"gateway": {
18+
"overlays": {
19+
"http": "k8s/gateway/http",
20+
"https": "k8s/gateway/https"
21+
}
22+
},
1723
"certificate": "example-plugin-ssl",
1824
"domain": {
1925
"prefix": "hello",

0 commit comments

Comments
 (0)