Skip to content

test: add a two-namespace upgrade test - #44

Merged
uniqueg merged 32 commits into
devfrom
test/two-namespace-upgrade
Nov 6, 2026
Merged

uniqueg merged 32 commits into
devfrom
test/two-namespace-upgrade

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Closes #36

Stacked on #37 and the branches of #34, #33 and #35. Until those are merged, this diff against dev also shows their commits; review only tests/e2e/, the job upgrade and the README note. The base is dev so that CI runs.

Light lane: this adds a test script and a CI job, without touching secrets, permissions or the release workflow.

Summary

  • tests/e2e/upgrade.sh: a throwaway k3s cluster with Pubgrade and MongoDB from the chart, two namespaces with a Deployment and a sidecar each. One publish rolls out both Deployments.
  • Failure paths: an unreachable subscriber (the others still upgrade, and the build shows the failure) and a tag that doesn't exist (nothing changes, and the sidecars report the failure after their retries).
  • Sidecars are built from the branch master of Pubgrade-Sidecar, as no image of it is published yet; SIDECAR_IMAGE can name a local one.
  • CI job upgrade / Upgrade test, part of the gate; README note.

Verification

  • tests/e2e/upgrade.sh locally: passed, in about 3 minutes; publishing took about 1 s, and both namespaces had rolled out within about 5 s. All containers and networks were removed afterwards.
  • CI: all jobs passed, including Upgrade test and CI passed.

Declined review findings

  • Pinning the sidecar to a commit: this test should follow master and fail when the two stop working together. It did so once already, when the sidecar's notifications became asynchronous.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Add a Kubernetes end-to-end upgrade test covering successful multi-namespace rollouts and failure handling, and run it in CI.

New Features:

  • Add an end-to-end upgrade test that verifies one publish rolls out deployments in two Kubernetes namespaces through Pubgrade Sidecars.

Enhancements:

  • Cover unreachable subscribers and nonexistent image tags, including notification failures, retry reporting, and preservation of the current deployment.

CI:

  • Run the upgrade test as a required GitHub Actions CI job and include it in the CI gate and publish dependencies.

Documentation:

  • Document the upgrade test requirements, behavior, and local sidecar image override.
  • Clarify that sidecars perform rollouts asynchronously and report deployment state separately.

Tests:

  • Add reusable throwaway k3s cluster setup and teardown helpers for end-to-end testing.

uniqueg and others added 14 commits November 5, 2026 05:25
Inserting shared mock data into a collection adds an `_id`, and later
tests couldn't serialize it. Two more tests lacked an app context.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replaces Travis and `main.yaml`. Tests run in the image. The smoke test
uses MongoDB 7, which needs a newer pymongo than FOCA 0.7 pins.
Excludes `.env*` from the image build context.

Closes #32

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each call has a timeout and follows no redirects. A failure stays with
its subscriber, and other than 2xx counts as one. The build stores one
result per subscriber, without URLs or tokens.

Closes #34

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With builds off, the default, the POST takes one prebuilt image and
notifies subscribers. Build requests and PUT get a 403. Registration can
be closed by configuration, and a subscription value `*` matches any tag
or branch, as registering again won't work then.

Closes #33

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Configuration from a Secret, and defaults in the image with no users and
no debug mode. Without builds, no updater, shared volume, or rights. Route
or Ingress with TLS, ClusterIP services with own selectors, no fixed user
IDs, MongoDB 7 and camelCase values. The image runs under any user ID.

Closes #35

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Admin users follow the configuration, the probe avoids the database, the
build path finds its own namespace, and the README covers moving from
the old chart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A shared thread limit let calls that hang keep later subscribers in the
queue until the overall wait ended, so these were never called. Each
subscriber now gets a thread, and the setting
`endpoints.subscriptions.max_per_repository` (default: 100) limits the
number of subscriptions per repository, and with it the threads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ages

