Skip to content

feat(components): isolate per-CR Helm actuation state by UID - #1239

Merged
VLukiantsev merged 6 commits into
mainfrom
feat/components-per-cr-helm-release-b548436300
Oct 20, 2026
Merged

VLukiantsev merged 6 commits into
mainfrom
feat/components-per-cr-helm-release-b548436300

Conversation

@VLukiantsev

@VLukiantsev VLukiantsev commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Helm actuation state, upgrade error tracking and async upgrade coalescing are now keyed by the Component's UID, so duplicate CRs in other namespaces or superseded incarnations never overwrite or cancel the active owner's state.

Motivation & Context

State keyed only by name let a conflicting or recreated CR clobber the live owner's actuation state, and deleting it could purge the owner's release. #1240 relies on per-CR state to clean up only the deleted CR's own workload.

Key Changes

  • ComponentRef.UID carried through K8sHelmManager actuation state, upgrade error tracking and upgrade coalescing.
  • ComponentReleaseNameForRef keeps returning the canonical xmc-cmp-<name> release name, for live upgrade and Orphan adoption compatibility.
  • ComponentReleaseName canonicalizes its input with naming.CanonicalComponentName, so release names match the CMS form (components/foo → xmc-cmp-foo). CR names are plain DNS labels, so the bridge's behavior is unchanged.
  • CRD CEL validation enforces metadata.name ≤ 45 characters, so the release name stays within Helm limits, and rejects names starting with xmc-cmp-, so release names are never doubly prefixed. Both rules are create-only (optionalOldSelf), so a Component stored before them can still be updated, have its status written and its finalizer removed.
  • Actuating a new incarnation evicts every kind of state held by superseded incarnations (actuation, upgrade errors, pending upgrades, health, repair) and the namespace-level entry hydrated from the values ConfigMap. Reconciler.ForgetComponent also evicts the Helm manager state of every incarnation once the CR is gone, so ghost incarnations no longer leak. An asynchronous upgrade that finishes after its incarnation was evicted or superseded has its outcome discarded rather than recreating that state.
  • Teardown semantics: Purge1PComponent always runs the Helm uninstall, even when ConfigMap and in-memory state are empty (cold start, fenced cluster). Delete no longer treats the ConfigMap-hydrated namespace entry as proof of a prior uninstall, so after a restart it uninstalls leaked releases.

Stack Position

Assumptions

  • Keeping the canonical release name, rather than a new per-namespace name, is preferable — it avoids reinstalling existing releases — impact if wrong: a future multi-namespace bridge would need distinct release names.
  • No existing Component name exceeds 45 characters — profile components are short — a longer name would now be rejected at admission. Likewise, no existing Component name starts with xmc-cmp-. Objects stored before the rules stay updatable because the rules are create-only.
  • Extra Helm uninstall calls on a cold start are acceptable — uninstalling a missing release is a no-op, and it removes leaked releases — impact if wrong: more Helm API calls after a bridge restart, relevant to the fenced-deletion path in feat(components): enforce deletion ownership and fenced CR cleanup #1240.
  • Ghost-incarnation eviction, the xmc-cmp- CEL rule, create-only name rules and the evicted-upgrade guard are covered by unit and envtest tests only; the live GKE evidence below predates them.
  • The live GKE evidence still applies to this revision — it was collected before the last rebase onto main, and git range-diff shows no behavioral change — if wrong, the checkpoint must be re-run before merge.

Verification & Testing

  • Commands Executed: bazel test //pkg/components/bridge:bridge_test //cmd/xmc_bridge:xmc_bridge_test; bazel test //pkg/components/... //cmd/xmc_bridge/... //api:protos_breaking_test at feat(components): enforce deletion ownership and fenced CR cleanup #1240 and the stack top.
  • Coverage & Test Status: all pass. The new create-only CEL envtest and the evicted-upgrade test both fail without their fixes.
  • KinD E2E: //test/e2e:components_lifecycle_test passed with the whole stack applied.
  • Diff size (tools/analyze_diff_size.py): 247 prod / 437 test / 2 doc lines.

Live Deployment & Manual Testing

Scenario Result Observation
Per-CR UID actuation state across recreate and conflict teardown ✅ PASS Recreating mt-cp3-recreate and deleting the conflicting mt-cp3-del2 kept actuation state per CR UID and uninstalled only the deleted CR's local Helm release (action=purge).

Related Issues / Bugs

Bug: 548436300

TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c


Stack created with GitHub Stacks CLI • Give Feedback 💬

@VLukiantsev
VLukiantsev added this pull request to stack #1245 October 13, 2026 07:27

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces per-CR incarnation isolation for Helm component management by adding a UID field to ComponentRef and transitioning state tracking keys to include this UID. It also adds a CEL validation rule to the Component CRD to limit metadata.name to 45 characters, ensuring Helm release names stay within limits. While these changes successfully isolate different CR incarnations, a critical issue was identified in uninstallComponent where a disabled component's Helm release could be leaked on a controller cold start because the uninstall is skipped when the specific incarnation key is not yet known in memory. A suggestion has been provided to check if the incarnation key is explicitly known before skipping the uninstall.

