-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvirtual-service-to-gateway-ref.yaml
55 lines (52 loc) · 1.36 KB
/
virtual-service-to-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
43
44
45
46
47
48
49
50
51
52
53
54
55
apiVersion: kubevious.io/v1alpha1
kind: ClusterRule
metadata:
name: istio-virtual-service-to-gateway-ref
spec:
summary: |
Validate Istio VirtualService to IstioGateway reference.
categories:
- istio
- virtual-service
- istio-gateway
- reference
target: |
Api('networking.istio.io')
.Kind('VirtualService')
rule: |
for(let gatewayTarget of (config.spec?.gateways || []))
{
if (gatewayTarget === 'mesh')
{
continue;
}
let gatewayNaming = gatewayTarget.split('/');
if (gatewayNaming.length == 2) {
let gatewayItem =
Api('networking.istio.io')
.Kind('Gateway')
.name(gatewayNaming[1])
.namespace(gatewayNaming[0])
.single();
if (!gatewayItem)
{
error(`Did not find Gateway ${gatewayNaming[1]} in namespace ${gatewayNaming[0]}`);
}
}
else if (gatewayNaming.length == 1)
{
let gatewayItem =
Api('networking.istio.io')
.Kind('Gateway')
.name(gatewayNaming[0])
.single();
if (!gatewayItem)
{
error(`Did not find Gateway ${gatewayNaming[0]}`);
}
}
else
{
error(`Invalid gateway name: ${gatewayTarget}`);
}
}