-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns.sh
executable file
·67 lines (36 loc) · 1.35 KB
/
dns.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
COREFILE="$(kubectl get cm -n kube-system coredns -o=jsonpath='{.data.Corefile}')"
echo -e "$COREFILE"
echo -e "####################"
COREFILE_EDIT="$(echo -e "$COREFILE" | sed '$d')"
COREFILE_EDIT="${COREFILE_EDIT%%rewrite*}"
newline() {
COREFILE_EDIT+=$'\n'
}
TENANT_MATCH='(^\w*\.uds\.dev)'
ADMIN_MATCH='(.*admin\.uds\.dev)'
TENANT_GATEWAY_HOSTNAME="$(kubectl get svc -n istio-tenant-gateway tenant-ingressgateway -o=jsonpath='{.status.loadBalancer.ingress[0].hostname}')"
ADMIN_GATEWAY_HOSTNAME="$(kubectl get svc -n istio-admin-gateway admin-ingressgateway -o=jsonpath='{.status.loadBalancer.ingress[0].hostname}')"
REWRITE_START=" rewrite stop {"
REWRITE_END=" }"
newline
COREFILE_EDIT+="$REWRITE_START"
newline
COREFILE_EDIT+=" name regex $TENANT_MATCH $TENANT_GATEWAY_HOSTNAME answer auto"
newline
COREFILE_EDIT+="$REWRITE_END"
newline
COREFILE_EDIT+="$REWRITE_START"
newline
COREFILE_EDIT+=" name regex $ADMIN_MATCH $ADMIN_GATEWAY_HOSTNAME answer auto"
newline
COREFILE_EDIT+="$REWRITE_END"
newline
COREFILE_EDIT+="}"
echo -e "$COREFILE_EDIT"
echo "############"
PATCH="data:
Corefile: |
$(while IFS= read -r line; do printf '%4s%s\n' '' "$line"; done <<< "$COREFILE_EDIT")"
kubectl patch cm -n kube-system coredns --patch-file <(echo -e "$PATCH")
kubectl rollout restart -n kube-system deployment/coredns