Skip to content

Allow patching/updating CRD resources after first install #7735

Closed

Description

@munnerz

Helm's support for CRD resources over the years has evolved alongside CRDs themselves.

cert-manager has, since its founding, used Helm to ship and allow users to deploy our project.

Previously (back in the days of cert-manager v0.4), we included CRDs as part of our Helm chart to make the installation experience easier for users. Around this time, the crd-install annotation was first introduced. This annotation was intended to ensure that CRDs were:

  • Installed before any other resource
  • Waiting until they were 'ready' before proceeding to install any other resource

This made it possible to include a CRD in your chart, as well as an instance of that CRD within the same chart (e.g. cert-manager defines a 'Certificate' CRD, and also installs a 'Certificate' resource in one chart).

We started making use of this new annotation in our v0.5 release. The 'side effect' we were not expecting at the time resulted in Helm assuming the CRD resource had been removed from the chart due to it moving from the regular phase of installation to the "before everything else phase". This was less than ideal for users, and caused a lot of pain.

Fast forward to now, and the 'state of the world' since #6243 merged means that the recommendation for CRDs in Helm is to include them in the crds/ subdirectory of a chart with the crd-install annotation included. This has the side effect that CRDs will not be upgraded any more if changes are made in a later release.

The justification for this is clearly documented in the above linked PR, however, I believe it is incorrect.

Updating CRD resources is absolutely something that needs to be supported in order to support the evolving nature of APIs. These are absolutely possible to apply in a safe way, without deleting and recreating all CRD resources.

The only time this is not a trivial operation is if a backwards incompatible change is made to the CRD, this includes:

  • Making a backward incompatible schema change (i.e. changing the type of a field from say, int to string)
  • Removing an API version without allowing a proper deprecation period

It is up to the author of the chart/CRD to follow these guidelines and best practices, and not so much the concern of the deployment tool. At most, Helm could/should 'check' these two conditions above and warn the user of the change it is about to apply. In lieu of that, the CRD author should document that they are making a breaking change (similar to if a chart author were to change the deployment.spec.selector field, which is immutable and therefore cannot be done without additional intervention).

