Skip to content

crd-install hook is not working on upgrade #4259 #4697

Closed

Description

@maver1ck

This is follow up for: #4259

Upgrade of cert-manager chart from version 0.4.1 to 0.5.0 added crd-install hook to CRD resources
helm/charts@e0505bb

Unfortunately running helm upgrade on this chart actually removes all crd and not upgrading them.

Output of helm version:

Client: &version.Version{SemVer:"v2.10.0", GitCommit:"9ad53aac42165a5fadc6c87be0dea6b115f93090", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.10.0", GitCommit:"9ad53aac42165a5fadc6c87be0dea6b115f93090", GitTreeState:"clean"}

Output of kubectl version:

Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.1", GitCommit:"b1b29978270dc22fecc592ac55d903350454310a", GitTreeState:"clean", BuildDate:"2018-07-17T18:53:20Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.6", GitCommit:"a21fdbd78dde8f5447f5f6c331f7eb6f80bd684e", GitTreeState:"clean", BuildDate:"2018-07-26T10:04:08Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

Cloud Provider/Platform (AKS, GKE, Minikube etc.):
Kops

Activity

  1. mmerrill3 commented on Sep 26, 2018

    @mmerrill3

    I too had this issue, referenced here #4704. I didn't see this until now.

  2. desaintmartin commented on Oct 4, 2018

    @desaintmartin

    Same with Helm v2.11.0

    Deleting and reinstall the chart works (beware of existing CRDs, you may have to use --replace).

  3. munnerz commented on Oct 5, 2018

    @munnerz
    Contributor

    Copied from #4740...


    As per #4259 (comment)

    It appears that adding the crd-install annotation retrospectively to a chart will cause the CRD to be deleted and then re-created, or in some cases, causes it to be attempted to be created when it already exists.

    I am not too certain on the details of how this bug behaves/manifests, but it's become a fairly critical issue for cert-manager users upgrading to v0.5.0 (which includes this annotations) from v0.4.x (which does not).

    I've seen reports of users that have had all their custom resources for our CRDs deleted, and other repos that have gotten Helm into a 'broken' state whereby they constantly get an AlreadyExists error.

    This may well be two separate bugs, but we have only begun to see issues since adding the crd-install annotation.

    We do not currently have e2e upgrade tests for the chart, hence why this has slipped through our automated testing.

    It'd be great to open some discussion on this, and aggregate conversation here to see if others are seeing similar problems!

  4. munnerz commented on Oct 5, 2018

    @munnerz
    Contributor

    From my understanding/observation, this is not a support issue and is in fact a bug. Labelling as such 😄

    /kind bug

    /cc @technosophos @bacongobbler

    EDIT: no prow bot automation 😢

  5. added
    bug
    and removed on Oct 18, 2018
  6. added this to the 2.11.1 - Bugfix milestone on Oct 18, 2018
  7. mortent commented on Oct 22, 2018

    @mortent

    So I think there are multiple issues here.

    First, the crd-install hook only runs on install and it does a create op without checking if the crd already exists. This is the same behavior as for other hooks. But this will cause the create operation to fail if the crd already exist. It might be possible to work around this by using the before-hook-creation deletion policy, but that doesn't sound like a good approach since it would delete all resources based on the crd.

    This also means that crds are not created (or updated) as part of updating a release, so changing an existing chart to use the crd-install hook will probably not work as expected.

    Both of these issues seems to be pretty well covered in the PR that introduced the crd-install hook #3982

    Also, transitioning a chart that is already installing crds in the normal way (without hooks) to use the crd-install hook has some pitfalls. If crds are created in the normal way, they will be managed by helm as part of the release, but with the crd-install hook that is no longer the case. So as part of an upgrade where the chart switches to create crds with the crd-install hook, the existing crds in the release will be deleted by helm. And since it is an upgrade, helm will not execute the crd-install hook (an even if it did, this would happen before the delete step).

    For any use case where helm does not create custom resources as part of the chart, the best option is probably to install crds with regular templates instead of using the crd-install hook. The hook would only be required where the chart need tthe crd to be installed before validation and creation of other resources.

  8. sdake commented on Nov 9, 2018

    @sdake

    Istio also impacted by this issue - and it is critical/blocking Istio 1.1 and 1.0.4. See istio/istio#9604 (comment).

  9. removed this from the 2.12.0 - Features milestone on Nov 10, 2018
  10. Stono commented on Nov 11, 2018

    @Stono

    Hey,
    I think it's important that whatever solution is found for this problem that the upmost is done to ensure an upgrade path for people who have either applied crd's manually, or used the install hook.

    They can't go deleting these CRDs to get helm to track them because then they'll loose the implementations too.

    The only approach I could see would be to have helm do a "create if missing, track if exists" style operation, that way it wouldn't require the pre-delete of the manifest.

  11. 4 remaining items

  12. kfox1111 commented on Dec 12, 2018

    @kfox1111
  13. abhishek-jaisingh commented on Mar 1, 2019

    @abhishek-jaisingh

    Any updates on this?

  14. woodcockjosh commented on Aug 6, 2019

    @woodcockjosh

    yo! still broken? so broken :-(. When release?

  15. monotek commented on Aug 6, 2019

    @monotek

    Try helm 2.14.3. They had some crd fixes...

  16. woodcockjosh commented on Aug 6, 2019

    @woodcockjosh

    Yeah just saw it. All the chart owners still have to re-add the CRD's to main helm charts. Epic fail. https://github.com/helm/helm/releases/tag/v2.14.3

  17. benbuzbee commented on Aug 7, 2019

    @benbuzbee

    It seems @mortent has a very good grasp on the issues here, but the upshot seems to be it is impossible to add a CRD to a chart along with a CR that consumes it without breaking the upgrade path.

    What is the recommendation? How can users upgrade a chart that has added a CRD/CR? Do they have no choice but to delete and re-install? That path breaks sane rolling-updates.

  18. woodcockjosh commented on Aug 7, 2019

    @woodcockjosh

    Upgrades should obviously ignore CRD's

  19. woodcockjosh commented on Aug 7, 2019

    @woodcockjosh

    @benbuzbee what I mean is that CRDs that already exist should just be ignored on updates. Helm should be able to determine whether or not a CRD exists. Any new CRDs should obviously be added.

  20. benbuzbee commented on Aug 7, 2019

    @benbuzbee

    I interpreted what @mortent said as "crd-install is required for charts that also install the custom-resource that requires the crd"

    And also "crd-install is ignored on upgrades"
    Seems to be true, crd-install is run here, before pre-install hooks

    // crd-install hooks

    But not here, during upgrade

    // pre-upgrade hooks

    The combination of those two facts leaves me puzzled as to how to upgrade a chart that has added a CRD + a custom resource that requires the CRD.

  21. mortent commented on Aug 9, 2019

    @mortent

    It's been a while since I was looking at this, but I think the best suggestion is to avoid mixing CRDs and CRs in the same chart. This allows CRDs to be installed without using the crd-install hook which should make it easier to update the CRD. Note that updating CRDs must be done very carefully as there are many ways to break existing CRs/controllers when updating a CRD. This is not specific to Helm. Also, a CRD is a global resource in the K8s cluster, so any changes will affect everyone in the cluster and should probably be a cluster-admin type of change.

    What is the use case for including both CRs and CRDs in the same chart? Operators are a commonly used patterns for CRDs and for these I think it makes the most sense to split the CRD and the CR.

  22. moduspwnens commented on Aug 9, 2019

    @moduspwnens
    Contributor

    We're currently building an application that makes use of Metacontroller. To configure it with a new "controller" to send events to, you create an instance of a resource defined by their CRDs (e.g. DecoratorController, CompositeController), and our application has many instances of those resources. We're wanting to distribute our app as a single chart to end users without them having to know or care what Metacontroller is.

    I don't know how common such a use case is, but we're conceptually just wanting to use another chart-based application (which defines CRDs) as a component of our own chart-based application. I expect that use case to become more common over time.

    We are working around this currently by just not creating any resources of CRDs in our chart directly via Helm, but using a Helm-created Kubernetes Job that essentially just uses kubectl to create/update them, or delete ones that the job would have created in previous versions, but don't exist any more. The upside is that we still get creates / updates / deletes as part of the Helm chart, but we're effectively managing our own process for it that Helm is triggering.

  23. benbuzbee commented on Aug 9, 2019

    @benbuzbee

    Our use case is similar - we are using helm mostly as an internal product release manager, and we need to create a custom operator that we then use. Adding multiple charts just for this case would be a bit round-about.

    Doing some looking, it seems even the canonical operator example, prometheus, does this. The chart can be configured with

    prometheusOperator.enabled: true
    prometheusOperator.createCustomResource: true
    prometheus.enabled: true
    

    Which will try to create a crd
    https://github.com/helm/charts/blob/7adf7372236b1327daf9483ba76397f2e0b23018/stable/prometheus-operator/templates/prometheus-operator/crd-prometheusrules.yaml#L4

    and also consume it
    https://github.com/helm/charts/blob/7adf7372236b1327daf9483ba76397f2e0b23018/stable/prometheus-operator/templates/prometheus/prometheus.yaml#L3

    They are using the crd-install hook so it probably works, but if they had added this in an upgrade it would have failed.

    It seem strange to me to have a case that users could achieve manually relatively easily, but that requires such workarounds in helm.

  24. bacongobbler commented on Aug 9, 2019

    @bacongobbler
    Member

    related discussion about CRDs and how they are managed in Helm: #5871

  25. bacongobbler commented on May 14, 2020

    @bacongobbler
    Member

    closing as inactive.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions