Skip to content

proposal: handle immutable resources on update #7082

Open

Description

@dastrobu

Steps to reproduce the issue:

helm create tmp
echo '
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
    name: {{ include "tmp.fullname" $ }}
roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: ClusterRole
    name: {{ .Values.role }}
subjects: []
' > tmp/templates/rolebinding.yaml
helm install tmp tmp --set role=view
helm upgrade --force tmp tmp --set role=edit

This fails with

Error: UPGRADE FAILED: failed to replace object: RoleBinding.rbac.authorization.k8s.io "tmp" is invalid: roleRef: Invalid value: rbac.RoleRef{APIGroup:"rbac.authorization.k8s.io", Kind:"ClusterRole", Name:"edit"}: cannot change roleRef

The expected result would be that helm replaces the role binding due to the --force flag.
The problem was already discussed in #6468 but it was mentioned that --force should work, so I am reporting this as new issue.

Output of helm version:
version.BuildInfo{Version:"v3.0.0", GitCommit:"e29ce2a54e96cd02ccfce88bee4f58bb6e2a28b6", GitTreeState:"clean", GoVersion:"go1.13.4"}
Output of kubectl version:
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.4", GitCommit:"a87e9a978f65a8303aa9467537aa59c18122cbf9", GitTreeState:"clean", BuildDate:"2019-07-08T08:51:16Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-16T01:01:59Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
Cloud Provider/Platform (AKS, GKE, Minikube etc.):

kind (and Openshift)

