Skip to content

fix(cli): remove exp scaletest from slim binary #9934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/exp_scaletest.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !slim

package cli

import (
Expand Down
18 changes: 18 additions & 0 deletions cli/exp_scaletest_slim.go
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 14 additions & 3 deletions scaletest/lib/coder_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}!"
Expand All @@ -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
Expand Down
41 changes: 40 additions & 1 deletion scaletest/templates/scaletest-runner/scripts/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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}"
}