Skip to content

Commit 9aac152

Browse files
authored
fix(cli): remove exp scaletest from slim binary (#9934)
- Removes the `exp scaletest` command from the slim binary - Updates scaletest-runner template to fetch the full binary from the running Coder instance
1 parent 45b53c2 commit 9aac152

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

cli/exp_scaletest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !slim
2+
13
package cli
24

35
import (

cli/exp_scaletest_slim.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//go:build slim
2+
3+
package cli
4+
5+
import "github.com/coder/coder/v2/cli/clibase"
6+
7+
func (r *RootCmd) scaletestCmd() *clibase.Cmd {
8+
cmd := &clibase.Cmd{
9+
Use: "scaletest",
10+
Short: "Run a scale test against the Coder API",
11+
Handler: func(inv *clibase.Invocation) error {
12+
SlimUnsupported(inv.Stderr, "exp scaletest")
13+
return nil
14+
},
15+
}
16+
17+
return cmd
18+
}

scaletest/lib/coder_init.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ ARCH="$(arch)"
2020
if [[ "$ARCH" == "x86_64" ]]; then
2121
ARCH="amd64"
2222
fi
23-
PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
2423

2524
if [[ -f "${CONFIG_DIR}/coder.env" ]]; then
2625
echo "Found existing coder.env in ${CONFIG_DIR}!"
@@ -29,8 +28,20 @@ if [[ -f "${CONFIG_DIR}/coder.env" ]]; then
2928
fi
3029

3130
maybedryrun "$DRY_RUN" mkdir -p "${CONFIG_DIR}"
32-
echo "Fetching Coder CLI for first-time setup!"
33-
maybedryrun "$DRY_RUN" curl -fsSLk "${CODER_URL}/bin/coder-${PLATFORM}-${ARCH}" -o "${CONFIG_DIR}/coder"
31+
echo "Fetching Coder for first-time setup!"
32+
pod=$(kubectl get pods \
33+
--namespace="${NAMESPACE}" \
34+
--selector="app.kubernetes.io/name=coder,app.kubernetes.io/part-of=coder" \
35+
--output="jsonpath='{.items[0].metadata.name}'")
36+
if [[ -z ${pod} ]]; then
37+
log "Could not find coder pod!"
38+
exit 1
39+
fi
40+
maybedryrun "$DRY_RUN" kubectl \
41+
--namespace="${NAMESPACE}" \
42+
cp \
43+
--container=coder \
44+
"${pod}:/opt/coder" "${CONFIG_DIR}/coder"
3445
maybedryrun "$DRY_RUN" chmod +x "${CONFIG_DIR}/coder"
3546

3647
set +o pipefail

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ SCALETEST_PHASE_FILE="${SCALETEST_STATE_DIR}/phase"
2020
# shellcheck disable=SC2034
2121
SCALETEST_RESULTS_DIR="${SCALETEST_RUN_DIR}/results"
2222
SCALETEST_PPROF_DIR="${SCALETEST_RUN_DIR}/pprof"
23+
# https://github.com/kubernetes/kubernetes/issues/72501 :-(
24+
SCALETEST_CODER_BINARY="/tmp/coder-full-${SCALETEST_RUN_ID//:/-}"
2325

2426
mkdir -p "${SCALETEST_STATE_DIR}" "${SCALETEST_RESULTS_DIR}" "${SCALETEST_PPROF_DIR}"
2527

2628
coder() {
27-
maybedryrun "${DRY_RUN}" command coder "${@}"
29+
if [[ ! -x "${SCALETEST_CODER_BINARY}" ]]; then
30+
log "Fetching full coder binary..."
31+
fetch_coder_full
32+
fi
33+
maybedryrun "${DRY_RUN}" "${SCALETEST_CODER_BINARY}" "${@}"
2834
}
2935

3036
show_json() {
@@ -240,3 +246,36 @@ set_appearance() {
240246
--data "${newjson}" \
241247
"${CODER_URL}/api/v2/appearance"
242248
}
249+
250+
# fetch_coder_full fetches the full (non-slim) coder binary from one of the coder pods
251+
# running in the same namespace as the current pod.
252+
fetch_coder_full() {
253+
if [[ -x "${SCALETEST_CODER_BINARY}" ]]; then
254+
log "Full Coder binary already exists at ${SCALETEST_CODER_BINARY}"
255+
return
256+
fi
257+
local pod
258+
local namespace
259+
namespace=$(</var/run/secrets/kubernetes.io/serviceaccount/namespace)
260+
if [[ -z "${namespace}" ]]; then
261+
log "Could not determine namespace!"
262+
exit 1
263+
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}')
269+
if [[ -z ${pod} ]]; then
270+
log "Could not find coder pod!"
271+
exit 1
272+
fi
273+
log "Fetching full Coder binary from ${pod}"
274+
maybedryrun "${DRY_RUN}" kubectl \
275+
--namespace "${namespace}" \
276+
cp \
277+
--container coder \
278+
"${pod}:/opt/coder" "${SCALETEST_CODER_BINARY}"
279+
maybedryrun "${DRY_RUN}" chmod +x "${SCALETEST_CODER_BINARY}"
280+
log "Full Coder binary downloaded to ${SCALETEST_CODER_BINARY}"
281+
}

0 commit comments

Comments
 (0)