In terms of how to handle multiple charts defining the same CRD resources, this is in my opinion something that should not be supported in Helm. Installing a CRD is the same thing as defining a new set of REST endpoints in the apiserver, and is a particularly sensitive operation. Only one chart, and one author, should own a CRD. Other charts that depend on this API group/version existing should implement their own checks for APIs (assuming Helm exposes this as a templating function) or otherwise clearly document their use of whatever APIs (in the same way that if a user wanted to consume 'Deployments v2', they would need to check to make sure the Kubernetes version being installed to actually defines this API group/resource.

I'm opening this to see if we can change the assumptions that Helm has made around CRDs, as this would allow cert-manager to start including our own CRD resources as part of our Helm chart once again (instead of requiring users to manually apply changes to their CRDs ahead of running helm upgrade).

Activity

  1. munnerz commented on Mar 5, 2020

    @munnerz
    ContributorAuthor
  2. monotek commented on Mar 7, 2020

    @monotek

    I'd like to see this changed too.

    As we run a "helm only" approach and don't want to use kubectl to add resources to our clusters we're currently using a second helm chart to install the cert-manager crds beforehand the cert-manager chart to workaround the issue.

  3. munnerz commented on Mar 30, 2020

    @munnerz
    ContributorAuthor

    What's the best way to get this surfaced/raised to the wider Helm community/team?

    There's more and more places/people that are running into issues deploying our controller apps due to us having to ship separate CRD manifests (see above! 😅) (i.e. they try and deploy into an alternate namespace, which requires manual edits to these CRDs). The majority of our users want a Helm chart, but these limitations are becoming really painful and the cause of one of our largest sources of user pain around deployment - I'd hate to have to cause even more pain for users by dropping Helm support 😞

  4. hickeyma commented on Mar 30, 2020

    @hickeyma
    Contributor

    Hey @munnerz. Would you like to pitch the proposal at Thursdays dev meeting: 9:30-10:00AM Pacific (https://zoom.us/j/696660622)?

  5. technosophos commented on Apr 21, 2020

    @technosophos
    Member

    This is why we will not change the behavior:

    The only time this is not a trivial operation is if a backwards incompatible change is made to the CRD

    CRD authors can unintentionally cause massive harm to a cluster by being careless. Until Kubernetes provides a better solution that can guard against this, Helm will take a defensive stance on CRDs. Unless you have a proposal that fixes that particular problem, we can't change the behavior without exposing users to high risks.

  6. monotek commented on Apr 21, 2020

    @monotek

    This is why we will not change the behavior:

    The only time this is not a trivial operation is if a backwards incompatible change is made to the CRD

    CRD authors can unintentionally cause massive harm to a cluster by being careless. Until Kubernetes provides a better solution that can guard against this, Helm will take a defensive stance on CRDs. Unless you have a proposal that fixes that particular problem, we can't change the behavior without exposing users to high risks.

    If you have a breaking change in your CRD the helm chart major version should have changed too, indicating that there is somethin breaking if you just do the update without reading the docs.

    At the moment this can already happen for non crd changes to a helm chart so i don't realy see why this is a reason to not support crd updates?
    Otherwise you should not support updates at all, or not?

  7. deads2k commented on Apr 22, 2020

    @deads2k

    API evolution for kubernetes APIs allows for several kinds of updates. Most notably, adding new fields is explicitly allowed as long as those fields are optional and their absence doesn't change the semantic meaning of the API resource.

    We (apimachinery) are considering how to handle recommendations for things like new defaults, but schema evolution right now is the standard way we handle it. Just one example last release in kube, we added a signerName to CSRs inside of v1beta1.

    Another point is that to even to handle API changes within different versions, it is necessary to add fields to previous versions to ensure that loss-less conversions are possible. Structurally preventing the evolution of schemas within one version effectively prevents that evolution in any version. An inability to evolve an API greatly diminishes the value of a feature that installs it.

    I think a more nuanced approach for installation makes sense. I don't think that kube CRDs will ever prevent incompatible changes because doing so at an API level eliminates options for development and iteration and no kube resource has ever supported modal validation. However, it seems fully possible for helm to either allow an "I know what I'm doing, allow me to evolve my schema" indicator or if you wish, you could build a more complicated allowed evolution detector. I recommend just an opt-in, let me make the changes that must be made.

    API compatibility here: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api_changes.md#on-compatibility

  8. TBBle commented on Apr 23, 2020

    @TBBle
    Contributor

    This is another instance of #5871. In my comment there I proposed a way for Helm to check the backwards compatibility of CRDs and give the user tools to deal with it within Helm.

    @munnerz would that flow be sufficient to address your concerns so we could have the CRDs for cert-manager inside the crds/ directory, and get the same behaviour of the current "use kubectl first" installation flow?

  9. omkensey commented on May 2, 2020

    @omkensey

    If you have a breaking change in your CRD the helm chart major version should have changed too, indicating that there is somethin breaking if you just do the update without reading the docs.

    True, and in a world where everybody rigorously adopted and respected (or even knew about) SemVer, this would be much less of an issue. But plenty of software vendors don't know or don't care -- their Helm chart versions may mean what they say it means, not what SemVer says it should say it means.

    At the moment this can already happen for non crd changes to a helm chart so i don't realy see why this is a reason to not support crd updates?
    Otherwise you should not support updates at all, or not?

    The difference is, as noted in some other issues discussing this, blast radius. A change to a Helm release is going to be known to a seasoned operator to have a risk of going wrong in that release. Things go wrong and it's understood that you might break your release when things change, so put on your protective helmet and make sure the backups are fresh. But when a CRD update/delete goes wrong, it can ruin the day of everybody running (or using) software in that cluster, with results ranging from "my app doesn't work and I have to wait till it gets fixed to work again" to "all my app's data is gone".

  10. monotek commented on May 4, 2020

    @monotek

    Imho backups are exactly for this "all data is gone" scenario if you did not test a chart update in your qa or staging environment first.

    I also think that helm should not try to protect people from badly maintained helm charts which are not respecting semver.

  11. bacongobbler commented on May 4, 2020

    @bacongobbler
    Member

    I strongly disagree that we should introduce such a dangerous feature to a tool because "everyone should have backups". That's a really poor argument to stand on. An entire cluster should not be brought down because someone rolled back to an older version of the application, updating a CRD (and therefore deleting all the CRs in the cluster).

    Thank you for your thoughts on this one @deads2k. Schema evolution is an interesting take.

    @TBBle is right though. This is a duplicate of the same discussion going on in #5871. To keep discussions happening in one place, I'm going ahead and closing this as a duplicate. Please feel free to continue the discussion there.

  12. monotek commented on May 5, 2020

    @monotek

    Thats not exactly what i said. Even if "having backups" and "testing updates" should not be something we need to have an argument about.

    I also don't think "An entire cluster brought down" will apply for most helm / crd updates.

    Again, my point is that information about such changes should be reponsibility of the chart maintainer and not be prevented by helm itself.

    If helm ist "The package manager for Kubernetes" it should be possible to update packages. If you compare it to APT or RPM such packages could destroy your system too if used wrong. I guess nobody would blame APT or RPM if the package contains some broken rm -rf. So i still don't see why Helm should prevent proper usage?

  13. ldemailly commented on Jul 7, 2021

    @ldemailly

    Not applying new crd objects when a chart version change, having to do silly things like

    kubectl get secrets -n istio-system | \
       grep "sh.helm.release.v1.istio-base" | \
       awk '{print $1}'| xargs kubectl delete secret -n istio-system

    just because helm update doesn't bother applying the yaml in the chart is a terrible user experience (and leaves clusters in broken state with missing crds)

    how can this be closed as "ok"?

    or please let me know at least what flag I am missing to force update a chart

  14. technotaff-nbs commented on Jan 27, 2022

    @technotaff-nbs

    Not applying new crd objects when a chart version change, having to do silly things like

    kubectl get secrets -n istio-system | \
       grep "sh.helm.release.v1.istio-base" | \
       awk '{print $1}'| xargs kubectl delete secret -n istio-system

    just because helm update doesn't bother applying the yaml in the chart is a terrible user experience (and leaves clusters in broken state with missing crds)

    how can this be closed as "ok"?

    or please let me know at least what flag I am missing to force update a chart

    Yes please provide a flag to for upgrade of CRDs!

  15. onedr0p commented on May 10, 2022

    @onedr0p

    @hickeyma or any other maintainer, can this issue be re-opened and considered for re-evaluation?

    It seems like the maintainers are aware of this issue but keep this issue closed:

    https://helm.sh/docs/chart_best_practices/custom_resource_definitions/#some-caveats-and-explanations

    I guess this issue supersedes this one. #10585

  16. thomasmckay commented on Mar 31, 2023

    @thomasmckay

    Is there a way to accomplish forcing replacement of CRDs?

  17. TBBle commented on Mar 31, 2023

    @TBBle
    Contributor

    Not within Helm itself, no. See https://github.com/helm/community/blob/main/hips/hip-0011.md for the full rationale why not.

    You should be able to use helm show crds to extract CRDs from a chart, and then manually inspect and apply them to your cluster with whatever data-migration and data-loss/data-corruption prevention steps you feel are necessary.

  18. monotek commented on Apr 3, 2023

    @monotek

    Not sure how you deploy your workloads but tools like FluxCD allow you to do that by using "CreateReplace" setting for CRDs.

    https://fluxcd.io/flux/components/helm/helmreleases/#crds

  19. dayeguilaiye commented on Aug 10, 2023

    @dayeguilaiye
    Contributor

    I understand that prevent users from losing all crs. But I don't understand why can't we provide a setting or flag to allow users update CRDs? And can set false as default, which means if user open that flag, they already know what it may cause.

    As a tool, I don't think it should completely prohibit from do anything especially when they totally understand what they are doing. "rm / -rf" eg.

  20. ldemailly commented on Aug 10, 2023

    @ldemailly

    In https://github.com/helm/community/blob/main/hips/hip-0011.md

    There are widely documented patterns and work-arounds for how to handle CRD

    yet... not really no... or at least I don't know how to update CRDs with helm without the hack of removing the secret (the state)

  21. TBBle commented on Aug 11, 2023

    @TBBle
    Contributor

    That line is followed by four such documented patterns and work-arounds. The first one is more for chart creators to worry about, but the last one is similar to how I've done it in the past: Extract the CRDs into YAML using helm show crds, and inspect, diff, loss-check against existing resources for those CRDs, and apply the CRDs (or email the CRDs to the cluster admin if that's not me, and they can do all that) before upgrading the chart to the version that needs the new CRDs.

  22. kvaps commented on Aug 21, 2023

    @kvaps
  23. DanielCastronovo commented on Sep 20, 2024

    @DanielCastronovo

    Any progress on this issue ?

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