WIP: helm upgrade: check ownership for deletion case#32257
Open
cg49996w11 wants to merge 1 commit into
Open
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 | ||
| } | ||
| } |
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