Skip to content

feat(helm): add new update-policy annotation to recreate resources - #9174

Closed
dastrobu wants to merge 1 commit into
helm:mainfrom
dastrobu:#7082/delete-policy-annotation
Closed

dastrobu wants to merge 1 commit into
helm:mainfrom
dastrobu:#7082/delete-policy-annotation

Conversation

@dastrobu

@dastrobu dastrobu commented Dec 28, 2020 •

Copy link
Copy Markdown
Contributor

Add annotation handling of new annotation helm.sh/update-policy with values recreate-on-conflict and recreate-on-invalid values to better deal with the following cases.
The server responds with 'invalid' e.g. if a certain resource contains an immutable field, which cannot be patched or updated by a PUT. In theses cases it can be helpful to delete the resource and recreate it. Examples for theses cases are:

  • roleRef in RoleBinding
  • spec.clusterIP in Service
  • parameters in StorageClass

If a chart developer has made sure that recreating a resource is safe, the annotation can be added to a resource template. Alternatively a user may add the annotation manually to an existing resource to allow Helm to recreate a certain resource.

Adding the new annotation in general by default or changing the default behaviour of Helm is not a good idea, since deletion and recreation of certain resources can lead to an unwanted or undefined state as described in detail in #7431 (comment):

"[...] selectively deleting/re-creating volume-backed resources (Secrets, Services, ConfigMaps, PVCs) without touching the Deployment. If a Persistent Volume Claim is deleted and re-created, there is a risk that an application (Deployment) consuming that Persistent Volume Claim will not receive the new volume's mount point. The same can be said for Secrets, Configmaps, Services, and other resources which are deployed and relied upon by another resource. Environment variables populated in a Deployment from a Service won't be updated until the Pods are destroyed."

Closes #7082.

Signed-off-by: Daniel Strobusch [email protected]

Special notes for your reviewer:

This is an alternative approach to #7431 as proposed in #7082 (comment).

There is a new timeout parameter introduced to Update in a backwards compatible way as UpdateWithTimeout as suggested in #9174 (comment). In Helm 4 this should be cleaned up as stated in the comments.

The update-policy and its possible values is a proposal related to the delete-policy of hooks and could be changed to something different.

If applicable:

  • this PR contains documentation
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

@helm-bot helm-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 28, 2020
@z4ce

z4ce commented Apr 27, 2023

Copy link
Copy Markdown
Contributor

Did you ever get any feedback on this? It seems like a pretty good idea to me. I wonder why the DCO check hasn't passed on this.

IMHO this PR seems preferable to #7431 should that one be closed in favor of this?

