Repository navigation
Drop blockOwnerDeletion on runner-owned Services - #7337
Conversation
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]>
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]>
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]>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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-admissionsuite passes under envtest withOwnerReferencesPermissionEnforcementon. - 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: trueundertoolhive-container-manager, then ran the realDeployWorkloadas 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
applyServicehas used server-side apply with that one field manager since #3992, so no other field manager owns the flag.
- Legacy Services: I server-side-applied
- Only
client.goever set the flag. The remainingblockOwnerDeletionreferences areSetControllerReferenceowners on the operator side, whichmcpservers/finalizerscovers 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=foregroundno 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.
Summary
blockOwnerDeletion: trueon themcp-<name>andmcp-<name>-headlessServices. UnderOwnerReferencesPermissionEnforcement(on by default in OpenShift), setting that flag requiresupdateonapps/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:RemoveWorkloaduses emptyDeleteOptions,finalizeMCPServerdeletes by name, and nothing setsPropagationPolicy. 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.ensureBackendServicesandapplyServiceno longer setblockOwnerDeletion. The owner reference andcontroller: trueare unchanged, so GC still removes the Services when the StatefulSet is deleted. Because the runner applies withForce: trueas the field owner, existing Services lose the field on their next apply. Removing the flag never triggers the admission check.apps/statefulsets/finalizersrule fromdefaultRBACRulesand its+kubebuilder:rbacmarker, regeneratedrole.yaml(task operator-manifests), and updated the Chainsaw ClusterRole and proxy-runner Role fixtures.upsertRolereplaces a Role's rules wholesale, so existing Roles shrink without a migration.mcpremoteproxies/finalizersandvirtualmcpservers/finalizersmarkers from Add /finalizers subresource for OKD/OpenShift installs #6756 stay. They aren't related to this flag.Closes #6836
Type of change
Test plan
task test)task test-e2e)task lint-fix)TestDeployWorkloadCreatesBackendServicesnow assertsblockOwnerDeletionis absent on both Services. A new table case first applies both Services under the runner's field manager withblockOwnerDeletion: true(as older runners did), then runsDeployWorkloadand 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 bytask operator-test-integration): the envtest API server runs withOwnerReferencesPermissionEnforcementon, through a newtestutil.SuiteOptions.EnableAdmissionPluginsoption, so other suites are unchanged.MCPServerReconcilergenerates the proxy-runner Role. The runner's actualDeployWorkloadthen runs as that ServiceAccount, and both Services must be created with the StatefulSet owner and noblockOwnerDeletion. A small goroutine marks the StatefulSet ready, since envtest has no StatefulSet controller.blockOwnerDeletion: truemust be rejected withcannot 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.WithBlockOwnerDeletion(true)temporarily put back inapplyService, 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 enforcesOwnerReferencesPermissionEnforcementsince 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.
mcp-<name>andmcp-<name>-headlesshadblockOwnerDeletion: true. Onmain(unreleased), the operator ClusterRole and every proxy-runner Role carriedupdateonapps/statefulsets/finalizers.Special notes for reviewers
operator.toolhiveRunnerImagewould still fail on OpenShift, but that pairing was already broken before Add /finalizers subresource for OKD/OpenShift installs #6756, so nothing regresses.BlockOwnerDeletionassertions undercmd/thv-operator/cover objects the operator owns throughSetControllerReference. They are out of scope and unchanged.🤖 Generated with Claude Code