@@ -247,33 +247,47 @@ set_appearance() {
247
247
" ${CODER_URL} /api/v2/appearance"
248
248
}
249
249
250
+ namespace () {
251
+ local ns
252
+ ns=$( < /var/run/secrets/kubernetes.io/serviceaccount/namespace)
253
+ echo " ${ns} "
254
+ }
255
+ coder_pods () {
256
+ local pods
257
+ pods=$( 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
+ echo " ${pods} "
262
+ }
263
+
250
264
# fetch_coder_full fetches the full (non-slim) coder binary from one of the coder pods
251
265
# running in the same namespace as the current pod.
252
266
fetch_coder_full () {
253
267
if [[ -x " ${SCALETEST_CODER_BINARY} " ]]; then
254
268
log " Full Coder binary already exists at ${SCALETEST_CODER_BINARY} "
255
269
return
256
270
fi
257
- local pod
258
- local namespace
259
- namespace=$( < /var/run/secrets/kubernetes.io/serviceaccount/namespace)
260
- if [[ -z " ${namespace} " ]]; then
271
+ ns=$( namespace)
272
+ if [[ -z " ${ns} " ]]; then
261
273
log " Could not determine namespace!"
262
274
exit 1
263
275
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}' )
276
+ log " Namespace from serviceaccount token is ${ns} "
277
+ pods=$( coder_pods)
278
+ if [[ -z ${pods} ]]; then
279
+ log " Could not find coder pods!"
280
+ exit 1
281
+ fi
282
+ pod=$( echo " ${pods} " | cut -d ' ' -f 1)
269
283
if [[ -z ${pod} ]]; then
270
284
log " Could not find coder pod!"
271
285
exit 1
272
286
fi
273
287
log " Fetching full Coder binary from ${pod} "
274
288
# We need --retries due to https://github.com/kubernetes/kubernetes/issues/60140 :(
275
289
maybedryrun " ${DRY_RUN} " kubectl \
276
- --namespace " ${namespace } " \
290
+ --namespace " ${ns } " \
277
291
cp \
278
292
--container coder \
279
293
--retries 10 \
0 commit comments