# Conflicts:
#	pubgrade/errors/exceptions.py
#	pubgrade/modules/endpoints/subscriptions.py
#	tests/pubgrade/endpoints/test_subscriptions.py
One publish upgrades Deployments in two namespaces of a throwaway k3s
cluster, with Pubgrade from its chart and sidecars built from the branch
`master` of Pubgrade-Sidecar. Also covers an unreachable subscriber and a
tag that doesn't exist. Runs in CI as the job `Upgrade test`, part of the
gate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR adds and gates a two-namespace k3s upgrade test while supplying the surrounding Helm, container, CI, API, notification, and configuration changes needed to exercise prebuilt-image fan-out, isolated sidecars, and failure reporting end to end.

Sequence diagram for prebuilt image fan-out upgrades

sequenceDiagram
    participant CI
    participant Pubgrade
    participant SidecarA as Sidecar_namespace_a
    participant SidecarB as Sidecar_namespace_b
    participant DeploymentA as Deployment_namespace_a
    participant DeploymentB as Deployment_namespace_b

    CI->>Pubgrade: POST /repositories/{repo_id}/builds
    Pubgrade->>Pubgrade: validate_prebuilt_image(build_data)
    Pubgrade->>Pubgrade: notify_all_subscriptions(subscription_ids, image, build_id)
    par Notify namespace A
        Pubgrade->>SidecarA: PUT callback_url
        SidecarA-->>Pubgrade: 2xx response
        SidecarA->>DeploymentA: Roll out image tag
    and Notify namespace B
        Pubgrade->>SidecarB: PUT callback_url
        SidecarB-->>Pubgrade: 2xx response
        SidecarB->>DeploymentB: Roll out image tag
    end
    Pubgrade-->>CI: Build status with notifications
Loading

Sequence diagram for notification failure reporting

sequenceDiagram
    participant CI
    participant Pubgrade
    participant ReachableSidecar
    participant UnreachableSidecar

    CI->>Pubgrade: POST /repositories/{repo_id}/builds
    Pubgrade->>Pubgrade: notify_all_subscriptions(subscription_ids, image, build_id)
    par Notify reachable subscriber
        Pubgrade->>ReachableSidecar: PUT callback_url
        ReachableSidecar-->>Pubgrade: 2xx response
    and Notify unreachable subscriber
        Pubgrade->>UnreachableSidecar: PUT callback_url
        UnreachableSidecar-->>Pubgrade: Request timeout or error
    end
    Pubgrade-->>CI: Build status with delivered and failed notifications
Loading

Flow diagram for the gated upgrade test

flowchart TD
    Checkout[Check out repository] --> Helm[Set up Helm]
    Helm --> Upgrade[Run tests/e2e/upgrade.sh]
    Upgrade --> Cluster[Start throwaway k3s cluster]
    Cluster --> Install[Install Pubgrade and MongoDB from Helm]
    Install --> Namespaces[Create two namespaces with sidecars and Deployments]
    Namespaces --> Publish[Publish one tagged prebuilt image]
    Publish --> Rollouts[Verify both Deployments roll out]
    Rollouts --> FailurePaths[Verify unreachable subscriber and nonexistent tag failures]
    FailurePaths --> Gate[CI passed gate]
Loading

File-Level Changes

Change Details Files
Adds a throwaway two-namespace Kubernetes end-to-end upgrade scenario covering successful fan-out and failure handling.
  • Starts and cleans up a containerized k3s cluster.
  • Builds or loads Pubgrade-Sidecar, installs Pubgrade from the Helm chart, and creates isolated targets with namespace-scoped RBAC.
  • Publishes one tagged image and verifies both deployments roll out, unreachable subscribers are reported without blocking others, and nonexistent tags fail without changing deployments.
  • Documents local execution and supports overriding the sidecar and Pubgrade images.
tests/e2e/cluster.sh
tests/e2e/upgrade.sh
README.md
Integrates the upgrade scenario into the GitHub Actions CI gate.
  • Adds an Upgrade test job with Helm setup, repository checkout, and a 20-minute timeout.
  • Includes the job in the aggregate CI passed gate.
  • Runs the workflow on pull requests and pushes to dev without adding credentials or release-workflow permissions.
