Skip to content

test: add an end-to-end check of a deployment - #114

Merged
uniqueg merged 5 commits into
devfrom
test/113-deployment-check
Nov 12, 2026
Merged

uniqueg merged 5 commits into
devfrom
test/113-deployment-check

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds an end-to-end check of a deployed Pubgrade for operators, and runs it in CI.

  • tests/e2e/check.sh, run against a Pubgrade URL with the current kubectl context:
    • creates a test Deployment (rancher/mirrored-pause:3.9) and a Pubgrade-Sidecar (elixircloud/pubgrade-sidecar:0.2.0) with rights on that Deployment only, in a new namespace (or in a named, existing one);
    • registers a repository and a user, verifies the user with an admin, and subscribes the sidecar's PUT /deployment to tag 3.10;
    • publishes 3.10 as a prebuilt image, the way a repository's CI does with builds off (the default). Pubgrade's real flow with builds off is this prebuilt path; with builds on, Pubgrade would build the repository instead, so the default repository URL can't be cloned and the check fails rather than building something;
    • checks that the notification was delivered and that the Deployment rolls out 3.10;
    • then removes everything it created (subscription, user, repository, then the namespace, or only its labelled objects in a named namespace), also on failure. It names anything it couldn't remove.
  • Credentials come only from the environment: PUBGRADE_URL, PUBGRADE_ADMIN_ID, PUBGRADE_ADMIN_TOKEN. No token reaches any argv in check.sh:
    • curl reads headers and bodies from private files (--header @file, and --disable so ~/.curlrc is ignored);
    • manifests go to kubectl create on stdin;
    • jq gets the sidecar token through its environment.
  • Output is one OK: line per step and an ERROR: with the reason on failure, with a non-zero exit. Example: when the callback is unreachable, it prints the notification result and hints at NetworkPolicies or builds being on.
  • Test objects are created, not applied, so existing objects with the same names fail the check instead of being taken over. Optional CHECK_* variables cover the namespace, name prefix, callback URL (for a Pubgrade outside the cluster, through a Route or Ingress), images, tags and timeout.
  • tests/e2e/check-local.sh runs check.sh against Pubgrade from its chart on the throwaway k3s cluster of tests/e2e/cluster.sh, from outside, with a kubeconfig and Pubgrade's URL. That is the same way an operator runs it. It runs in the new CI job check / "Deployment check", which the gate CI passed needs. The ruleset needs no change.
  • Docs: docs/deployment.md gets the new section "Checking a deployment": how to run it, the variables, the rights needed, network and Pod Security notes. docs/development.md covers check-local.sh and CI.

The chart is untouched. #112 changes a different part of docs/deployment.md, so the two shouldn't conflict.

Closes #113

Verification

  • Ran check.sh locally against Pubgrade from the chart on a k3s cluster (the cluster.sh setup) from outside, through the kubeconfig and a port-forward. Cases:
    • default (new namespace): passed, rollout in about 5 s, namespace and Pubgrade objects removed (GET /repositories returns []);
    • CHECK_NAMESPACE=pubgrade CHECK_NAME=pubgrade-check: passed, no labelled objects left, namespace kept;
    • wrong admin token: ERROR: PUT /users/<id>/verify: status 401, cleanup ran, exit 1;
    • unreachable CHECK_CALLBACK_URL: notification ... failed, expected delivered (build status FAILED), cleanup ran, exit 1;
    • missing named namespace: fails, exit 1;
    • existing Service with the check's name: AlreadyExists, exit 1, and the existing Service was kept unchanged.
  • I didn't run check-local.sh end to end locally. Pulling mongo:7.0 inside k3s over this machine's network takes over 4 minutes, longer than cluster.sh's 180 s rollout wait. I ran its steps with MongoDB preloaded (the runs above); CI runs the script itself.
  • pre-commit on the changed files passed (actionlint and others). mkdocs build --strict passed. shellcheck (koalaman/shellcheck:stable -x) passed, apart from the info SC2119 that upgrade.sh has too.
  • CI: all checks passed. The new job "Deployment check" ran check-local.sh end to end (1m32s): every step OK, rollout after 2 s, Check passed. Upgrade, smoke, tests, chart, docs and scans also passed.

Declined review findings

  • Sharing the defaults and the sidecar manifest with upgrade.sh (quality, medium): check.sh must run on its own for operators, without the repository's other scripts. cluster.sh's api runs inside the cluster, so it doesn't fit. docs/development.md says to keep the defaults in line with upgrade.sh.
  • Keeping the variable reference only in the docs (quality, low): the script header lists the variables so that operators can run the script without the docs. Both lists match.
  • The default sidecar image 0.2.0 will go stale (quality, low): it is pinned on purpose, like any default, and CHECK_SIDECAR_IMAGE overrides it. A bump goes with the next sidecar release.
  • cluster.sh puts the throwaway admin token of the local cluster into docker exec argv (adversarial, low): this is existing code, local only, and the token is throwaway. The "no argv" guarantee applies to check.sh, which operators run.

