Skip to content

WIP: helm upgrade: check ownership for deletion case#32257

Open
cg49996w11 wants to merge 1 commit into
helm:mainfrom
cg49996w11:cg49996w11-feat/check-ownership-during-upgrade
Open

WIP: helm upgrade: check ownership for deletion case#32257
cg49996w11 wants to merge 1 commit into
helm:mainfrom
cg49996w11:cg49996w11-feat/check-ownership-during-upgrade

Conversation

@cg49996w11

@cg49996w11 cg49996w11 commented Jun 22, 2026

Copy link
Copy Markdown

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

Signed-off-by: cg49996w11 <cg49996w11@gmail.com>
Copilot AI review requested due to automatic review settings June 22, 2026 19:02
@pull-request-size pull-request-size Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.Update with 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 thread pkg/kube/client.go
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 thread pkg/kube/client.go
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Helm ignores ownership during upgrade

2 participants