Skip to content

Drop blockOwnerDeletion on runner-owned Services - #7337

Merged
ChrisJBurns merged 3 commits into
mainfrom
ChrisJBurns/toolhive-issue-6836
Nov 26, 2026
Merged

ChrisJBurns merged 3 commits into
mainfrom
ChrisJBurns/toolhive-issue-6836

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Why: The proxy runner puts a StatefulSet owner reference with blockOwnerDeletion: true on the mcp-<name> and mcp-<name>-headless Services. Under OwnerReferencesPermissionEnforcement (on by default in OpenShift), setting that flag requires update on apps/statefulsets/finalizers, which Add /finalizers subresource for OKD/OpenShift installs #6756 granted to both the proxy-runner Role and the operator ClusterRole. The flag only matters for foreground cascading deletion, and toolhive never deletes that way: RemoveWorkload uses empty DeleteOptions, finalizeMCPServer deletes by name, and nothing sets PropagationPolicy. Dropping the flag lets us drop the permission. That is least privilege: with the grant, every MCPServer's runner service account could set blocking owner references on any StatefulSet in its namespace.
  • What:
    • ensureBackendServices and applyService no longer set blockOwnerDeletion. The owner reference and controller: true are unchanged, so GC still removes the Services when the StatefulSet is deleted. Because the runner applies with Force: true as the field owner, existing Services lose the field on their next apply. Removing the flag never triggers the admission check.
    • Removed the apps/statefulsets/finalizers rule from defaultRBACRules and its +kubebuilder:rbac marker, regenerated role.yaml (task operator-manifests), and updated the Chainsaw ClusterRole and proxy-runner Role fixtures. upsertRole replaces a Role's rules wholesale, so existing Roles shrink without a migration.
    • The mcpremoteproxies/finalizers and virtualmcpservers/finalizers markers from Add /finalizers subresource for OKD/OpenShift installs #6756 stay. They aren't related to this flag.

Closes #6836

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

TestDeployWorkloadCreatesBackendServices now asserts blockOwnerDeletion is absent on both Services. A new table case first applies both Services under the runner's field manager with blockOwnerDeletion: true (as older runners did), then runs DeployWorkload and checks that the flag is gone. This is the upgrade path for existing Services.

Integration test (cmd/thv-operator/test-integration/mcp-server-ownerref-admission/, run by task operator-test-integration): the envtest API server runs with OwnerReferencesPermissionEnforcement on, through a new testutil.SuiteOptions.EnableAdmissionPlugins option, so other suites are unchanged.

  • Positive case: the real MCPServerReconciler generates the proxy-runner Role. The runner's actual DeployWorkload then runs as that ServiceAccount, and both Services must be created with the StatefulSet owner and no blockOwnerDeletion. A small goroutine marks the StatefulSet ready, since envtest has no StatefulSet controller.
  • Negative control: the same ServiceAccount creating a Service with blockOwnerDeletion: true must be rejected with cannot set blockOwnerDeletion. This proves the plugin is on, so the positive case can't pass vacuously, and it fails if the finalizers grant comes back.
  • Mutation check: with WithBlockOwnerDeletion(true) temporarily put back in applyService, the positive case fails with the Proxy runner fails on OpenShift creating owned Services #6835 error. The suite passes on repeated runs. The kind e2e cluster enforces OwnerReferencesPermissionEnforcement since Enforce owner reference permissions in kind e2e #7334, so the operator e2e suite in CI proves Services are still created without the finalizers grant.

Does this introduce a user-facing change?

Yes, it is visible on the Services and in RBAC, but has no functional effect.

  • Before: the owner reference on mcp-<name> and mcp-<name>-headless had blockOwnerDeletion: true. On main (unreleased), the operator ClusterRole and every proxy-runner Role carried update on apps/statefulsets/finalizers.
  • After: the field is absent and the grant is gone. Existing Services lose the field on the runner's next apply. Deleting the StatefulSet (without orphaning) still garbage-collects the Services. OpenShift clusters create the Services without any extra RBAC.

Special notes for reviewers

🤖 Generated with Claude Code

