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
This commit is contained in:
Cian Johnston 2023-10-03 15:13:04 +01:00 committed by GitHub
parent 45b53c285f
commit 9aac15212b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 4 deletions

View File

@ -1,3 +1,5 @@
//go:build !slim
package cli
import (

18
cli/exp_scaletest_slim.go Normal file
View File

@ -0,0 +1,18 @@
//go:build slim
package cli
import "github.com/coder/coder/v2/cli/clibase"
func (r *RootCmd) scaletestCmd() *clibase.Cmd {
cmd := &clibase.Cmd{
Use: "scaletest",
Short: "Run a scale test against the Coder API",
Handler: func(inv *clibase.Invocation) error {
SlimUnsupported(inv.Stderr, "exp scaletest")
return nil
},
}
return cmd
}

View File

@ -20,7 +20,6 @@ ARCH="$(arch)"
if [[ "$ARCH" == "x86_64" ]]; then
ARCH="amd64"
fi
PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
if [[ -f "${CONFIG_DIR}/coder.env" ]]; then
echo "Found existing coder.env in ${CONFIG_DIR}!"
@ -29,8 +28,20 @@ if [[ -f "${CONFIG_DIR}/coder.env" ]]; then
fi
maybedryrun "$DRY_RUN" mkdir -p "${CONFIG_DIR}"
echo "Fetching Coder CLI for first-time setup!"
maybedryrun "$DRY_RUN" curl -fsSLk "${CODER_URL}/bin/coder-${PLATFORM}-${ARCH}" -o "${CONFIG_DIR}/coder"
echo "Fetching Coder for first-time setup!"
pod=$(kubectl get pods \
--namespace="${NAMESPACE}" \
--selector="app.kubernetes.io/name=coder,app.kubernetes.io/part-of=coder" \
--output="jsonpath='{.items[0].metadata.name}'")
if [[ -z ${pod} ]]; then
log "Could not find coder pod!"
exit 1
fi
maybedryrun "$DRY_RUN" kubectl \
--namespace="${NAMESPACE}" \
cp \
--container=coder \
"${pod}:/opt/coder" "${CONFIG_DIR}/coder"
maybedryrun "$DRY_RUN" chmod +x "${CONFIG_DIR}/coder"
set +o pipefail

View File

@ -20,11 +20,17 @@ SCALETEST_PHASE_FILE="${SCALETEST_STATE_DIR}/phase"
# shellcheck disable=SC2034
SCALETEST_RESULTS_DIR="${SCALETEST_RUN_DIR}/results"
SCALETEST_PPROF_DIR="${SCALETEST_RUN_DIR}/pprof"
# https://github.com/kubernetes/kubernetes/issues/72501 :-(
SCALETEST_CODER_BINARY="/tmp/coder-full-${SCALETEST_RUN_ID//:/-}"
mkdir -p "${SCALETEST_STATE_DIR}" "${SCALETEST_RESULTS_DIR}" "${SCALETEST_PPROF_DIR}"
coder() {
maybedryrun "${DRY_RUN}" command coder "${@}"
if [[ ! -x "${SCALETEST_CODER_BINARY}" ]]; then
log "Fetching full coder binary..."
fetch_coder_full
fi
maybedryrun "${DRY_RUN}" "${SCALETEST_CODER_BINARY}" "${@}"
}
show_json() {
@ -240,3 +246,36 @@ set_appearance() {
--data "${newjson}" \
"${CODER_URL}/api/v2/appearance"
}
# fetch_coder_full fetches the full (non-slim) coder binary from one of the coder pods
# running in the same namespace as the current pod.
fetch_coder_full() {
if [[ -x "${SCALETEST_CODER_BINARY}" ]]; then
log "Full Coder binary already exists at ${SCALETEST_CODER_BINARY}"
return
fi
local pod
local namespace
namespace=$(</var/run/secrets/kubernetes.io/serviceaccount/namespace)
if [[ -z "${namespace}" ]]; then
log "Could not determine namespace!"
exit 1
fi
log "Namespace from serviceaccount token is ${namespace}"
pod=$(kubectl get pods \
--namespace "${namespace}" \
--selector "app.kubernetes.io/name=coder,app.kubernetes.io/part-of=coder" \
--output jsonpath='{.items[0].metadata.name}')
if [[ -z ${pod} ]]; then
log "Could not find coder pod!"
exit 1
fi
log "Fetching full Coder binary from ${pod}"
maybedryrun "${DRY_RUN}" kubectl \
--namespace "${namespace}" \
cp \
--container coder \
"${pod}:/opt/coder" "${SCALETEST_CODER_BINARY}"
maybedryrun "${DRY_RUN}" chmod +x "${SCALETEST_CODER_BINARY}"
log "Full Coder binary downloaded to ${SCALETEST_CODER_BINARY}"
}