.github/workflows/ci.yml
Adds supporting image, chart, and test-environment changes required for the end-to-end path.
  • Updates the image and chart defaults for local Kubernetes installation, MongoDB, arbitrary OpenShift user IDs, and configurable image overrides.
  • Runs unit tests inside the application image and adds chart and smoke-test scripts.
  • Adds dependency and configuration adjustments for the CI migration and test execution.
Dockerfile
Makefile
helm/Chart.yaml
helm/values.yaml
tests/chart.sh
tests/smoke.sh
setup.py
setup.cfg
.github/dependabot.yml
.trivyignore.yaml
Implements prebuilt-image publishing and concurrent subscription notification behavior exercised by the upgrade test.
  • Validates tagged image input and routes builds-disabled requests through immediate prebuilt-image publication.
  • Notifies all subscriptions concurrently with bounded timeouts, records delivered/failed/skipped results on the build, and preserves per-subscriber failures.
  • Adds wildcard subscription matching, registration limits/toggles, ownership checks, and safer public build results without callback secrets.
  • Synchronizes configured admin users with MongoDB on startup and documents the expanded API behavior.
pubgrade/modules/endpoints/builds.py
pubgrade/modules/endpoints/subscriptions.py
pubgrade/modules/endpoints/repositories.py
pubgrade/modules/endpoints/users.py
pubgrade/app.py
pubgrade/config.yaml
pubgrade/errors/exceptions.py
pubgrade/api/pubgrade.yaml
Expands automated coverage for publishing, notification concurrency, configuration, and rendered deployment variants.
  • Adds unit tests for prebuilt publishing, validation, notification outcomes, concurrency, time bounds, access control, and registration settings.
  • Adds default-configuration tests and shared fixture state restoration.
  • Adds chart rendering assertions for Kubernetes, OpenShift, ingress, config-secret, and build-enabled variants.
tests/conftest.py
tests/test_config.py
tests/pubgrade/endpoints/test_builds.py
tests/pubgrade/endpoints/test_subscriptions.py
tests/pubgrade/endpoints/test_repositories.py
tests/pubgrade/endpoints/test_users.py
tests/pubgrade/test_server.py
Replaces the legacy CI and chart layout with the current GitHub Actions and Helm application structure.
  • Removes Travis and the previous workflow.
  • Converts the chart to Helm v2 with component-specific resources, selectors, services, optional ingress/Route, MongoDB, updater, and build RBAC.
  • Updates documentation and badges for the new CI, chart installation, configuration, and publishing workflow.
.github/workflows/main.yaml
.travis.yml
helm/templates/_helpers.tpl
helm/templates/mongodb/deployment.yaml
helm/templates/mongodb/network-policy.yaml
helm/templates/mongodb/pvc.yaml
helm/templates/mongodb/service.yaml
helm/templates/pubgrade/deployment.yaml
helm/templates/pubgrade/ingress.yaml
helm/templates/pubgrade/pvc.yaml
helm/templates/pubgrade/role-binding.yaml
helm/templates/pubgrade/role.yaml
helm/templates/pubgrade/route.yaml
helm/templates/pubgrade/service-account.yaml
helm/templates/pubgrade/services.yaml
helm/templates/updater/deployment.yaml
helm/templates/pubgrade-build-complete-updater/deployment.yaml
helm/templates/pubgrade-mongodb/deployment.yaml
helm/templates/pubgrade-mongodb/pvc.yaml
helm/templates/pubgrade-mongodb/service.yaml
helm/templates/pubgrade-webserver/.sops.yaml
helm/templates/pubgrade-webserver/deployment.yaml
helm/templates/pubgrade-webserver/ingress.yaml
helm/templates/pubgrade-webserver/pvc.yaml
helm/templates/pubgrade-webserver/role-binding.yaml
helm/templates/pubgrade-webserver/role.yaml
helm/templates/pubgrade-webserver/secrets.yaml
helm/templates/pubgrade-webserver/service-account.yaml
helm/templates/pubgrade-webserver/services.yaml

