-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhook.sh
executable file
·42 lines (37 loc) · 1.21 KB
/
hook.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
#!/bin/bash
#set -x
source /shell_lib.sh
function __config__() {
cat << EOF
configVersion: v1
kubernetes:
- name: nodes
apiVersion: v1
kind: Node
labelSelector:
matchLabels:
node-role.kubernetes.io/egress: "true"
jqFilter: |
{
name: .metadata.name,
taints: .spec.taints
}
group: main
keepFullObjectsInMemory: false
executeHookOnEvent: ["Modified"]
EOF
}
function __main__() {
for i in $(seq 0 "$(context::jq -r '(.snapshots.nodes | length) - 1')"); do
node_name="$(context::jq -r '.snapshots.nodes['"$i"'].filterResult.name')"
taints="$(context::jq -r '.snapshots.nodes['"$i"'].filterResult.taints')"
if echo $taints | grep -v "node.kubernetes.io/unreachable"; then
export egress_ready=$node_name
for i in $(kubectl get ciliumegressgatewaypolicies.cilium.io -o name); do
kubectl get $i -o yaml | yq 'del(.metadata.annotations, .metadata.creationTimestamp, .metadata.generation, .metadata.resourceVersion, .metadata.uid)' | yq '.spec.egressGateway.nodeSelector.matchLabels."kubernetes.io/hostname" = env(egress_ready)' | kubectl apply -f -
done
break
fi
done
}
hook::run "$@"