Skip to content

Commit 00c0a68

Browse files
committed
refactor(scaletest/templates/scaltest/runner/scripts): extract coder_pods and namespace functions
1 parent 1e75762 commit 00c0a68

File tree

1 file changed

+24
-10
lines changed
  • scaletest/templates/scaletest-runner/scripts

1 file changed

+24
-10
lines changed

scaletest/templates/scaletest-runner/scripts/lib.sh

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,33 +247,47 @@ set_appearance() {
247247
"${CODER_URL}/api/v2/appearance"
248248
}
249249

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+
250264
# fetch_coder_full fetches the full (non-slim) coder binary from one of the coder pods
251265
# running in the same namespace as the current pod.
252266
fetch_coder_full() {
253267
if [[ -x "${SCALETEST_CODER_BINARY}" ]]; then
254268
log "Full Coder binary already exists at ${SCALETEST_CODER_BINARY}"
255269
return
256270
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
261273
log "Could not determine namespace!"
262274
exit 1
263275
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)
269283
if [[ -z ${pod} ]]; then
270284
log "Could not find coder pod!"
271285
exit 1
272286
fi
273287
log "Fetching full Coder binary from ${pod}"
274288
# We need --retries due to https://github.com/kubernetes/kubernetes/issues/60140 :(
275289
maybedryrun "${DRY_RUN}" kubectl \
276-
--namespace "${namespace}" \
290+
--namespace "${ns}" \
277291
cp \
278292
--container coder \
279293
--retries 10 \

0 commit comments

Comments
 (0)