Activity

  1. zwwhdls commented on Nov 27, 2019

    @zwwhdls
    Contributor

    Hi,

    I have tried for this. And I found in code here: https://github.com/helm/helm/blob/master/pkg/kube/client.go#L393. It means that when "--force" exits, attempt to call apiserver for PUT resource api. Besides, when "--force" doesn't exits, attempt to call apiserver for PATCH resource api.

    When I tried the PUT api to change role to "edit" in your yaml, I got the same error:
    image

    I guess this field in rolebinding can't be changed in k8s side. So, I think it's the wrong way to change roleRef and Helm did the right thing.

  2. bacongobbler commented on Nov 28, 2019

    @bacongobbler
    Member

    Helm 2 used to delete and re-install the resource on a PATCH failure, which led to a lot of cases where things like spurious client timeouts causing the patch to fail would delete the resource... Not exactly what you'd call a great experience.

    In Helm 3, the behaviour of --force was refactored to better align with its intent: to force a PUT operation (an overwrite) when the user requests. This allows the user to bypass the three-way merge patch strategy, forcing idempotency and overwriting the object currently maintained by Helm in the cluster.

    If there are certain objects that cannot be replaced, we can look up the expected behaviour from Kubernetes' side of things. In this particular case, certain fields present in a role binding cannot be changed/replaced once they've been created as @zwwhdls rightly pointed out. So this seems intentional from Kubernetes' point of view. If you want to modify the role binding, my suggestion would be to delete it from the cluster first before upgrading.

    Hope this helps!

  3. dastrobu commented on Dec 2, 2019

    @dastrobu
    ContributorAuthor

    @bacongobbler thanks for explaining this difference between Helm 2 and Helm 3. I agree that the way Helm 3 works with --force updates is very good for most use cases, since no unnecessary recreation of resources happens, which could cause trouble.
    However, I assume that it will be problematic for some resources, that no --force update is possible anymore without manual intervention. So I would suggests to extend helms behavior on --force updates with a fallback to delete and create, when it receives a 422 response on the PUT request. This would then still not cause any unnecessary re-creations but would still make sure all resources can be update via Helm --force.

    To illustrate, why I think this would be important, I would like to explain a little more detail why updating a roleRef is a standard use case.
    When developing a chart with a deployment that requires a service account with certain permissions, I usually create three objects in the template (ServiceAccount, Role, RoleBinding):

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: {{ include "my-chart.fullname" . }}
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: {{ include "my-chart.fullname" . }}
    rules:
      - verbs
          - get
      # ...
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: {{ include "my-chart.fullname" . }}
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: {{ include "my-chart.fullname" . }}
    subjects:
      - kind: ServiceAccount
        name: {{ include "my-chart.fullname" . }}
        namespace: {{ .Release.Namespace }}
    

    So if someone likes to change the "my-chart.fullname" on update providing e.g. a fullnameOverride this will cause changing the roleRef.
    I would assume that there are more Kubernetes objects, where the change from delete/create to update (PUT) will cause some surprises, so I would be interested what you @zwwhdls and @bacongobbler think about a fallback to delete/create on update failure (422)?

  4. bacongobbler commented on Dec 2, 2019

    @bacongobbler
    Member

    it might be worth considering a new feature flag that forces a deletion of the object on an upgrade. Something like --recreate, perhaps.

  5. dastrobu commented on Dec 4, 2019

    @dastrobu
    ContributorAuthor

    Certainly one could keep the "recreate" strategy separated from the force flag and let the user decide.
    I could think of adding a recreate flag in the flowing alternative ways:

    1. --recreate always does a delete and create and thus is an alternative to the standard upgrade (PATCH) and the --force upgrade (PUT).
    2. --recreate implies --force and tries PUT first and does a recreate on failure.
    3. --recreate tries PATCH or PUT (if --force was specified as well) and does a recreate on failure.

    I would propose option 3, since it is the most flexible one and gives the user most control. Option 1. does not seem to make sense, since I cannot imagine a case where deletion of non conflicting resources would pre preferable (in this case one could just delete the entire release and re-install it).

    For option 2 and 3 it needs to be decided, if recreation should be attempted only on status 422 or if there are other status codes, where the recreate attempt makes sense.

    I would like to hear your thoughts and if the maintainers like the idea of adding a recreate fallback strategy I can try to find time for proposing a PR.

  6. tatchiuleung commented on Dec 5, 2019

    @tatchiuleung

    Option 3 gives us greatest flexibility but I think user already understands why --recreate is needed in the first place, thus I believe option 2 covers most scenarios.

  7. changed the title [-]helm upgrade --force fails on changing roleRef.[/-] [+]proposal: `helm install/upgrade --recreate`[/+] on Dec 6, 2019
  8. bacongobbler commented on Dec 6, 2019

    @bacongobbler
    Member

    re-labeled and re-titled the issue to reflect the ask.

  9. bacongobbler commented on Dec 13, 2019

    @bacongobbler
    Member

    I think option 1 should be implemented. There may be cases where someone wants to recreate every object similar to how --recreate-pods worked in Helm 2. Less ambiguity between feature flags is always better for the end user, anyways.

  10. dastrobu commented on Dec 16, 2019

    @dastrobu
    ContributorAuthor

    @bacongobbler least ambiguity of flags is certainly preferable. But option 1 would resemble the behaviour of helm delete followed by helm install. So option 1 would not add a real new feature. To me option 3 would be least unambiguous. However, one might chose a different name than --recreate, maybe something like helm upgrade --immutable.

  11. bacongobbler commented on Dec 16, 2019

    @bacongobbler
    Member

    To me option 3 would be least unambiguous.

    I'm concerned about the approach of "if A fails, then B". This was the trap we fell into with Helm 2's old --force behaviour: it deleted the resource and re-created it only if the patch failed. Many users were confused about the ambiguity of the flag's implementation. On their end, sometimes the behaviour was triggered, and sometimes it didn't. This caused the deletion and recreation behaviour to be inconsistent, and in many cases disrupting application traffic. Many users became wary of the flag because of its reliance on a PATCH operation's failure. While you and I may understand the behaviour, it's difficult to convey to others how the internals of Helm works at a broad level.

    This is why I believe making the behaviour more explicit is desired: it's a destructive action, and there's no ambiguity.

    But option 1 would resemble the behaviour of helm delete followed by helm install. So option 1 would not add a real new feature.

    I'd argue the opposite here: users have been asking for a feature flag that performs the same behaviour as helm delete --keep-history && helm install --replace. A "one-stop shop" for CI/CD workflows. That's why flags like helm upgrade --install --dependency-update exist today. :)

  12. changed the title [-]proposal: `helm install/upgrade --recreate`[/-] [+]proposal: `helm upgrade --recreate`[/+] on Dec 16, 2019
  13. 79 remaining items

  14. ericblackburn commented on Mar 4, 2026

    @ericblackburn

    remove stale

  15. antonakv commented on Mar 4, 2026

    @antonakv

    Update can be handled with recreate. It's the best.

  16. antonakv commented on Mar 4, 2026

    @antonakv

    Explicit resource planning is better than standard immutable k8s approach. Plan - destroy - create - apply. K8S architects way of doing this is raising eybrows.

  17. silence-coding commented on Mar 11, 2026

    @silence-coding

    Could the community owner pay special attention to this issue? Unresolvable conflicts are inevitable for projects that have been running for a long time.

  18. github-actions commented on Jun 10, 2026

    @github-actions

    This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

  19. lucasfcnunes commented on Jun 10, 2026

    @lucasfcnunes

    Not stale.

  20. github-actions commented on Sep 10, 2026

    @github-actions

    This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

  21. antonakv commented on Sep 10, 2026

    @antonakv

    Not stale

  22. antonakv commented on Sep 10, 2026

    @antonakv

    Helm 4 design is finally correct. Focused on modernizing the underlying architecture, it added WebAssembly (Wasm) support for plugins, native Kubernetes Server-Side Apply, and content-based caching while maintaining backward compatibility for existing charts.
    Although instead of doing good software a lot of engineers are conducting resarch/investigations using code repositories in a quite weird way. It's all not necessary at all with correct planning and prediction of what will be going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions