Repository navigation
WIP: helm upgrade: check ownership for deletion case - #32257
Closed
cg49996w11 wants to merge 2 commits into
Closed
cg49996w11 wants to merge 2 commits into
cg49996w11 wants to merge 2 commits into
Conversation
Signed-off-by: cg49996w11 <cg49996w11@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an ownership-aware safeguard to Helm’s Kubernetes update/delete flow during helm upgrade, preventing deletion of orphaned resources when they are annotated as belonging to a different Helm release.
Changes:
- Introduces exported constants for Helm ownership annotations (
meta.helm.sh/release-name/meta.helm.sh/release-namespace). - Extends
kube.Client.Updatewith an optional “ownership” update option and uses it from the upgrade action to skip deleting resources owned by other releases. - Adds a unit test covering the “skip delete when owned by a different release” scenario.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
pkg/kube/resource_policy.go |
Adds exported constants for Helm ownership annotations. |
pkg/kube/client.go |
Adds ownership-aware deletion guard and a new ClientUpdateOptionOwnership option. |
pkg/kube/client_test.go |
Adds a test asserting resources owned by a different release are not deleted. |
pkg/action/upgrade.go |
Enables ownership-aware deletion behavior during upgrade by passing the new option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+29
to
+33
| // ReleaseNameAnnotation is the annotation that tracks which release owns a resource | ||
| const ReleaseNameAnnotation = "meta.helm.sh/release-name" | ||
|
|
||
| // ReleaseNamespaceAnnotation is the annotation that tracks which release namespace owns a resource | ||
| const ReleaseNamespaceAnnotation = "meta.helm.sh/release-namespace" |
Comment on lines
+809
to
+812
| // ClientUpdateOptionOwnership specifies the release name and namespace that owns the resources being updated. | ||
| // When set, orphaned resources (present in the original list but not in the target list) will only be deleted | ||
| // if their meta.helm.sh/release-name and meta.helm.sh/release-namespace annotations match the specified | ||
| // release. Resources annotated as belonging to a different release will be skipped. |
Comment on lines
+813
to
+820
| func ClientUpdateOptionOwnership(releaseName, releaseNamespace string) ClientUpdateOption { | ||
| return func(o *clientUpdateOptions) error { | ||
| o.releaseName = releaseName | ||
| o.releaseNamespace = releaseNamespace | ||
|
|
||
| return nil | ||
| } | ||
| } |
gjenkins8
marked this pull request as draft
June 23, 2026 01:20
Member
|
Converted to draft to reflect "WIP: " title |
Signed-off-by: cg49996w11 <cg49996w11@gmail.com>
Comment on lines
+677
to
+691
| if releaseName != "" && annotations != nil { | ||
| annoReleaseName := annotations[ReleaseNameAnnotation] | ||
| annoReleaseNS := annotations[ReleaseNamespaceAnnotation] | ||
| ownedByDifferentRelease := (annoReleaseName != "" && annoReleaseName != releaseName) || | ||
| (releaseNamespace != "" && annoReleaseNS != "" && annoReleaseNS != releaseNamespace) | ||
| if ownedByDifferentRelease { | ||
| c.Logger().Warn("skipping delete of resource not owned by this release", | ||
| slog.String("namespace", info.Namespace), | ||
| slog.String("name", info.Name), | ||
| slog.String("kind", info.Mapping.GroupVersionKind.Kind), | ||
| slog.String("release", releaseName), | ||
| ) | ||
| continue | ||
| } | ||
| } |
Comment on lines
475
to
+477
| kube.ClientUpdateOptionServerSideApply(serverSideApply, u.ForceConflicts), | ||
| kube.ClientUpdateOptionUpgradeClientSideFieldManager(upgradeClientSideFieldManager)) | ||
| kube.ClientUpdateOptionUpgradeClientSideFieldManager(upgradeClientSideFieldManager), | ||
| kube.ClientUpdateOptionOwnership(upgradedRelease.Name, upgradedRelease.Namespace)) |
| err := opt(&o) | ||
| assert.ErrorContains(t, err, "releaseName must not be empty") | ||
|
|
||
| // Non-empty releaseName with empty namespace is allowed (cluster-scoped resources). |
|
This pull request has been marked as stale because it has been open for 90 days with no activity. This pull request will be automatically closed in 30 days if no further activity occurs. |
silence-coding
added a commit
to silence-coding/helm
that referenced
this pull request
Oct 21, 2026
The delete phase of Update (pkg/kube/client.go) is annotation-blind: a resource present in the original release but absent from the target is deleted without consulting meta.helm.sh/release-name. When a resource has been adopted by another release (via --take-ownership), the source release still deletes it on its next upgrade/rollback, corrupting the adopter's state. This is helm#32218. The uninstall path already guards against this via verifyOwnershipBeforeDelete (helm#31584). This extends the same principle to the shared update() delete loop, which is reached by upgrade, rollback, and install. Add an opt-in ClientUpdateOptionOwnership(releaseName). When set, the delete loop reads the live resource's release-name annotation and skips deletion when it belongs to a different release. Resources owned by the operating release, or carrying no annotation, are deleted as before. When releaseName is empty the safeguard is disabled and behavior is unchanged. Wire the option into all three Update call sites: - pkg/action/upgrade.go (releasingUpgrade) - pkg/action/rollback.go (performRollback) - pkg/action/install.go (performInstall) Compared to the stalled draft helm#32257 (upgrade-only), this also covers rollback and install, and checks only release-name (not namespace) to avoid edge-case false skips across namespaces. Export ReleaseNameAnnotation / ReleaseNamespaceAnnotation from pkg/kube so pkg/action can reuse the constants instead of duplicating them. Verified on a k3s cluster with a cross-release transfer scenario: after release B adopts a resource from A via --take-ownership, upgrading A no longer deletes it. The unmodified build deletes it. A bidirectional swap (A->B and B->A via upgrade) keeps both resources alive with correct ownership on the fixed build; the unmodified build loses one. Regular upgrades that remove a release's own resources still delete them. Signed-off-by: silence-coding <32766901+silence-coding@users.noreply.github.com>
silence-coding
added a commit
to silence-coding/helm
that referenced
this pull request
Oct 21, 2026
The delete phase of Update (pkg/kube/client.go) is annotation-blind: a resource present in the original release but absent from the target is deleted without consulting meta.helm.sh/release-name. When a resource has been adopted by another release (via --take-ownership), the source release still deletes it on its next upgrade/rollback, corrupting the adopter's state. This is helm#32218. The uninstall path already guards against this via verifyOwnershipBeforeDelete (helm#31584). This extends the same principle to the shared update() delete loop, which is reached by upgrade, rollback, and install. Add an opt-in ClientUpdateOptionOwnership(releaseName). When set, the delete loop reads the live resource's release-name annotation and skips deletion when it belongs to a different release. Resources owned by the operating release, or carrying no annotation, are deleted as before. When releaseName is empty the safeguard is disabled and behavior is unchanged. Wire the option into all three Update call sites: - pkg/action/upgrade.go (releasingUpgrade) - pkg/action/rollback.go (performRollback) - pkg/action/install.go (performInstall) Compared to the stalled draft helm#32257 (upgrade-only), this also covers rollback and install, and checks only release-name (not namespace) to avoid edge-case false skips across namespaces. Verified on a k3s cluster with a cross-release transfer scenario: after release B adopts a resource from A via --take-ownership, upgrading A no longer deletes it. The unmodified build deletes it. A bidirectional swap (A->B and B->A via upgrade) keeps both resources alive with correct ownership on the fixed build; the unmodified build loses one. Regular upgrades that remove a release's own resources still delete them. Signed-off-by: silence-coding <32766901+silence-coding@users.noreply.github.com>
silence-coding
added a commit
to silence-coding/helm
that referenced
this pull request
Oct 21, 2026
The delete phase of Update (pkg/kube/client.go) is annotation-blind: a resource present in the original release but absent from the target is deleted without consulting meta.helm.sh/release-name. When a resource has been adopted by another release (via --take-ownership), the source release still deletes it on its next upgrade/rollback, corrupting the adopter's state. This is helm#32218. The uninstall path already guards against this via verifyOwnershipBeforeDelete (helm#31584). This extends the same principle to the shared update() delete loop, which is reached by upgrade, rollback, and install. Add an opt-in ClientUpdateOptionOwnership(releaseName). When set, the delete loop reads the live resource's release-name annotation and skips deletion when it belongs to a different release. Resources owned by the operating release, or carrying no annotation, are deleted as before. When releaseName is empty the safeguard is disabled and behavior is unchanged. Wire the option into all three Update call sites: - pkg/action/upgrade.go (releasingUpgrade) - pkg/action/rollback.go (performRollback) - pkg/action/install.go (performInstall) Compared to the stalled draft helm#32257 (upgrade-only), this also covers rollback and install, and checks only release-name (not namespace) to avoid edge-case false skips across namespaces. Verified on a k3s cluster with a cross-release transfer scenario: after release B adopts a resource from A via --take-ownership, upgrading A no longer deletes it. The unmodified build deletes it. A bidirectional swap (A->B and B->A via upgrade) keeps both resources alive with correct ownership on the fixed build; the unmodified build loses one. Regular upgrades that remove a release's own resources still delete them. Signed-off-by: silence-coding <32766901+silence-coding@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
This PR adds an ownership-aware safeguard to Helm’s Kubernetes update/delete flow during helm upgrade, preventing deletion of orphaned resources when they are annotated as belonging to a different Helm release.
Fixes #32218