Comment thread pkg/components/bridge/helm_manager.go Resolved
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces per-CR-incarnation isolation for Helm component releases by incorporating the Kubernetes metadata UID into the state tracking keys. This prevents stale or superseded custom resource incarnations from interfering with active ones during upgrades or teardowns. Additionally, a CEL validation rule is added to the CRD to limit component names to 45 characters, ensuring Helm release names stay within the 53-character limit. Feedback on the changes suggests removing redundant calls to dropPendingUpgrade and setUpgradeErr in uninstallComponent since these are already handled internally by forgetIncarnationLocked.

Comment thread pkg/components/bridge/helm_manager.go Resolved
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch from 7594a81 to 87674b5 Compare October 13, 2026 15:09
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch from 87674b5 to 23e6001 Compare October 13, 2026 15:25
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch 2 times, most recently from 2749898 to a2a44e0 Compare October 14, 2026 09:49
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch from a2a44e0 to 5925ae3 Compare October 14, 2026 10:54
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch from 5925ae3 to bb0e46d Compare October 14, 2026 11:58
@VLukiantsev
VLukiantsev removed this pull request from stack #1245 October 14, 2026 13:31
@VLukiantsev
VLukiantsev added this pull request to stack #1277 October 14, 2026 13:32
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch from bb0e46d to 3b8141e Compare October 14, 2026 13:54
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch 5 times, most recently from f5803f0 to f53f44a Compare October 15, 2026 09:29
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch from f53f44a to 31ce028 Compare October 15, 2026 09:49
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch from f88605f to f74228b Compare October 16, 2026 11:27
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch 3 times, most recently from 7e12b24 to 3a837df Compare October 16, 2026 13:09
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch 2 times, most recently from 198ebe0 to bf0791f Compare October 16, 2026 13:45
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch from bf0791f to dd3ce3c Compare October 16, 2026 14:39
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch 2 times, most recently from 990b5a2 to 2ece4b9 Compare October 16, 2026 15:27
@VLukiantsev
VLukiantsev force-pushed the feat/components-per-cr-helm-release-b548436300 branch 2 times, most recently from 175338e to a880612 Compare October 19, 2026 07:45
Comment thread pkg/components/bridge/helm_manager.go Resolved
Comment thread pkg/components/bridge/helm_manager.go Resolved
Carry ComponentRef.UID across K8sHelmManager actuation state, upgrade
error tracking, and async upgrade coalescing so duplicate Component CRs
in different namespaces or superseded CR incarnations in the same
namespace never overwrite or cancel an active owner's state. Keep
ComponentReleaseNameForRef returning the canonical xmc-cmp-<name>
release name for live upgrade and Orphan adoption compatibility, and
enforce metadata.name <= 45 in CEL admission validation.

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
…elete

Skip the Delete uninstall only when the CR incarnation's own UID-scoped
state is recorded as inactive. The namespace-level entry hydrated from
the values ConfigMap on cold start cannot prove that the incarnation's
release was already uninstalled, so it no longer suppresses the
uninstall. Also drop a trailing blank line flagged by gofmt.

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
When a CR incarnation is actuated, drop the in-memory activation,
actuation, upgrade, health and repair state of every other incarnation
of the same namespace/name. Kubernetes keeps one live CR per name, so a
stale incarnation whose teardown never ran could otherwise suppress the
live incarnation's uninstall or run an outdated queued upgrade.
Superseded and purged incarnations now delete their entries instead of
leaving permanent inactive markers.

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
…carnations

forgetIncarnationLocked already clears the incarnation's pending upgrade,
upgrade error and cached health verdict.

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
…refix

Adopting a release with a new CR incarnation now evicts every kind of
in-memory state of superseded incarnations (actuation, upgrade errors,
pending upgrades, health and repair) plus the namespace-level entry
hydrated from the values ConfigMap. Reconciler.ForgetComponent also
evicts the Helm manager state of every incarnation once the CR is gone,
so incarnations whose teardown never ran no longer leak.

The Component CRD rejects metadata.name values starting with xmc-cmp-,
preventing doubly prefixed release names.

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
…rade outcomes

- Mark the metadata.name CEL rules optionalOldSelf with an oldSelf.hasValue()
  guard, so a Component stored before the rules existed can still be updated,
  have its status written and its finalizer removed after a CRD upgrade.
  Covered by a new envtest.
- Record an asynchronous upgrade outcome only while the request is still the
  incarnation's pending upgrade. An outcome for an incarnation evicted by a
  teardown or ForgetComponent mid-upgrade is logged and discarded instead of
  recreating its upgradeErrs entry.
- Cover ComponentReleaseName canonicalization of resource-style names.

Addresses:
- #1239 (comment)
- #1239 (comment)
- #1239 (comment)

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority::2-high top of mind. should not wait.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants