-
Notifications
You must be signed in to change notification settings - Fork 6
/
runonce.sh
48 lines (34 loc) · 977 Bytes
/
runonce.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
#!/bin/bash
# this has yet to be tested
set -euo pipefail
function main() {
kubectl apply -f configmap.yaml
kubectl apply -f daemonset.yaml
local -r DAEMONSET_NAME="ssm-agent-installer"
local -r PODS="$(kubectl get pods | grep -i "${DAEMONSET_NAME}" | awk '{print $1}')"
wait_for_pods
wait_for_success
kubectl delete -f daemonset.yaml
}
function wait_for_pods() {
echo -n "waiting for ${DAEMONSET_NAME} pods to run"
for POD in ${PODS}; do
while [[ "$(kubectl get pod "${POD}" -o go-template --template "{{.status.phase}}")" != "Running" ]]; do
sleep 1
echo -n "."
done
done
echo
}
function wait_for_success() {
echo -n "waiting for ${DAEMONSET_NAME} daemonset to complete"
for POD in ${PODS}; do
while [[ $(kubectl logs "${POD}" --tail 1) != "Success" ]]; do
sleep 1
echo -n "."
done
# at this point you could take the output of kubectl logs and do something with it
done
echo
}
main