From 6e13b75eced35fb8f6249204393c32a6cbeecefa Mon Sep 17 00:00:00 2001 From: Lucas Koontz Date: Mon, 2 Nov 2026 15:05:32 -0800 Subject: [PATCH 1/2] fix(argocd-pr-env-deploy): check the customer label against the env before skipping, fail at once on a parent CI can't change (ENG-3919) --- argocd-pr-env-deploy/action.yml | 201 +++++++++++++++------------- scripts/prune_pr_environments.py | 8 +- tests/test_argocd_pr_env_deploy.py | 112 ++++++++++++++-- tests/test_prune_pr_environments.py | 2 + 4 files changed, 212 insertions(+), 111 deletions(-) diff --git a/argocd-pr-env-deploy/action.yml b/argocd-pr-env-deploy/action.yml index ba8eae8..ecb3646 100644 --- a/argocd-pr-env-deploy/action.yml +++ b/argocd-pr-env-deploy/action.yml @@ -34,7 +34,8 @@ # (the AppSet's ignoreApplicationDifferences no longer reverts it). # - A PR labeled `customer:` deploys nothing. An admin deploys # customer envs, and the Argo CD token this action holds can only read -# their parents. +# their parents. The label is still checked against the env that exists +# first, so a label added after `deploy` is refused, not skipped. # # Linked-PR image tags resolve in order: # 1. `development-head-` — pushed by build-push-ecr's PR @@ -250,9 +251,105 @@ runs: PR_BODY="$(jq -r '.body // ""' <<<"$PR_JSON" | tr -d '\r')" LABEL_HOST="$(jq -r '[.labels[].name | select(startswith("customer:")) | ltrimstr("customer:")] | first // ""' <<<"$PR_JSON")" + # Post a comment on the anchor PR explaining a refused deploy. + post_blocking_comment() { + jq -n --arg b "$1" '{body: $b}' \ + | curl -sfX POST -H "Authorization: Bearer $GH_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/$OWN_REPO/issues/$PR_NUMBER/comments" \ + --data @- >/dev/null \ + || echo "::warning::could not post the blocking comment to ${OWN_REPO}#${PR_NUMBER} (does the gh-token allow writing issue comments?)" >&2 + } + + # Install argocd CLI to a writable location if missing. /usr/local/bin + # is owned by root on self-hosted runners; $RUNNER_TEMP is per-job + # and always user-writable. + if command -v argocd >/dev/null 2>&1; then + ARGOCD_BIN=argocd + else + ARGOCD_BIN="${RUNNER_TEMP:-/tmp}/argocd" + if [ ! -x "$ARGOCD_BIN" ]; then + curl -sSLo "$ARGOCD_BIN" "https://github.com/argoproj/argo-cd/releases/download/${ARGOCD_VERSION}/argocd-linux-amd64" + chmod +x "$ARGOCD_BIN" + fi + fi + + # Flags every argocd call needs, resolved once. + # + # --grpc-web is unconditional: it is harmless on a direct connection and + # required through the nginx ingress. + # + # --plaintext is the endpoint question. argocd-server runs with + # `server.insecure: true`, so it serves cleartext on Service port 80 and + # expects TLS to terminate upstream at the ingress. Talking to the + # Service directly therefore MUST be plaintext, and talking to the public + # hostname must NOT be. `auto` reads that off the endpoint rather than + # making callers keep two inputs consistent by hand; an explicit + # true/false still wins for anything this rule does not cover. + case "${ARGOCD_PLAINTEXT:-auto}" in + true) ARGOCD_PLAINTEXT_RESOLVED=true ;; + false) ARGOCD_PLAINTEXT_RESOLVED=false ;; + auto) + case "$ARGOCD_SERVER" in + *.svc.cluster.local|*.svc.cluster.local:*|*.svc|*.svc:*|localhost|localhost:*|127.0.0.1|127.0.0.1:*) + ARGOCD_PLAINTEXT_RESOLVED=true ;; + *) + ARGOCD_PLAINTEXT_RESOLVED=false ;; + esac + ;; + *) + echo "::error::argocd-plaintext must be 'auto', 'true' or 'false' (got '${ARGOCD_PLAINTEXT}')." + exit 1 + ;; + esac + ARGOCD_FLAGS=(--grpc-web) + if [ "$ARGOCD_PLAINTEXT_RESOLVED" = true ]; then + ARGOCD_FLAGS+=(--plaintext) + fi + echo "ArgoCD endpoint: ${ARGOCD_SERVER} (plaintext=${ARGOCD_PLAINTEXT_RESOLVED})" + + # Skip `argocd login` — it doesn't honour --auth-token (login only + # accepts username/password/sso), and the ARGOCD_SERVER + + # ARGOCD_AUTH_TOKEN env vars set above are picked up by every + # subsequent argocd command directly. + + # Compare the PR's `customer:` label with the env that exists. An + # ordinary env reads its label once, when the ApplicationSet creates it, + # and an admin creates a customer env's parent. A parent that is absent + # or being deleted has nothing to compare: skip, and for an ordinary PR + # the `app set` retry below waits for the ApplicationSet to create it. + PARENT_JSON="" + get_errfile="$(mktemp)" + if ! PARENT_JSON="$("$ARGOCD_BIN" app get "$PARENT_APP" "${ARGOCD_FLAGS[@]}" -o json 2>"$get_errfile")"; then + PARENT_JSON="" + get_err="$(cat "$get_errfile")" + case "$get_err" in + *PermissionDenied*|*NotFound*|*"not found"*|*"permission denied"*|*"being deleted"*) + echo "Application ${PARENT_APP} not found or being deleted; skipping the customer label check." + ;; + *) + echo "argocd app get ${PARENT_APP} failed unexpectedly:" >&2 + echo "$get_err" >&2 + rm -f "$get_errfile" + exit 1 + ;; + esac + fi + rm -f "$get_errfile" + if [ -n "$PARENT_JSON" ]; then + PARENT_HOST="$(jq -r '[.spec.source.helm.parameters[]? | select(.name=="hostBase") | .value] | first // ""' <<<"$PARENT_JSON")" + if [ "$LABEL_HOST" != "$PARENT_HOST" ]; then + comment="**PR-env deploy blocked.** This PR's \`customer:\` label does not match the environment that already exists (label: \`${LABEL_HOST}\`, env: \`${PARENT_HOST}\`). An ordinary env reads the label only when it is created, and an admin creates a customer env. Remove the \`deploy\` label and wait for the env to disappear; an admin then sets up the customer env (internal-documentation pr-environments.md, \"Per-customer checklist\")." + post_blocking_comment "$comment" + echo "::error::Refusing to deploy: customer label '${LABEL_HOST}' does not match the existing env's hostBase '${PARENT_HOST}'." + exit 1 + fi + fi + # An admin deploys a customer env, pinning its parent to a reviewed # argocd-envs commit. This action's token can read that parent but not - # change it, so a customer-labeled PR sets nothing here. + # change it, so a customer-labeled PR whose label matches its env, or + # that has no env yet, sets nothing here. A mismatch was refused above. if [ -n "$LABEL_HOST" ]; then echo "::notice::This PR carries customer:${LABEL_HOST}. An admin deploys customer envs, so this job changes nothing in Argo CD." exit 0 @@ -504,16 +601,6 @@ runs: done ) - # Post a comment on the anchor PR explaining a refused deploy. - post_blocking_comment() { - jq -n --arg b "$1" '{body: $b}' \ - | curl -sfX POST -H "Authorization: Bearer $GH_TOKEN" \ - -H "Accept: application/vnd.github+json" \ - "https://api.github.com/repos/$OWN_REPO/issues/$PR_NUMBER/comments" \ - --data @- >/dev/null \ - || echo "::warning::could not post the blocking comment to ${OWN_REPO}#${PR_NUMBER} (does the gh-token allow writing issue comments?)" >&2 - } - # Fail closed on any unresolvable Deploys link, and comment on the # anchor PR so the cause is visible without digging through the log. if [ "${#unresolved_links[@]}" -gt 0 ]; then @@ -532,89 +619,6 @@ runs: echo "Parent chart (argocd-envs) pinned to branch ${ENVS_REVISION} via ${ENVS_LINK}." fi - # Install argocd CLI to a writable location if missing. /usr/local/bin - # is owned by root on self-hosted runners; $RUNNER_TEMP is per-job - # and always user-writable. - if command -v argocd >/dev/null 2>&1; then - ARGOCD_BIN=argocd - else - ARGOCD_BIN="${RUNNER_TEMP:-/tmp}/argocd" - if [ ! -x "$ARGOCD_BIN" ]; then - curl -sSLo "$ARGOCD_BIN" "https://github.com/argoproj/argo-cd/releases/download/${ARGOCD_VERSION}/argocd-linux-amd64" - chmod +x "$ARGOCD_BIN" - fi - fi - - # Flags every argocd call needs, resolved once. - # - # --grpc-web is unconditional: it is harmless on a direct connection and - # required through the nginx ingress. - # - # --plaintext is the endpoint question. argocd-server runs with - # `server.insecure: true`, so it serves cleartext on Service port 80 and - # expects TLS to terminate upstream at the ingress. Talking to the - # Service directly therefore MUST be plaintext, and talking to the public - # hostname must NOT be. `auto` reads that off the endpoint rather than - # making callers keep two inputs consistent by hand; an explicit - # true/false still wins for anything this rule does not cover. - case "${ARGOCD_PLAINTEXT:-auto}" in - true) ARGOCD_PLAINTEXT_RESOLVED=true ;; - false) ARGOCD_PLAINTEXT_RESOLVED=false ;; - auto) - case "$ARGOCD_SERVER" in - *.svc.cluster.local|*.svc.cluster.local:*|*.svc|*.svc:*|localhost|localhost:*|127.0.0.1|127.0.0.1:*) - ARGOCD_PLAINTEXT_RESOLVED=true ;; - *) - ARGOCD_PLAINTEXT_RESOLVED=false ;; - esac - ;; - *) - echo "::error::argocd-plaintext must be 'auto', 'true' or 'false' (got '${ARGOCD_PLAINTEXT}')." - exit 1 - ;; - esac - ARGOCD_FLAGS=(--grpc-web) - if [ "$ARGOCD_PLAINTEXT_RESOLVED" = true ]; then - ARGOCD_FLAGS+=(--plaintext) - fi - echo "ArgoCD endpoint: ${ARGOCD_SERVER} (plaintext=${ARGOCD_PLAINTEXT_RESOLVED})" - - # Skip `argocd login` — it doesn't honour --auth-token (login only - # accepts username/password/sso), and the ARGOCD_SERVER + - # ARGOCD_AUTH_TOKEN env vars set above are picked up by every - # subsequent argocd command directly. - - # The `customer:` label is read only when the env is created. A parent - # that is absent or being deleted has nothing to compare: skip, and the - # `app set` retry below waits for the ApplicationSet to create it. - PARENT_JSON="" - get_errfile="$(mktemp)" - if ! PARENT_JSON="$("$ARGOCD_BIN" app get "$PARENT_APP" "${ARGOCD_FLAGS[@]}" -o json 2>"$get_errfile")"; then - PARENT_JSON="" - get_err="$(cat "$get_errfile")" - case "$get_err" in - *PermissionDenied*|*NotFound*|*"not found"*|*"permission denied"*|*"being deleted"*) - echo "Application ${PARENT_APP} not found or being deleted; skipping the customer label check." - ;; - *) - echo "argocd app get ${PARENT_APP} failed unexpectedly:" >&2 - echo "$get_err" >&2 - rm -f "$get_errfile" - exit 1 - ;; - esac - fi - rm -f "$get_errfile" - if [ -n "$PARENT_JSON" ]; then - PARENT_HOST="$(jq -r '[.spec.source.helm.parameters[]? | select(.name=="hostBase") | .value] | first // ""' <<<"$PARENT_JSON")" - if [ "$LABEL_HOST" != "$PARENT_HOST" ]; then - comment="**PR-env deploy blocked.** This PR's \`customer:\` label does not match the environment that already exists (label: \`${LABEL_HOST}\`, env: \`${PARENT_HOST}\`). The label is read only when the env is created. Remove the \`deploy\` label, wait for the env to disappear, then add \`customer:\` first and \`deploy\` second." - post_blocking_comment "$comment" - echo "::error::Refusing to deploy: customer label '${LABEL_HOST}' does not match the existing env's hostBase '${PARENT_HOST}'." - exit 1 - fi - fi - # Turn the staff console off when nothing selects it any more. Only the # two staff console parameters go: a parent can carry other parameters # set by hand, which this must keep. A parent that does not exist yet @@ -647,6 +651,13 @@ runs: if set_err="$("$ARGOCD_BIN" app set "$PARENT_APP" "${ARGOCD_FLAGS[@]}" "${set_args[@]}" 2>&1)"; then break fi + # A parent the token could read but can't change won't become + # set-able by waiting: it belongs to a project ci-pr-envs doesn't hold. + if [ -n "$PARENT_JSON" ] && [[ "$set_err" == *PermissionDenied* || "$set_err" == *"permission denied"* ]]; then + echo "::error::ci-pr-envs may not change ${PARENT_APP} (project $(jq -r '.spec.project' <<<"$PARENT_JSON")); an admin deploys it." >&2 + echo "$set_err" >&2 + exit 1 + fi case "$set_err" in *PermissionDenied*|*NotFound*|*"not found"*|*"permission denied"*|*"being deleted"*) ;; *) diff --git a/scripts/prune_pr_environments.py b/scripts/prune_pr_environments.py index cae7fae..2e8c197 100644 --- a/scripts/prune_pr_environments.py +++ b/scripts/prune_pr_environments.py @@ -9,9 +9,9 @@ Environments are listed before PRs, so an environment created mid-run is left for the next run. A repo whose PR list cannot be read is skipped entirely. -A closed PR labelled ``deploy`` and ``customer:`` had a customer env -whose data nothing deletes, so each one gets a single comment listing it (see -``REMINDER``). Every closed PR is scanned, so a PR missed while the job was +A closed PR labelled ``deploy`` and ``customer:`` anchors a customer +env, which an admin removes and whose data nothing deletes, so each one gets a +single comment saying so (see ``REMINDER``). Every closed PR is scanned, so a PR missed while the job was failing is still reminded once it recovers. """ @@ -29,7 +29,7 @@ CUSTOMER_PREFIX = "customer:" MARKER = "" REMINDER = MARKER + """ -This customer env is gone, but its data is not. Delete by hand when the engagement is over: +Closing this PR leaves its customer env running: an admin removes it, in the order internal-documentation `pr-environments.md` gives under "Ending a customer env". Its data outlives that. Delete by hand when the engagement is over: - Files: the `customer-envs/{host_base}/` prefix in the bucket named by `filesBucket` in argocd-envs `parent/values.yaml` - Cowork workspaces: the `pr-{slug}-{number}` directory on the cowork EFS - Postgres: the retained PersistentVolume for `data-postgres-postgresql-0` in namespace `pr-{slug}-{number}` (`kubectl get pv | grep pr-{slug}-{number}`) diff --git a/tests/test_argocd_pr_env_deploy.py b/tests/test_argocd_pr_env_deploy.py index c53ef5e..570e71b 100644 --- a/tests/test_argocd_pr_env_deploy.py +++ b/tests/test_argocd_pr_env_deploy.py @@ -13,6 +13,7 @@ `argocd` that records its arguments. """ +import json import os import subprocess from pathlib import Path @@ -65,7 +66,7 @@ def test_warns_against_retrying_with_the_deploy_label(self): STAFF_FUNCTIONS_START = "is_revision_only_repo() {" LINKS_START = 'if is_revision_only_repo "$OWN_SHORT"; then' -LINKS_END = "\n\n# Post a comment on the anchor PR" +LINKS_END = "\n\n# Fail closed on any unresolvable" STAFF_OFF_START = "# Turn the staff console off when nothing selects it any more." STAFF_OFF_END = "\n\n# Retry `app set` directly" APP_SET_CALL = '"$ARGOCD_BIN" app set "$PARENT_APP"' @@ -212,30 +213,117 @@ def test_the_switch_off_runs_after_reading_the_parent_and_before_app_set(): CUSTOMER_SKIP_START = 'LABEL_HOST="$(jq' CUSTOMER_SKIP_END = "\n\n# Lint: `Deploys:`-looking lines" +APP_SET_RETRY_START = "# Retry `app set` directly" +APP_SET_RETRY_END = "\n\n# A sync operation may be in flight" -def run_customer_skip(labels): - """Run the action from reading the PR's labels through the customer check.""" +def fake_tools(tmp_path: Path, argocd_body: str) -> dict[str, str]: + """`argocd` and `curl` on PATH: argocd runs `argocd_body`, curl records each comment it would post.""" + bin_dir = tmp_path / "bin" + bin_dir.mkdir() + for name, body in (("argocd", argocd_body), ("curl", 'cat >>"$COMMENTS"; printf "\\n" >>"$COMMENTS"')): + tool = bin_dir / name + tool.write_text(f"#!/usr/bin/env bash\n{body}\n", encoding="utf-8") + tool.chmod(0o755) + return {"PATH": f"{bin_dir}:{os.environ['PATH']}", "COMMENTS": str(tmp_path / "comments")} + + +def run_customer_check(tmp_path: Path, labels, parent_host=None): + """Run the action from reading the PR's labels through the customer check. + + `parent_host` None means no parent exists; otherwise the parent carries + that hostBase. Returns the run and the comments posted on the PR. + """ + if parent_host is None: + argocd = 'echo "rpc error: code = PermissionDenied desc = permission denied" >&2; exit 1' + else: + parent = {"spec": {"project": "x", "source": {"helm": {"parameters": [{"name": "hostBase", "value": parent_host}]}}}} + argocd = f"printf '%s' '{json.dumps(parent)}'" segment = RUN[RUN.index(CUSTOMER_SKIP_START):RUN.index(CUSTOMER_SKIP_END)] - pr_json = '{"labels": [' + ", ".join(f'{{"name": "{name}"}}' for name in labels) + "]}" + pr_json = json.dumps({"labels": [{"name": name} for name in labels]}) script = f'PR_JSON="$1"\n{segment}\necho "went on to argocd"' - return subprocess.run(["bash", "-c", script, "_", pr_json], capture_output=True, text=True) + env = { + **os.environ, + **fake_tools(tmp_path, argocd), + "PARENT_APP": "pr-mindshub-frontend-7", + "ARGOCD_SERVER": "argo.example", + "OWN_REPO": "mindsdb/mindshub_frontend", + "PR_NUMBER": "7", + "GH_TOKEN": "x", + } + result = subprocess.run(["bash", "-c", script, "_", pr_json], capture_output=True, text=True, env=env) + comments = tmp_path / "comments" + return result, comments.read_text(encoding="utf-8") if comments.exists() else "" class TestCustomerEnvs: - def test_a_customer_labeled_pr_stops_before_argocd(self): - result = run_customer_skip(["deploy", "customer:acme"]) + def test_a_customer_pr_with_no_env_yet_is_left_to_an_admin(self, tmp_path): + result, comments = run_customer_check(tmp_path, ["deploy", "customer:acme"]) assert result.returncode == 0 assert "::notice::This PR carries customer:acme. An admin deploys customer envs" in result.stdout assert "went on to argocd" not in result.stdout + assert comments == "" - def test_an_ordinary_pr_goes_on(self): - result = run_customer_skip(["deploy"]) + def test_a_customer_pr_whose_env_matches_is_left_to_an_admin(self, tmp_path): + result, comments = run_customer_check(tmp_path, ["deploy", "customer:acme"], parent_host="acme") + assert result.returncode == 0 + assert "went on to argocd" not in result.stdout + assert comments == "" + + def test_a_customer_label_on_an_ordinary_env_is_refused(self, tmp_path): + # The label came after deploy: the env exists with no hostBase. + result, comments = run_customer_check(tmp_path, ["deploy", "customer:acme"], parent_host="") + assert result.returncode == 1 + assert "PR-env deploy blocked" in comments + assert "Per-customer checklist" in comments + + def test_an_ordinary_pr_on_a_customer_env_is_refused(self, tmp_path): + result, comments = run_customer_check(tmp_path, ["deploy"], parent_host="acme") + assert result.returncode == 1 + assert "PR-env deploy blocked" in comments + + def test_an_ordinary_pr_goes_on(self, tmp_path): + result, comments = run_customer_check(tmp_path, ["deploy"]) assert result.returncode == 0 assert "went on to argocd" in result.stdout + assert comments == "" -def test_the_customer_check_runs_before_any_argocd_call(): +def test_the_label_is_checked_against_the_env_before_the_customer_skip(): skip = RUN.index('if [ -n "$LABEL_HOST" ]; then') - assert skip < RUN.index(PARENT_GET_CALL) < RUN.index(APP_SET_CALL) - assert skip < RUN.index('"$ARGOCD_BIN"') + assert RUN.index(PARENT_GET_CALL) < RUN.index("PR-env deploy blocked.** This PR's") < skip + # A customer PR stops before link resolution and anything that changes Argo CD. + assert skip < RUN.index("# Lint: `Deploys:`-looking lines") < RUN.index(APP_SET_CALL) + + +def run_app_set_retry(tmp_path: Path, parent_json: str): + """Run the `app set` retry against an argocd that always answers PermissionDenied.""" + script = "\n".join([ + "set -euo pipefail", + "sleep() { :; }", + "ARGOCD_FLAGS=(--grpc-web)", + "set_args=(--helm-set tags.x=y)", + run_slice(APP_SET_RETRY_START, APP_SET_RETRY_END), + ]) + env = { + **os.environ, + **fake_tools(tmp_path, 'echo "rpc error: code = PermissionDenied desc = permission denied" >&2; exit 1'), + "ARGOCD_BIN": "argocd", + "PARENT_APP": "pr-mindshub-frontend-1651", + "PARENT_JSON": parent_json, + } + return subprocess.run(["bash", "-c", script], capture_output=True, text=True, env=env) + + +class TestAppSetPermission: + def test_a_parent_the_token_reads_but_cannot_change_fails_at_once(self, tmp_path): + result = run_app_set_retry(tmp_path, '{"spec": {"project": "customer-kinaxis"}}') + assert result.returncode == 1 + assert "ci-pr-envs may not change pr-mindshub-frontend-1651 (project customer-kinaxis); an admin deploys it." in result.stderr + assert "attempt" not in result.stdout + + def test_a_parent_not_created_yet_is_waited_for(self, tmp_path): + result = run_app_set_retry(tmp_path, "") + assert result.returncode == 1 + assert "attempt 29/30" in result.stdout + assert "Timed out waiting" in result.stderr diff --git a/tests/test_prune_pr_environments.py b/tests/test_prune_pr_environments.py index ced2d41..2a5fea3 100644 --- a/tests/test_prune_pr_environments.py +++ b/tests/test_prune_pr_environments.py @@ -139,6 +139,8 @@ def test_posts_once_per_closed_customer_pr(self): body = gh.posted_bodies()[0] assert "" in body assert "`customer-envs/acme/`" in body + # An admin owns a customer env's parent, so closing the PR doesn't remove it. + assert "leaves its customer env running: an admin removes it" in body assert "pr-auth-5" in body def test_reminder_names_the_envs_sam_stack(self): From db40c38a0e57bb937a4fafbbda59fffc12837c9a Mon Sep 17 00:00:00 2001 From: Lucas Koontz Date: Mon, 2 Nov 2026 15:06:43 -0800 Subject: [PATCH 2/2] fix(argocd-pr-env-deploy): keep customer and internal names out of messages and tests (ENG-3919) --- argocd-pr-env-deploy/action.yml | 2 +- scripts/prune_pr_environments.py | 2 +- tests/test_argocd_pr_env_deploy.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/argocd-pr-env-deploy/action.yml b/argocd-pr-env-deploy/action.yml index ecb3646..a5a5722 100644 --- a/argocd-pr-env-deploy/action.yml +++ b/argocd-pr-env-deploy/action.yml @@ -339,7 +339,7 @@ runs: if [ -n "$PARENT_JSON" ]; then PARENT_HOST="$(jq -r '[.spec.source.helm.parameters[]? | select(.name=="hostBase") | .value] | first // ""' <<<"$PARENT_JSON")" if [ "$LABEL_HOST" != "$PARENT_HOST" ]; then - comment="**PR-env deploy blocked.** This PR's \`customer:\` label does not match the environment that already exists (label: \`${LABEL_HOST}\`, env: \`${PARENT_HOST}\`). An ordinary env reads the label only when it is created, and an admin creates a customer env. Remove the \`deploy\` label and wait for the env to disappear; an admin then sets up the customer env (internal-documentation pr-environments.md, \"Per-customer checklist\")." + comment="**PR-env deploy blocked.** This PR's \`customer:\` label does not match the environment that already exists (label: \`${LABEL_HOST}\`, env: \`${PARENT_HOST}\`). An ordinary env reads the label only when it is created, and an admin creates a customer env. Remove the \`deploy\` label and wait for the env to disappear; an admin then sets up the customer env." post_blocking_comment "$comment" echo "::error::Refusing to deploy: customer label '${LABEL_HOST}' does not match the existing env's hostBase '${PARENT_HOST}'." exit 1 diff --git a/scripts/prune_pr_environments.py b/scripts/prune_pr_environments.py index 2e8c197..29d813f 100644 --- a/scripts/prune_pr_environments.py +++ b/scripts/prune_pr_environments.py @@ -29,7 +29,7 @@ CUSTOMER_PREFIX = "customer:" MARKER = "" REMINDER = MARKER + """ -Closing this PR leaves its customer env running: an admin removes it, in the order internal-documentation `pr-environments.md` gives under "Ending a customer env". Its data outlives that. Delete by hand when the engagement is over: +Closing this PR leaves its customer env running: an admin removes it. Its data outlives that. Delete by hand when the engagement is over: - Files: the `customer-envs/{host_base}/` prefix in the bucket named by `filesBucket` in argocd-envs `parent/values.yaml` - Cowork workspaces: the `pr-{slug}-{number}` directory on the cowork EFS - Postgres: the retained PersistentVolume for `data-postgres-postgresql-0` in namespace `pr-{slug}-{number}` (`kubectl get pv | grep pr-{slug}-{number}`) diff --git a/tests/test_argocd_pr_env_deploy.py b/tests/test_argocd_pr_env_deploy.py index 570e71b..dc108c5 100644 --- a/tests/test_argocd_pr_env_deploy.py +++ b/tests/test_argocd_pr_env_deploy.py @@ -275,7 +275,7 @@ def test_a_customer_label_on_an_ordinary_env_is_refused(self, tmp_path): result, comments = run_customer_check(tmp_path, ["deploy", "customer:acme"], parent_host="") assert result.returncode == 1 assert "PR-env deploy blocked" in comments - assert "Per-customer checklist" in comments + assert "an admin then sets up the customer env" in comments def test_an_ordinary_pr_on_a_customer_env_is_refused(self, tmp_path): result, comments = run_customer_check(tmp_path, ["deploy"], parent_host="acme") @@ -309,7 +309,7 @@ def run_app_set_retry(tmp_path: Path, parent_json: str): **os.environ, **fake_tools(tmp_path, 'echo "rpc error: code = PermissionDenied desc = permission denied" >&2; exit 1'), "ARGOCD_BIN": "argocd", - "PARENT_APP": "pr-mindshub-frontend-1651", + "PARENT_APP": "pr-mindshub-frontend-7", "PARENT_JSON": parent_json, } return subprocess.run(["bash", "-c", script], capture_output=True, text=True, env=env) @@ -317,9 +317,9 @@ def run_app_set_retry(tmp_path: Path, parent_json: str): class TestAppSetPermission: def test_a_parent_the_token_reads_but_cannot_change_fails_at_once(self, tmp_path): - result = run_app_set_retry(tmp_path, '{"spec": {"project": "customer-kinaxis"}}') + result = run_app_set_retry(tmp_path, '{"spec": {"project": "customer-acme"}}') assert result.returncode == 1 - assert "ci-pr-envs may not change pr-mindshub-frontend-1651 (project customer-kinaxis); an admin deploys it." in result.stderr + assert "ci-pr-envs may not change pr-mindshub-frontend-7 (project customer-acme); an admin deploys it." in result.stderr assert "attempt" not in result.stdout def test_a_parent_not_created_yet_is_waited_for(self, tmp_path):