Open questions

None.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV

Summary by Sourcery

Add and require an operator-style end-to-end deployment check for validating a deployed Pubgrade installation.

New Features:

  • Add an operator-facing end-to-end deployment check that validates image publication, notification delivery, and Deployment rollout while cleaning up created resources.

Enhancements:

  • Provide a local-cluster wrapper for running the deployment check from outside the cluster with operator-like connectivity and credentials.
  • Document deployment-check prerequisites, configuration, permissions, networking, security constraints, and local development usage.

CI:

  • Run the deployment check in CI and include it in the required CI gate.

Documentation:

  • Add deployment and development documentation for running and maintaining the end-to-end deployment check.

Tests:

  • Add coverage for the complete deployed Pubgrade workflow, including resource creation, registration, subscription, publication, notification delivery, rollout verification, and failure cleanup.

uniqueg and others added 3 commits November 12, 2026 13:39
tests/e2e/check.sh checks a deployed Pubgrade from outside: it sets up
a test Deployment with a Pubgrade-Sidecar in a namespace of the current
kubectl context, registers a repository, a user and a subscription,
publishes a prebuilt image and checks that the sidecar rolls it out.
It removes everything it created, also on failure, and names anything
left behind. Credentials come from the environment and never reach an
argument list (curl reads headers and bodies from private files).

tests/e2e/check-local.sh runs it against Pubgrade on a throwaway k3s
cluster, from outside with a kubeconfig and Pubgrade's URL, in the new
CI job "Deployment check". The deployment guide says how to run it.

Closes #113

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
A namespace given by CHECK_NAMESPACE must exist and is never created
or deleted; CHECK_NAME sets a fixed prefix, so that a Route or Ingress
can lead to the sidecar of a Pubgrade outside the cluster. The default
repository URL can't be cloned, so that a Pubgrade with builds on
refuses the build instead of building a real repository.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
- Create the test objects instead of applying them: existing objects
  of the same names fail the check instead of being taken over and
  deleted, and no last-applied annotation copies the sidecar's token.
- curl ignores ~/.curlrc (--disable) and has time limits.
- A second interrupt doesn't stop the cleanup halfway.
- Fail if the sidecar's Service doesn't route to it, instead of a
  confusing failed notification later.
- Set the identifiers only once their headers are written, for the
  cleanup.
- Docs: the rights needed, Pod Security, prerequisites, wrapping.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Add the operator-facing check that provisions a test Deployment and sidecar, registers and verifies a user and subscription, publishes a prebuilt image, verifies notification and rollout, and cleans up created resources.

  • tests/e2e/check.sh L1-366

Configuration

Add the local-cluster harness and CI job for running the deployment check, and require its result in the publish and aggregate gates.

  • .github/workflows/ci.yml L4-12, L293-310 (+2 small edits)
  • tests/e2e/check-local.sh L1-55

Documentation

Document how operators configure and run the deployment check, its permissions and network requirements, and how developers run it locally.

  • docs/deployment.md L405-475
  • docs/development.md L65-72, L111-115

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

read-the-docs-community Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 Pubgrade | 🛠️ Build #35842906 | 📁 Comparing 06b1031 against latest (c8087cb)

  🔍 Preview build  

2 files changed
± deployment/index.html
± development/index.html

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9b5beba) to head (06b1031).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #114   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines         1545      1545           
=========================================
  Hits          1545      1545           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 12, 2026 13:49
@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 06b1031

#113 test: add an end-to-end check of a deployment · 3 of 3 met

# Requirement Status Notes
1 Add a script in tests/ that registers a repository, user and subscription, publishes a test image, checks that a test sidecar rolls out its target Deployment, and cleans up everything it created. ✅ Met tests/e2e/check.sh creates the test Deployment and sidecar, registers the repository, user and subscription, publishes the image, verifies delivery and rollout, and cleans up on exit.
2 Take credentials from the environment, never the command line; provide clear output and a non-zero exit code on failure. ✅ Met The script requires credentials from environment variables, writes API headers to private files, logs step results and errors, and exits non-zero on failure.
3 Document how to run the script in the deployment docs. ✅ Met docs/deployment.md explains the check and includes the required environment variables and invocation.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/e2e/check.sh" line_range="59" />
<code_context>
+namespace="${CHECK_NAMESPACE:-pubgrade-check-${run_id}}"
+target="${name}-target"
+sidecar="${name}-sidecar"
+callback_url="${CHECK_CALLBACK_URL:-http://${sidecar}.${namespace}.svc:8080/deployment}"
+sidecar_image="${CHECK_SIDECAR_IMAGE:-elixircloud/pubgrade-sidecar:0.2.0}"
+image="${CHECK_IMAGE:-rancher/mirrored-pause}"
</code_context>
<issue_to_address>
**Callback setting enables SSRF**