Possibly linked issues


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

Sidecars now accept a notification with a 202 and roll out in the
background, so a missing tag only shows in their report, after retries.
The test reads that report, and the README says what `delivered` means.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg marked this pull request as ready for review November 5, 2026 05:42
uniqueg and others added 2 commits November 5, 2026 06:45
Threads per notification stay within the limit of subscriptions, also for
lists longer than that. Completing a build needs the token of the
repository that the build belongs to.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 3 issues

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

## Individual Comments

### Comment 1
<location path="tests/e2e/upgrade.sh" line_range="16" />
<code_context>
+# shellcheck source=tests/e2e/cluster.sh
+source "$(dirname "$0")/cluster.sh"
+
+SIDECAR_REPO="https://github.com/elixir-cloud-aai/Pubgrade-Sidecar.git#master"
+# A small image on Docker Hub that stays up, as the sidecar checks that tags
+# exist there
</code_context>
<issue_to_address>
**Unpinned sidecar breaks or compromises CI**

When the upstream `master` branch changes incompatibly, disappears, or is compromised, `docker build` fetches and executes the current branch's Dockerfile, so an incompatible change or removal breaks the upgrade job without a Pubgrade change, while a compromised branch runs code on the CI runner.

Pin `SIDECAR_REPO` to a reviewed immutable commit.
</issue_to_address>

### Comment 2
<location path="tests/e2e/upgrade.sh" line_range="228" />
<code_context>
+jq -e --arg id "${unreachable}" \
+  '.status == "FAILED" and (.notifications[] | select(.subscription_id == $id) | .result == "failed")' \
+  <<< "${result}" > /dev/null || fail "The unreachable subscriber wasn't reported"
+if grep -Eq 'nobody|callback_url|access_token' <<< "${result}"; then
+  fail "The public build shows URLs or tokens"
+fi
</code_context>
<issue_to_address>
**Secret leaks evade assertion**

When the public build response leaks callback URLs or tokens under other field names, the `upgrade.sh` check only searches for the literals `nobody`, `callback_url`, and `access_token`, so a response that exposes the callback URLs and tokens under neutral keys such as `url` and `token` passes the test.

Assert that each callback URL and token created by the test is absent from the response.
</issue_to_address>

### Comment 3
<location path="tests/e2e/cluster.sh" line_range="22-23" />
<code_context>
+
+# Remove the cluster, with its network and volume
+cluster_down() {
+  docker rm --force --volumes "${E2E_NAME}" > /dev/null 2>&1 || true
+  docker network rm "${E2E_NAME}" > /dev/null 2>&1 || true
+}
+
</code_context>
<issue_to_address>
**Preexisting Docker resources are deleted**

When a user already has a container or network named by `E2E_NAME` (by default, `pubgrade-e2e`), `cluster_up` calls `cluster_down`, and `docker rm --force --volumes` deletes the named container and its volumes before the test starts; the user loses unrelated local state.

Use a unique test-run name and refuse to remove resources unless the script can verify that it created them.
</issue_to_address>

Linked issues

#36 test: add a two-namespace upgrade test · 6 of 6 met