The proxy runner set blockOwnerDeletion on the StatefulSet owner
reference of its headless and ClusterIP Services. Under
OwnerReferencesPermissionEnforcement (OpenShift) that requires update
on apps/statefulsets/finalizers. The flag only affects foreground
cascading deletion, which toolhive never uses, so it bought nothing
but an extra RBAC requirement. GC still removes the Services when the
StatefulSet is deleted.

The statefulsets/finalizers grant stays for one release so a new
operator paired with an older pinned runner image keeps working.

Closes #6836

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added the size/XS Extra small PR: < 100 lines changed label Nov 26, 2026
The runner no longer sets blockOwnerDeletion, so neither the
proxy-runner Role nor the operator ClusterRole needs update on
apps/statefulsets/finalizers. The grant from #6756 has not shipped in
a release, so there is no mixed-version runner to keep working.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Nov 26, 2026
Run the proxy-runner's real DeployWorkload, as its ServiceAccount with
the operator-generated Role, against an envtest API server with
OwnerReferencesPermissionEnforcement enabled. Both Services must be
created without the finalizers grant, and a blockOwnerDeletion owner
reference must be rejected, which proves the plugin is on and pins
that the grant is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added size/M Medium PR: 300-599 lines changed and removed size/S Small PR: 100-299 lines changed labels Nov 26, 2026
@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.44%. Comparing base (9300f3f) to head (f227ce6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7337      +/-   ##
==========================================
+ Coverage   82.40%   82.44%   +0.04%     
==========================================
  Files         937      937              
  Lines       95821    95819       -2     
==========================================
+ Hits        78962    78999      +37     
+ Misses      16854    16815      -39     
  Partials        5        5              

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

@rdimitrov rdimitrov left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. This matches the plan in #6836, and I checked the seams against a real API server rather than only the fake clientset.

Design. The PR drops the grant outright instead of keeping it for one release, which departs from the sequencing in the #6836 plan. The reason holds: v0.69.1 shipped on 2026-11-25 and #6756 merged on 2026-11-26, so the apps/statefulsets/finalizers grant has never been in a release. The only pairing this affects is a new operator with an older runner image pinned through operator.toolhiveRunnerImage, and that pairing was already broken on OpenShift before #6756.

Verified locally on this branch

  • pkg/container/kubernetes, the operator controllers and the RBAC packages pass.
  • The new mcp-server-ownerref-admission suite passes under envtest with OwnerReferencesPermissionEnforcement on.
  • With a temporary extra spec on the same envtest harness (not part of the PR), I ran the two paths the PR only covers with the fake clientset:
    • Legacy Services: I server-side-applied blockOwnerDeletion: true under toolhive-container-manager, then ran the real DeployWorkload as the proxy-runner ServiceAccount with the generated Role. The flag was dropped and nothing was rejected.
    • Recreated StatefulSet (new UID): the Services were re-owned to the new UID, with no flag and no finalizers grant.
    • The upgrade claim holds because applyService has used server-side apply with that one field manager since #3992, so no other field manager owns the flag.
  • Only client.go ever set the flag. The remaining blockOwnerDeletion references are SetControllerReference owners on the operator side, which mcpservers/finalizers covers and which this PR leaves alone.

Risk for existing users

  • On non-OpenShift clusters there is no functional change. Deletion is background everywhere (RemoveWorkload, finalizeMCPServer), so GC still removes the Services.
  • Anyone who deletes a StatefulSet by hand with --cascade=foreground no longer waits on the Services. That is harmless.
  • Mixed versions are better than before. A newer runner against an older operator chart now works without the grant.

One release-process point. This must merge before the next release is cut. If a release goes out first, the grant ships and the #6836 one-release rule applies again. The PR body already says so.

@ChrisJBurns
ChrisJBurns merged commit 420f1b5 into main Nov 26, 2026
57 of 59 checks passed
@ChrisJBurns
ChrisJBurns deleted the ChrisJBurns/toolhive-issue-6836 branch November 26, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drop blockOwnerDeletion on proxy-runner owned Services

2 participants