-
Notifications
You must be signed in to change notification settings - Fork 45
/
test.sh
executable file
·65 lines (55 loc) · 1.55 KB
/
test.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
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bold=$(tput bold) || true
norm=$(tput sgr0) || true
red=$(tput setaf 1) || true
green=$(tput setaf 2) || true
yellow=$(tput setaf 3) || true
fail() {
echo "${red}$*${norm}."
exit 1
}
delete-ns() {
echo "${bold}Cleaning up...${norm}"
kubectl delete --ignore-not-found namespace spire > /dev/null
}
cleanup() {
if [ -z "${GOOD}" ]; then
echo "${yellow}Dumping statefulset/spire-server logs...${norm}"
kubectl -nspire logs statefulset/spire-server --all-containers
echo "${yellow}Dumping daemonset/spire-agent logs...${norm}"
kubectl -nspire logs daemonset/spire-agent --all-containers
fi
delete-ns
if [ -n "${GOOD}" ]; then
echo "${green}Success.${norm}"
else
echo "${red}Failed.${norm}"
fi
}
trap cleanup EXIT
echo "${bold}Preparing environment...${norm}"
delete-ns
kubectl create namespace spire
echo "${bold}Applying configuration...${norm}"
kubectl apply -k "${DIR}"
LOGLINE="Agent attestation request completed"
for ((i=0;i<120;i++)); do
if ! kubectl -nspire rollout status statefulset/spire-server; then
sleep 1
continue
fi
if ! kubectl -nspire rollout status daemonset/spire-agent; then
sleep 1
continue
fi
if ! kubectl -nspire logs statefulset/spire-server -c spire-server | grep -e "$LOGLINE" ; then
sleep 1
continue
fi
echo "${bold}Node attested.${norm}"
GOOD=1
exit 0
done
echo "${red}Timed out waiting for node to attest.${norm}"
exit 1