# Requirement Status Notes
1 Run a local k3s cluster with Pubgrade installed from its chart and two namespaces, each with a test Deployment and a Pubgrade-Sidecar instance. ✅ Met The upgrade script starts a throwaway k3s cluster, installs Pubgrade from helm/, and creates both sites with a Deployment and sidecar; it builds the sidecar from the master branch by default.
2 Register a repository and subscriptions, publish one prebuilt image, and check that both Deployments roll out to the new image. ✅ Met tests/e2e/upgrade.sh registers the repository and both subscriptions, makes one publish request, and waits for each Deployment to run the new image.
3 Cover an unreachable sidecar and a tag that doesn't exist. ✅ Met The script checks that the unreachable subscriber is reported as failed while both sites roll out, and that a missing tag is reported as failed without changing either Deployment's image.
4 Add an upgrade / Upgrade test CI job as part of the gate. ✅ Met The workflow defines the Upgrade test job and includes upgrade in the CI passed gate's dependencies.
5 Add a short description in the README. ✅ Met The Development section describes the test, its prerequisites, its two-namespace upgrade and failure-path coverage, and how to supply a local sidecar image.
6 The test passes locally and in CI, and covers the MongoDB version the chart uses by default. ✅ Met The supplied verification reports local and CI passes; the test installs the chart with its default MongoDB image, mongo:7.0.

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and at startup, the configured admin list replaces the stored list, so a missing or incorrect Secret can revoke admin access; restoring the configuration can restore those users. The documented move from chart 0.1 also requires replacing the MongoDB volume, so existing database records are lost and reverting the chart does not bring them back.

Blocking findings: tests/e2e/upgrade.sh:16, tests/e2e/upgrade.sh:228, tests/e2e/cluster.sh:23


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

Comment thread tests/e2e/upgrade.sh Resolved
Comment thread tests/e2e/upgrade.sh Resolved
Comment thread tests/e2e/cluster.sh Resolved
uniqueg and others added 10 commits November 5, 2026 06:46
Image references follow Docker's rules, and requests without images or
image names get a 400 instead of a server error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	tests/pubgrade/endpoints/test_builds.py
MongoDB listens on the configured port, and the builds' Role has no rights
on Services, which nothing uses. The README names the storage class that
builds need, and says to use HTTPS for callbacks outside the cluster.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test looks for the actual tokens in public builds, not only for field
names, and by default no longer reuses the name of existing containers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Push both images by digest in the environment dev-images, scan
exactly those digests, then attest, sign with Sigstore and tag them,
as cloud-registry does. Report unit test coverage to Codecov. Drop
the date tag, which the other repos don't publish.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Always write the coverage report and hand it to the host user, also
when tests fail. Document the environment, secrets and variable that
publishing needs, and how to verify an image's signature.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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.

Linked issues

#36 test: add a two-namespace upgrade test · 3 of 5 met · 1 to check by hand

# Requirement Status Notes
1 Run a local k3s test with Pubgrade from its chart and two namespaces, each with a Deployment and sidecar from Pubgrade-Sidecar's master branch. 🟡 Partly met The test creates the cluster, chart installation, and two namespace setups, but builds the sidecar from the dev branch.
2 Register a repository and subscriptions, publish one prebuilt image, and check that both Deployments roll out. ✅ Met The script publishes once and checks each namespace's Deployment image and rollout.
3 Cover an unreachable subscriber and a tag that doesn't exist. ✅ Met The test checks the unreachable subscriber's failed result while both sites roll out, then checks that a missing tag leaves the Deployments unchanged and is reported as failed.
4 Add an upgrade / Upgrade test CI job as part of the gate, and a short README description. ✅ Met The job runs the test, is included in the publish and gate dependencies, and the README describes the test.
5 Pass locally and in CI, and cover the MongoDB version used by the chart by default. 👀 Check by hand (runtime) Confirm the reported local and CI runs pass; the test installs the chart without overriding its default MongoDB image.

Comment thread tests/e2e/upgrade.sh Resolved
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1236b0d) to head (335aef4).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev       #44   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          669       669           
=========================================
  Hits           669       669           

☔ 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.

…rade

# Conflicts:
#	.github/workflows/ci.yml
#	README.md
@uniqueg
uniqueg requested a review from akash2237778 as a code owner November 6, 2026 05:03
@uniqueg
uniqueg merged commit 08a01c4 into dev Nov 6, 2026
29 of 30 checks passed
@uniqueg
uniqueg deleted the test/two-namespace-upgrade branch November 6, 2026 05:07
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 a two-namespace upgrade test

1 participant