diff --git a/scaletest/scaletest.sh b/scaletest/scaletest.sh index 9db7d5a123e74..fdb23d9271bbb 100755 --- a/scaletest/scaletest.sh +++ b/scaletest/scaletest.sh @@ -18,10 +18,11 @@ SCALETEST_CODER_LICENSE="${SCALETEST_CODER_LICENSE:-}" SCALETEST_SKIP_CLEANUP="${SCALETEST_SKIP_CLEANUP:-0}" SCALETEST_CREATE_CONCURRENCY="${SCALETEST_CREATE_CONCURRENCY:-10}" SCALETEST_TRAFFIC_BYTES_PER_TICK="${SCALETEST_TRAFFIC_BYTES_PER_TICK:-1024}" -SCALETEST_TRAFFIC_TICK_INTERVAL="${SCALETEST_TRAFFIC_TICK_INTERVAL:-10}" +SCALETEST_TRAFFIC_TICK_INTERVAL="${SCALETEST_TRAFFIC_TICK_INTERVAL:-10s}" +SCALETEST_DESTROY="${SCALETEST_DESTROY:-0}" script_name=$(basename "$0") -args="$(getopt -o "" -l create-concurrency:,dry-run,help,name:,num-workspaces:,project:,scenario:,skip-cleanup,traffic-bytes-per-tick:,traffic-tick-interval:, -- "$@")" +args="$(getopt -o "" -l create-concurrency:,destroy,dry-run,help,name:,num-workspaces:,project:,scenario:,skip-cleanup,traffic-bytes-per-tick:,traffic-tick-interval:, -- "$@")" eval set -- "$args" while true; do case "$1" in @@ -29,12 +30,16 @@ while true; do SCALETEST_CREATE_CONCURRENCY="$2" shift 2 ;; + --destroy) + SCALETEST_DESTROY=1 + shift + ;; --dry-run) DRY_RUN=1 shift ;; --help) - echo "Usage: $script_name --name --project --num-workspaces --scenario [--dry-run] [--skip-cleanup] [--create-concurrency=]" + echo "Usage: $script_name --name --project --num-workspaces --scenario [--create-concurrency ] [--destroy] [--dry-run] [--skip-cleanup] [--traffic-bytes-per-tick ] [--traffic-tick-interval ]" exit 1 ;; --name) @@ -142,7 +147,7 @@ echo "Initializing terraform." maybedryrun "$DRY_RUN" terraform init echo "Setting up infrastructure." -maybedryrun "$DRY_RUN" terraform apply --var-file="${SCALETEST_SCENARIO_VARS}" --var-file="${SCALETEST_SECRETS}" --auto-approve +maybedryrun "$DRY_RUN" terraform apply --var-file="${SCALETEST_SCENARIO_VARS}" --var-file="${SCALETEST_SECRETS}" --var state=started --auto-approve if [[ "${DRY_RUN}" != 1 ]]; then SCALETEST_CODER_URL=$(<"${CONFIG_DIR}/url") @@ -151,7 +156,21 @@ else fi KUBECONFIG="${PROJECT_ROOT}/scaletest/.coderv2/${SCALETEST_NAME}-cluster.kubeconfig" echo "Waiting for Coder deployment at ${SCALETEST_CODER_URL} to become ready" -maybedryrun "$DRY_RUN" kubectl --kubeconfig="${KUBECONFIG}" -n "coder-${SCALETEST_NAME}" rollout status deployment/coder +max_attempts=10 +for attempt in $(seq 1 $max_attempts); do + maybedryrun "$DRY_RUN" curl --silent --fail --output /dev/null "${SCALETEST_CODER_URL}/api/v2/buildinfo" + curl_status=$? + if [[ $curl_status -eq 0 ]]; then + break + fi + if attempt -eq $max_attempts; then + echo + echo "Coder deployment failed to become ready in time!" + exit 1 + fi + echo "Coder deployment not ready yet (${attempt}/${max_attempts}), sleeping 3 seconds" + maybedryrun "$DRY_RUN" sleep 3 +done echo "Initializing Coder deployment." DRY_RUN="$DRY_RUN" "${PROJECT_ROOT}/scaletest/lib/coder_init.sh" "${SCALETEST_CODER_URL}" @@ -212,5 +231,10 @@ if [[ "${SCALETEST_SKIP_CLEANUP}" == 1 ]]; then exit 0 fi -echo "Cleaning up" -maybedryrun "$DRY_RUN" terraform destroy --var-file="${SCALETEST_SCENARIO_VARS}" --var-file="${SCALETEST_SECRETS}" --auto-approve +if [[ "${SCALETEST_DESTROY}" == 1 ]]; then + echo "Destroying infrastructure" + maybedryrun "$DRY_RUN" terraform destroy --var-file="${SCALETEST_SCENARIO_VARS}" --var-file="${SCALETEST_SECRETS}" --auto-approve +else + echo "Scaling down infrastructure" + maybedryrun "$DRY_RUN" terraform apply --var-file="${SCALETEST_SCENARIO_VARS}" --var-file="${SCALETEST_SECRETS}" --var state=stopped --auto-approve +fi diff --git a/scaletest/terraform/coder.tf b/scaletest/terraform/coder.tf index ad93d100ed5e0..13bd15205b6eb 100644 --- a/scaletest/terraform/coder.tf +++ b/scaletest/terraform/coder.tf @@ -25,13 +25,24 @@ provider "helm" { } } -resource "kubernetes_namespace" "coder_namespace" { - metadata { - name = local.coder_namespace +resource "null_resource" "coder_namespace" { + triggers = { + namespace = local.coder_namespace + kubeconfig_path = local.cluster_kubeconfig_path } depends_on = [ google_container_node_pool.coder ] + provisioner "local-exec" { + when = create + command = <