-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgateway-ref.yaml
42 lines (42 loc) · 1.21 KB
/
gateway-ref.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
apiVersion: kubevious.io/v1alpha1
kind: ClusterRule
metadata:
name: http-route-gateway-ref
spec:
summary: |
Validate HTTPRoute to Gateway reference.
target: |
Api('gateway.networking.k8s.io')
.Kind('HTTPRoute')
categories:
- k8s
- gateway-api
- http-route
- gateway
- reference
rule: |
for(const gatewayRef of config.spec?.parentRefs ?? [])
{
const gatewayItem = Api('gateway.networking.k8s.io')
.Kind('Gateway')
.name(gatewayRef.name)
.namespace(gatewayRef.namespace)
.single();
if (!gatewayItem)
{
if (gatewayRef.namespace) {
error(`Gateway ${gatewayRef.name} not found in namespace ${gatewayRef.namespace}`);
} else {
error(`Gateway ${gatewayRef.name} not found`);
}
}
else
{
if (gatewayRef.sectionName) {
const listener = _.find(gatewayItem.config?.spec.listeners, x => x.name === gatewayRef.sectionName);
if (!listener) {
error(`Could not find listener ${gatewayRef.sectionName} in Gateway ${gatewayRef.name}`);
}
}
}
}