Comment thread pkg/kube/client.go Outdated
// resource updates, creations, and deletions that were attempted. These can be
// used for cleanup or other logging purposes.
func (c *Client) Update(original, target ResourceList, force bool) (*Result, error) {
func (c *Client) Update(original, target ResourceList, force bool, timeout time.Duration) (*Result, error) {

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.

As you said, this is a breaking change as written. You can work around that by doing something like this:

Suggested change
func (c *Client) Update(original, target ResourceList, force bool, timeout time.Duration) (*Result, error) {
func (c *Client) Update(original, target ResourceList, force bool) (*Result, error) {
return UpdateWithTimeout(original, target, force, time.Duration(0))
}
func (c *Client) UpdateWithTimeout(original, target ResourceList, force bool, timeout time.Duration) (*Result, error) {

Where if timeout is 0 you revert to the original behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@joejulian thanks for the suggestion. I noticed that there was a similar issue in the meantime which lead to:

type InterfaceExt interface {
	// WaitForDelete wait up to the given timeout for the specified resources to be deleted.
	WaitForDelete(resources ResourceList, timeout time.Duration) error
}

So I will follow that pattern and remove the breaking change by introducing a trait like additional interface.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@joejulian PR is cleaned up and all breaking changes have been removed as suggested. Looking forward to your feedback.

@joejulian

Copy link
Copy Markdown
Contributor

Same question:
#7431 (comment)

@dastrobu
dastrobu force-pushed the #7082/delete-policy-annotation branch 2 times, most recently from 3f64f63 to 1994290 Compare December 14, 2023 17:16
@dastrobu
dastrobu marked this pull request as draft December 14, 2023 17:58
@dastrobu
dastrobu force-pushed the #7082/delete-policy-annotation branch 5 times, most recently from d5442ec to 0ac28fc Compare December 17, 2023 13:34
Add annotation handling of new annotation helm.sh/update-policy with values recreate-on-conflict and recreate-on-invalid values to better deal with the following cases.
The server responds with 'invalid' e.g. if a certain resource contains an immutable field, which cannot be patched or updated by a PUT. In theses cases it can be helpful to delete the resource and recreate it. Examples for theses cases are:

 * roleRef in RoleBinding
 * spec.clusterIP in Service
 * parameters in StorageClass

If a chart developer has made sure that recreating a resource is safe, the annotation can be added to a resource template. Alternatively a user may add the annotation manually to an existing resource to allow Helm to recreate a certain resource.

Adding the new annotation in general by default or changing the default behaviour of Helm is not a good idea, since deletion and recreation of certain resources can lead to an unwanted or undefined state as described in detail in helm#7431 (comment):

"[...] selectively deleting/re-creating volume-backed resources (Secrets, Services, ConfigMaps, PVCs) without touching the Deployment. If a Persistent Volume Claim is deleted and re-created, there is a risk that an application (Deployment) consuming that Persistent Volume Claim will not receive the new volume's mount point. The same can be said for Secrets, Configmaps, Services, and other resources which are deployed and relied upon by another resource. Environment variables populated in a Deployment from a Service won't be updated until the Pods are destroyed."

Closes helm#7082.

Signed-off-by: Daniel Strobusch <[email protected]>
@dastrobu
dastrobu force-pushed the #7082/delete-policy-annotation branch from 0ac28fc to 0b58239 Compare December 17, 2023 13:37
@dastrobu
dastrobu marked this pull request as ready for review December 17, 2023 14:35
@dastrobu

Copy link
Copy Markdown
Contributor Author

@joejulian could you unlock #7082 to be able to comment on in again, since I am not able to comment on this issue anymore?

@scottrigby

Copy link
Copy Markdown
Member

@joejulian could you unlock #7082 to be able to comment on in again, since I am not able to comment on this issue anymore?

I unlocked that issue

@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the Stale label Aug 27, 2025
@dastrobu

Copy link
Copy Markdown
Contributor Author

remove stale

@github-actions github-actions Bot removed the Stale label Sep 4, 2025
@github-actions

github-actions Bot commented Dec 3, 2025

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the Stale label Dec 3, 2025
@pierluigilenoci

Copy link
Copy Markdown

/nostale

@github-actions github-actions Bot removed the Stale label Dec 5, 2025
@f1603849451-arch

Copy link
Copy Markdown

I’d like to ask about the current status of this feature and when it is expected to be merged.

@silence-coding

Copy link
Copy Markdown

Are there any further updates on this feature? I’ve noticed that the current forceReplace configuration is too coarse-grained and does not meet production-level requirements. In a production environment, we do not want to trigger a full delete-and-recreate process, as this could result in prolonged service downtime.

@TerryHowe

Copy link
Copy Markdown
Contributor

There are a lot of issues with this PR and then there are conflicts as well.

@dastrobu

dastrobu commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

This PR is pretty old, unless the maintainers show interest in the proposal #7082 I dont think it makes sense to spend time on this PR (rebasing, ...).

@silence-coding

Copy link
Copy Markdown

@TerryHowe Is there enough interest from the Helm maintainers/community to accept this feature?

@silence-coding

Copy link
Copy Markdown

Are there any other features that can address this issue? We can't expect users to uninstall the entire chart before proceeding, can we?

@joejulian

Copy link
Copy Markdown
Contributor

Thanks for this, and for keeping it alive as long as you did. The need is real: some resources have immutable fields, and a normal update or apply cannot get past them.

Helm 4 now covers both cases this PR set out to handle, as operator-invoked flags rather than a chart annotation:

  • --force-replace recreates resources that cannot be updated in place, which is the recreate-on-invalid / immutable-field case. (--force is now deprecated in favor of --force-replace.)
  • --force-conflicts forces server-side-apply changes against field-ownership conflicts, which covers the recreate-on-conflict case.

To be precise about server-side apply: no apply strategy can mutate a truly immutable field, so this is not SSA quietly solving it. It is that the delete-and-recreate path now has a first-class flag (--force-replace) alongside the SSA conflict override.

The one real difference from this PR is that those are flags the person running the upgrade sets, not an annotation the chart author sets, and that is deliberate. Recreating a resource is destructive and cluster-state-dependent, and whether it is safe to delete and recreate a given object (a PVC, or anything holding state) is something the operator knows at upgrade time and the chart author usually does not. Keeping that decision with the operator rather than baking it into the chart is the separation we hold elsewhere, so the flag form is the shape we want.

Given that, plus the conflicts against the Helm 4 update path (rewritten for server-side apply) and the related #7431 already being closed, I am going to close this as superseded. I genuinely appreciate the work, and it surfaced a real need that Helm 4 ended up filling.

If you think there is still a case for a targeted, per-resource, only-on-invalid recreate beyond these flags, that would be a Helm Improvement Proposal conversation rather than a reopen, since it changes the chart contract.

@joejulian joejulian closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature 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.

proposal: handle immutable resources on update

9 participants