-
Notifications
You must be signed in to change notification settings - Fork 0
/
extended-resources-updater-cm.yaml
40 lines (38 loc) · 1.36 KB
/
extended-resources-updater-cm.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
apiVersion: v1
data:
script: |-
#!/bin/sh
patch_node() {
curl -k --header "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \
--header "Content-Type: application/json-patch+json" \
--request PATCH \
--data '[{"op": "add", "path": "/status/capacity/'$1'~1'$2'", "value": "'$3'"}]' \
https://kubernetes.default.svc.cluster.local/api/v1/nodes/${MY_NODE_NAME}/status
}
# Wait for the Kubernetes API to become available.
until nslookup kubernetes.default >/dev/null 2>&1; do echo "Waiting for Kubernetes API"; sleep 2; done
# Initialise by forcing an update of the state of each resource.
zstick=0
rfxtrx433=0
[ -c /dev/ttyACM0 ] && zstick=1
[ -c /dev/ttyUSB0 ] && rfxtrx433=1
patch_node aeotec zstick $zstick
patch_node rfxcom rfxtrx433 $rfxtrx433
while [ 1 ]
do
zstick_prev=$zstick
rfxtrx433_prev=$rfxtrx433
zstick=0
rfxtrx433=0
[ -c /dev/ttyACM0 ] && zstick=1
[ -c /dev/ttyUSB0 ] && rfxtrx433=1
# Only only call kube-api if there is a change in value since last iteration.
[ $zstick_prev -eq $zstick ] || patch_node aeotec zstick $zstick
[ $rfxtrx433_prev -eq $rfxtrx433 ] || patch_node rfxcom rfxtrx433 $rfxtrx433
sleep 10
done
kind: ConfigMap
metadata:
creationTimestamp: null
name: extended-resources-updater
namespace: kube-system