This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deployments-apply.sh
executable file
·191 lines (160 loc) · 5.19 KB
/
deployments-apply.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/sh
# Copyright 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
set -e
# ---------------- option / arg checking ------------------
SEPARATOR="------------------------------------------------"
usage ()
{
name=${0##*/}
echo "Apply scalability tester deployments to test cluster"
echo
echo "Usage: $name [-v] [test queue names]"
echo
echo "All queue deployments are expected to be in directories named as:"
echo " deployments/<queue name>-queue/"
echo
echo "And their corresponding data volumes (if any), in:"
echo " deployments/<queue name>-queue/volume/"
echo
echo "All queues, and the frontend serving them, will first be"
echo "taken down to make sure everything starts from a clean slate."
echo
echo "If '-v' option is given, also their volumes are deleted"
echo "(this is not done by default in case they are shared)."
echo
echo "Frontend, deployments for the specified test queues, their"
echo "data volumes and client control ingress points, are then"
echo "(re-)applied to the cluster."
echo
echo "ERROR: $1!"
exit 1
}
if [ ! -d deployments ]; then
usage "'deployments' directory is missing"
fi
cd deployments
FRONTEND=frontend/frontend.yaml
NAMESPACE=$(awk '/^ *namespace:/{print $2}' $FRONTEND)
if [ -z "$NAMESPACE" ]; then
usage "unable to determine '$FRONTEND' namespace"
fi
del_vols="false"
if [ "$1" = "-v" ]; then
del_vols="true"
shift
fi
for name in "$@"; do
if [ ! -d "$name-queue" ]; then
usage "'$name-queue' deployment directory for '$name' queue is missing"
fi
done
# ---------------- pod state helper ------------------
# wait upto given timeout until specified number of pods with given prefix are in given state
# in given namespace, and none of those pods are in any other state
wait_pod_state ()
{
SECS=$1
COUNT=$2
PREFIX=$3
SPACE=$4
STATE=$5
echo "Waiting ${SECS}s for $COUNT $SPACE/${PREFIX}* deployment(s) to be in '$STATE' state..."
SLEEP=2
while [ "$SECS" -gt 0 ]; do
# start with sleep to make sure terminated pods are not anymore in running state
SECS=$((SECS-SLEEP))
sleep $SLEEP
# show current deployment status, with node names
kubectl -n "$SPACE" get pods -o wide | grep -F "^$PREFIX" || true
# requested number of deployments not yet in given state?
LINES=$(kubectl -n "$SPACE" get pods | grep -c "^${PREFIX}.* $STATE " || true)
echo "= $LINES/$COUNT pods (${SECS}s remaining)"
if [ "$LINES" -ne "$COUNT" ]; then
continue
fi
# none in any other state?
LINES=$(kubectl -n "$SPACE" get pods | grep -F "^$PREFIX" | grep -vcF " $STATE " || true)
if [ "$LINES" -eq 0 ]; then
# => wait done
return
fi
echo "$LINES pods still in other state(s)"
done
# show state of pods on timeout
echo $SEPARATOR
kubectl -n "$SPACE" get pods | grep -F -e NAME -e "^$PREFIX"
echo $SEPARATOR
echo "ERROR: deployment wait timed out"
# and log for first erroring pod, if errors
CRASHER=$(kubectl -n "$SPACE" get pods | awk "/^${PREFIX}.* (Crash|Error)/"'{print $1; exit}')
if [ "$CRASHER" != "" ]; then
echo $SEPARATOR
echo "kubectl -n $SPACE logs $CRASHER"
kubectl -n "$SPACE" logs "$CRASHER"
echo $SEPARATOR
fi
exit 1
}
# ---------------- previous deployment removal ------------------
# avoid error on missing objects
delete="kubectl delete --ignore-not-found=true"
echo "Removing current scalability tester deployments..."
for queue in *-queue; do
name=${queue%-queue}
echo "Deleting '$name' queue deployment..."
$delete -f "$queue"
# secs count prefix space state
wait_pod_state 20 0 "scalability-tester-backend-$name-" "$NAMESPACE" "Running"
done
# need to be done after all queues have been deleted,
# in case queues use same data volume
for queue in *-queue; do
name=${queue%-queue}
if [ $del_vols = true ] && [ -d "$queue/volume" ]; then
echo "Deleting '$name' data volume..."
$delete -f "$queue/volume/"
fi
done
echo "Deleting frontend deployment / service..."
$delete -f frontend/
$delete -f frontend/service/
# secs count prefix space state
wait_pod_state 20 0 "scalability-tester-frontend-" "$NAMESPACE" "Running"
echo
if [ $# -lt 1 ]; then
echo "No queues specified -> DONE!"
exit 0
fi
# ---------------- create specified deployment ------------------
# as these may be used also for other purposes, do not
# remove them, and use apply instead of create
echo "Creating namespaces..."
kubectl apply -f namespace
# everything done in reverse order compared to deletion
echo "Creating frontend..."
kubectl create -f frontend/service/
kubectl create -f frontend/
# secs count prefix space state
wait_pod_state 60 1 "scalability-tester-frontend-" "$NAMESPACE" "Running"
echo "Starting specified queues..."
for name in "$@"; do
queue="$name-queue"
if [ -d "$queue/volume" ]; then
# as these may be shared, use apply, not create
echo "Creating '$name' data volume..."
kubectl apply -f "$queue/volume/"
fi
echo "Create '$name' queue deployment..."
kubectl create -f "$queue"
wait_pod_state 60 1 "scalability-tester-backend-$name-" "$NAMESPACE" "Running"
done
awk '/name:/{print $2}' namespace/*.yaml | while read -r ns; do
echo
echo "Resulting '$ns' namespace deployments:"
echo " kubectl -n $ns get all | grep -e NAME -e scalability"
echo
kubectl -n "$ns" get all | grep -e NAME -e scalability
done
echo
echo "DONE!"