When an untrusted caller can set `CHECK_CALLBACK_URL` for a run that has the required Pubgrade credentials, `CHECK_CALLBACK_URL` is stored in the subscription and the subsequent build triggers Pubgrade to send an authenticated PUT to that URL. A caller who can influence this setting when the check runs can make Pubgrade issue requests to hosts reachable from its network, including internal services.

Restrict callback destinations to explicitly trusted hosts or networks before registering the subscription.
</issue_to_address>

### Comment 2
<location path="tests/e2e/check.sh" line_range="54" />
<code_context>
+done
+
+api_url="${PUBGRADE_URL%/}"
+run_id="$(od -An -N4 -tx1 /dev/urandom | tr -d ' \n')"
+name="${CHECK_NAME:-pubgrade-check-${run_id}}"
+namespace="${CHECK_NAMESPACE:-pubgrade-check-${run_id}}"
</code_context>
<issue_to_address>
**A run collision deletes another check**

When two concurrent checks use the same existing `CHECK_NAMESPACE`, omit `CHECK_NAME`, and happen to generate the same 32-bit run ID, the second run’s create fails on the first existing object, then `cleanup` selects the colliding `pubgrade-check` label and deletes the first run’s objects from the shared namespace. The first check loses its Deployment and sidecar.

Use a substantially larger random run ID for names and labels so concurrent runs cannot realistically share an ownership selector.

Also at `tests/e2e/check.sh:147`.
</issue_to_address>

### Comment 3
<location path="tests/e2e/check.sh" line_range="182" />
<code_context>
+# deleted), and no last-applied annotation copies the token
+if [ -z "${CHECK_NAMESPACE:-}" ]; then
+  "${KUBECTL}" create namespace "${namespace}" > /dev/null
+  created_namespace=1
+fi
+created_objects=1
</code_context>
<issue_to_address>
**Created resources escape cleanup**

When the Kubernetes API or Pubgrade commits a create but the response is lost or times out, `create namespace` or `api` returns nonzero before the cleanup flag or resource ID is recorded, so `cleanup` skips deleting the namespace, repository, user, or subscription and leaves it behind.

Make create handling recover and record the created resource for cleanup even when the response is lost.

Also at `tests/e2e/check.sh:308-312`, `tests/e2e/check.sh:315-319`, `tests/e2e/check.sh:331`.
</issue_to_address>

### Comment 4
<location path="tests/e2e/check.sh" line_range="98" />
<code_context>
+  # `--disable` first: no ~/.curlrc, which could log or forward the headers.
+  # The build's POST waits for the notifications
+  local -a args=(--disable --silent --show-error --connect-timeout 10
+    --max-time 120 --request "${method}" --output "${work}/response" --write-out '%{http_code}')
+  if [ -n "${headers}" ]; then
+    args+=(--header "@${headers}")
</code_context>
<issue_to_address>
**Long notifications fail the check**

When pubgrade's configured notification timeout allows a notification request to remain open beyond 120 seconds, `api` stops waiting after 120 seconds and returns a transport error before Pubgrade finishes processing or reports the notification result, so the check reports failure even when the rollout succeeds.

Set the request timeout to cover Pubgrade's configured notification wait, including its additional response margin.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 4 findings to address first, and the check creates a subscription and posts a test build, which causes Pubgrade to send a notification to CHECK_CALLBACK_URL; cleanup can remove the test records and cluster objects, but it cannot recall a notification already sent. The check also uses an admin token to verify its temporary test user.

Blocking findings: tests/e2e/check.sh:59, tests/e2e/check.sh:54, tests/e2e/check.sh:182, tests/e2e/check.sh:98


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/e2e/check.sh Resolved
Comment thread tests/e2e/check.sh Resolved
Comment thread tests/e2e/check.sh Resolved
Comment thread tests/e2e/check.sh Resolved
uniqueg and others added 2 commits November 12, 2026 15:05
- Run IDs have 48 bits instead of 32, so that concurrent checks in one
  namespace don't share a label.
- The namespace is recorded before it is created, and deleted with
  --ignore-not-found, so that a create whose answer got lost is still
  cleaned up.
- Calls to Pubgrade wait up to CHECK_TIMEOUT, as the build's POST waits
  for the notifications.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
@uniqueg
uniqueg merged commit 646c862 into dev Nov 12, 2026
35 checks passed
@uniqueg
uniqueg deleted the test/113-deployment-check branch November 12, 2026 15:44
@uniqueg uniqueg added this to the v0.3.0 milestone Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add an end-to-end check of a deployment

1 participant