@@ -40,7 +40,7 @@ show_json() {
40
40
set_status () {
41
41
dry_run=
42
42
if [[ ${DRY_RUN} == 1 ]]; then
43
- dry_run=" (dry-ryn )"
43
+ dry_run=" (dry-run )"
44
44
fi
45
45
prev_status=$( get_status)
46
46
if [[ ${prev_status} != * " Not started" * ]]; then
@@ -49,6 +49,9 @@ set_status() {
49
49
echo " $( date -Ins) ${* }${dry_run} " >> " ${SCALETEST_STATE_DIR} /status"
50
50
51
51
annotate_grafana " status" " Status: ${* } "
52
+
53
+ status_lower=$( tr ' [:upper:]' ' [:lower:]' <<< " ${*}" )
54
+ set_pod_status_annotation " ${status_lower} "
52
55
}
53
56
lock_status () {
54
57
chmod 0440 " ${SCALETEST_STATE_DIR} /status"
@@ -247,37 +250,58 @@ set_appearance() {
247
250
" ${CODER_URL} /api/v2/appearance"
248
251
}
249
252
253
+ namespace () {
254
+ cat /var/run/secrets/kubernetes.io/serviceaccount/namespace
255
+ }
256
+ coder_pods () {
257
+ kubectl get pods \
258
+ --namespace " $( namespace) " \
259
+ --selector " app.kubernetes.io/name=coder,app.kubernetes.io/part-of=coder" \
260
+ --output jsonpath=' {.items[*].metadata.name}'
261
+ }
262
+
250
263
# fetch_coder_full fetches the full (non-slim) coder binary from one of the coder pods
251
264
# running in the same namespace as the current pod.
252
265
fetch_coder_full () {
253
266
if [[ -x " ${SCALETEST_CODER_BINARY} " ]]; then
254
267
log " Full Coder binary already exists at ${SCALETEST_CODER_BINARY} "
255
268
return
256
269
fi
257
- local pod
258
- local namespace
259
- namespace=$( < /var/run/secrets/kubernetes.io/serviceaccount/namespace)
260
- if [[ -z " ${namespace} " ]]; then
270
+ ns=$( namespace)
271
+ if [[ -z " ${ns} " ]]; then
261
272
log " Could not determine namespace!"
262
- exit 1
273
+ return 1
263
274
fi
264
- log " Namespace from serviceaccount token is ${namespace} "
265
- pod=$( kubectl get pods \
266
- --namespace " ${namespace} " \
267
- --selector " app.kubernetes.io/name=coder,app.kubernetes.io/part-of=coder" \
268
- --output jsonpath=' {.items[0].metadata.name}' )
275
+ log " Namespace from serviceaccount token is ${ns} "
276
+ pods=$( coder_pods)
277
+ if [[ -z ${pods} ]]; then
278
+ log " Could not find coder pods!"
279
+ return
280
+ fi
281
+ pod=$( cut -d ' ' -f 1 <<< " ${pods}" )
269
282
if [[ -z ${pod} ]]; then
270
283
log " Could not find coder pod!"
271
- exit 1
284
+ return
272
285
fi
273
286
log " Fetching full Coder binary from ${pod} "
274
287
# We need --retries due to https://github.com/kubernetes/kubernetes/issues/60140 :(
275
288
maybedryrun " ${DRY_RUN} " kubectl \
276
- --namespace " ${namespace } " \
289
+ --namespace " ${ns } " \
277
290
cp \
278
291
--container coder \
279
292
--retries 10 \
280
293
" ${pod} :/opt/coder" " ${SCALETEST_CODER_BINARY} "
281
294
maybedryrun " ${DRY_RUN} " chmod +x " ${SCALETEST_CODER_BINARY} "
282
295
log " Full Coder binary downloaded to ${SCALETEST_CODER_BINARY} "
283
296
}
297
+
298
+ # set_pod_status_annotation annotates the currently running pod with the key
299
+ # com.coder.scaletest.status. It will overwrite the previous status.
300
+ set_pod_status_annotation () {
301
+ if [[ $# -ne 1 ]]; then
302
+ log " must specify an annotation value"
303
+ return
304
+ else
305
+ maybedryrun " ${DRY_RUN} " kubectl --namespace " $( namespace) " annotate pod " $( hostname) " " com.coder.scaletest.status=$1 " --overwrite
306
+ fi
307
+ }
0 commit comments