Skip to content

Proposal: Manage CRDs #5871

Closed
Closed

Description

@mattfarina

I have to give credit to @prydonius for this idea. I'm just writing it up here. Can do a proposal to community if this needs to move forward. Not entirely sure what is feasible yet.

The idea:

Have a crd directory alongside the templates directory. Helm would then check for missing CRDs and attempt to install them. If it cannot install them and they are missing it would stop, explain why it can't install them (e.g., permissions), and provide some details (e.g., someone with permissions needs to install the CRDs).

This is because there is common wrapper logic needed around CRDs for each of them that is about the same for this. First, check if it's installed and if it's not then have it there with the crd install hook.

One unknown is handing changes in the CRD content at the same apiVersion. This happens in practice and has many potential problems. Can we detect a change and throw an error to require human intervention?

Once this is in place the Helm dependency system can be used to handle CRDs that are dependent upon one another. Each can be in their own chart with their own controllers.

Activity

  1. added
    v3.x
    on Jun 11, 2019
  2. bacongobbler commented on Jun 11, 2019

    @bacongobbler
    Member

    I agree that there is a common wrapper logic being used for all CRDs in Helm 2 recently. Taking a closer look at how CRDs are installed and managed would and how we can improve that process would be appreciated.

    I would love to see a practical example! It seems like it's an idea worth investigating. I'm having a hard time conceptualizing this, so having a practical example to play with and understand the solution might be a good way forward to see if this is feasible or not (as well as provide feedback on the design).

  3. technosophos commented on Jun 11, 2019

    @technosophos
    Member

    As I see it, we have four major problems to sort out with CRDs:

    • Install order: CRDs have to be installed in a separate operation from any usage of (instances of) that CRD.
    • Compatibility detection: If a CRD exists, and a request to install the CRD comes in, but the api versions are different, what do we do?
    • Update process: CRDs are possibly global, while most other kinds that appear in Helm charts are not. So under what conditions can a chart that contains a CRD upgrade the CRD?
    • Deletion of a CRD: When a CRD is deleted, all of its instances are deleted. And CRDs are global. Under what conditions can Helm delete a CRD (clearly, it's not by default)

    As far as I can tell, the above makes it easier to solve the first point. But is it in any way helping or hindering with the others? I don't want to take a shot at solving just one prong, only to discover that that solution prevented us from solving the others.

    The proposal does not explain what the mechanics of the crd/ directory are. Are CRD YAML files treated as templates, too? Do they get the same context as other templates? Are they always evaluated BEFORE the others? And if so, can anything be injected from the CRD template eval into the context used for regular eval? What happens if a non-CRD is placed in the crd directory? For example, if I have a deployment that is a CRD controller, it is often necessary for that controller to be up and running before instances can be reliably processed. So do I put the controller objects in the CRD folder?

  4. mattfarina commented on Jun 11, 2019

    @mattfarina
    CollaboratorAuthor

    Just spitballing...

    Install order: CRDs have to be installed in a separate operation from any usage of (instances of) that CRD.

    The CRD directory would make it easy to figure out where they were to install them first. We would not need to parse all the templates first. This could extend to the whole dependency tree.

    Compatibility detection: If a CRD exists, and a request to install the CRD comes in, but the api versions are different, what do we do?

    This is the hard one. There is a whole page in the docs on versioning CRDs. While I'm open to suggestions, I would argue we notify the user and let them decide what to do.

    Update process: CRDs are possibly global, while most other kinds that appear in Helm charts are not. So under what conditions can a chart that contains a CRD upgrade the CRD?

    When there is a change such as a new apiVersion, change in storage/serving, etc. I would propose this is an operation that notifies the user of the coming change and asks them to accept it. A human in the loop because this could be a destructive change.

    Deletion of a CRD: When a CRD is deleted, all of its instances are deleted. And CRDs are global. Under what conditions can Helm delete a CRD (clearly, it's not by default)

    Always manual? Directions about deleting them with big flashers like we used to have on geocities for the under construction pages.

    @technosophos you raised a lot of good questions. Ones worth airing and discussing publicly.

  5. prydonius commented on Jun 12, 2019

    @prydonius
    Member

    The CRD directory would make it easy to figure out where they were to install them first. We would not need to parse all the templates first. This could extend to the whole dependency tree.

    Placing CRDs in a specific directory in the chart package gives us a more reliable way to handle them separately. For example, we could render all the CRDs in the chart and sub-charts first and then install them before installing the rest (just an example, the idea is we can use it to make the right decisions). I guess there's no reason we can't do this with the current crd-install hook, but I'm not sure what the future of hooks are in Helm 3 and I also feel like annotations aren't the best way of defining these if we have the opportunity to extend the chart format.

    Completely agree with @mattfarina's comment, Helm should not try to do anything clever in most of these scenarios, I think the goal here would be to just provide more info to the operator so that they can decide how to proceed.

  6. paulczar commented on Jun 13, 2019

    @paulczar
    Contributor

    Have a crd directory alongside the templates directory - is this necessary? We know that a CRD has the following top level items in their declaration:

    apiVersion: apiextensions.k8s.io/v1beta1
    kind: CustomResourceDefinition
    

    would it be within Helm's scope to look at the apiVersion/kind of resources and act on them based on the resource type? If we know its a CRD by the apiVersion/kind then we can treat it as a CRD, however we decide to treat them.

  7. mattfarina commented on Jun 13, 2019

    @mattfarina
    CollaboratorAuthor

    @paulczar If Helm is to read the apiVersion and kind of each object and know how to act on them it's a new level of introspection and ordering.

    So, let's say you have a CRD that needs to be installed, then a controller to work on those CRDs, and then some CRs you have a definite ordering thing. You have to know a fair amount of intent. Do we need to tell people to break these into two charts?

    Then there is the apiVersion. What we have now is a beta version and that will change. At the least is to go to GA. How do we handle this changing in the future?

  8. prydonius commented on Jun 13, 2019

    @prydonius
    Member

    Well FWIW Helm already defines the operation order per kind (https://github.com/helm/helm/blob/bed4054c412f95d140c8c98b6387f40df7f3139e/pkg/tiller/kind_sorter.go), so perhaps extracting the CRDs is not a terrible approach.

    Not sure that the apiVersion matters that much, at least for core resources we can pretty much assume the kind name won't change or clash with anything (at least from beta onwards).

  9. paulczar commented on Jun 14, 2019

    @paulczar
    Contributor

    So putting crd at the top of the sort order would be a good start. Maybe helm can then check if the crd already exists with the name and apiVersion, and if so skip it, if not install it. We could potentially do a equivalent of kubectl auth can-i create crds to validate the user has permissions to install crds, and have a friendly error.

    In a larger picture we could also check each resource kind/apiVersion in the chart against kubectl apiVersion, kubectl apiResources, kubectl get crd to validate that its doable on the cluster (maybe a set of kubectl auth can-i to validate the user is allowed to ?), if it doesn't it can error out.

  10. bacongobbler commented on Jun 14, 2019

    @bacongobbler
    Member

    So putting crd at the top of the sort order would be a good start.

    One of the problems with CRDs today stems from the fact that the CRD and its children (the CRs) are defined within the same chart. During resource validation, the CRs fail API validation because the CRD does not exist yet therefore there's no API endpoint that can accept those CRs. #2994 and @mattfarina's earlier comment summarizes the issue fairly well here.

    Throwing CRDs earlier in the sort order will not help in this situation. They need to be installed prior to validating CRs within the chart itself... Either that or tell people that CRDs and CRs need to be broken into two charts.

    However, that does bring up a good point. What if we validated and installed each resource in sort order by it's GroupVersion?

    We might be able to change the current logic in pkg/kube from

    1. render all templates as resources
    2. validate all resources together <-- where CRDs/CRs currently fail unless they were installed using the crd-install hook
    3. install resources based on sort order

    To

    1. render all templates as resources
    2. based on sort order, for each GroupVersion
      a. validate the resources
      b. install all resources with the same GroupVersion
      c. GOTO next GroupVersion

    It may be more computationally expensive, but it could solve the install order issue. Perhaps there may be issues with validating resources individually... @technosophos do you know of any limitations this approach may bring?

    If that works, that would solve the "install order" issue and remove the need for a crd directory. That doesn't solve compatibility detection, update process or the CRD deletion use cases though, and I do agree that we should discuss those issues as well. I'd hate for us to come up with a solution for one use case that doesn't help solve the other three.

    Then there is the apiVersion. What we have now is a beta version and that will change. At the least is to go to GA. How do we handle this changing in the future?

    Did we have a v1beta2 to apps/v1 migration story for the workloads API? As far as I understand, handling apiVersion migrations is out of scope for kubernetes as the behaviour between different apiVersions may differ. That being said, there have been iterations in the past where very few changes occurred (like v1beta1 to v1beta2). I'm not sure how (or if) we can handle that.

  11. mattfarina commented on Jun 14, 2019

    @mattfarina
    CollaboratorAuthor

    Detecting if a CRD is installed and installing if not present is the easy problem to solve or bike shed on. Can we look at the hard problems instead? The things that don't have easy solutions.

    For example, how do we handle updating CRDs? For example, A CRD is installed and there's an operator using it in one namespace. Now, someone is installing a second operator for the same thing in a different namespace without knowledge of the first install. The CRD for the second chart has new version information (maybe even a new storage version). Does Helm install the update? What will happen to the first operator? I think this has the potential to cause problems if I read https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definition-versioning/#writing-reading-and-updating-versioned-customresourcedefinition-objects correctly.

    Or, How do we handle charts that have CRDs, controllers, and CRs based on the CRDs. In this case the install order needs to be the CRD, the controller responding to the CRD, and then any other assets. If the controller is run as a deployment than it needs to be sort ordered after the CRD and before any other assets. How do we determine that?

    The Create step in the CRD CRUD is the easiest to solve. It's the RUD parts that are more complicated and we need proposed solutions for.

  12. bacongobbler commented on Jun 14, 2019

    @bacongobbler
    Member

    Can we look at the hard problems instead?

    Absolutely. Thank you for calling us out on that.

    For example, A CRD is installed and there's an operator using it in one namespace. Now, someone is installing a second operator for the same thing in a different namespace without knowledge of the first install. The CRD for the second chart has new version information (maybe even a new storage version). Does Helm install the update?

    Ooh, good one. Yeah, this is a semi-common use case today where two applications rely on the same CRD. It's a good case of sharing common resources between multiple apps: how do the two reconcile a shared resource without stepping on eachother's toes?

    If I'm not mistaken, this particular problem applies to all global resources including CRDs. For example, it's quite possible that two apps could create the same PersistentVolume or a similar StorageClass.

    I guess the same problem might also be considered for non-globally scoped resources as well. I've heard users ask about how two applications installed in the same namespace can rely on a shared postgres instance in the same namespace. There might be similar issues there too.

    Crazy thought here: what if Helm didn't manage globally-scoped resources, and left that to the cluster administrator? That way we leave the reconciliation of globally scoped resources to the cluster administrator. That would put Helm squarely as a userland tool, instead of the current system where Helm can be being used as a cluster management tool, managing the entire cluster's state for an application.

    Other than that, I don't have any immediate solutions that come to mind. How do other package managers reconcile shared resources between two apps? Do they just tell package maintainers that it's out of scope?

  13. paulczar commented on Jun 17, 2019

    @paulczar
    Contributor

    It's a good case of sharing common resources between multiple apps: how do the two reconcile a shared resource without stepping on eachother's toes?

    If we take a stance of A helm chart being a standalone package, then we probably shouldn't try and handle two apps sharing a resource, instead we would make it three apps.

    In this case where the shared resource is a CRD, then the CRD would be the third app, and would have its own method of install ( whether it being a helm chart that's installed first, or some other method ).

    That would make our stance something like "you can use helm to manage a CRD, but it should be its own discreet package, and not be part of an operator or other chart". The user could then reach for a higher order tool like helmfile to orchestrate composing infrastructure from multiple charts.

    Crazy thought here: what if Helm didn't manage globally-scoped resources, and left that to the cluster administrator? That way we leave the reconciliation of globally scoped resources to the cluster administrator.

    I'm starting to lean in this direct. A CRD is effectively adding to the kubernetes control plane, an app deployed by a "user" definitely shouldn't be trying to change the behaviour of the control plane, and the blast radius from a CRD CRUD operation is big enough that Helm probably shouldn't try and manage the lifecycle of them. Hell its a hard enough problem that the operator-sdk folks have built a tool specifically to deal with operator lifecycle management - https://github.com/operator-framework/operator-lifecycle-manager

  14. 30 remaining items

  15. kyounger commented on Jul 3, 2020

    @kyounger

    Would considering an option like --only-crds make sense, where helm would skip everything except the crds? One of the two recommended approaches in the docs is to install CRDs as a separate chart. This would allow reuse of the chart package for two release installs, 1) as a release for the CRDs at a specific version, and 2) a release of the chart templates at that same version.

    I think this would also work well with k8s api versioning. You would just install multiple releases of the chart (using proposed --only-crds) at different versions and you'd have the ability to take advantage of multiple CRD versions.

    I readily admit that it doesn't trigger my "elegance" spidey-sense. But typically these CRDs are developed in the same git repo and versioned together anyway. So I think we all agree it makes sense to keep them in the same chart. This would just provide a way to keep that pattern and easily implement recommend docs approach #2.

  16. TBBle commented on Jul 5, 2020

    @TBBle
    Contributor

    That would probably make more sense as a command, install-crds, I think. Since they're not templated, for example, a lot of the options (like --values) wouldn't make much sense to have available. It'd be specifically-useful in the situation I mentioned above where you want to use a chart that depends on CRDs, but do not yourself have permissions to install CRDs on a cluster, so you can ask the administrator to just install the CRDs for you.

    I still intend to try and implement my ideas above (both --force-crds, --overwrite-crds, or similar as the inversion of --skip-crds, and a (plugin, at first) crd-management command (I called it update-crds earlier, it probably overlaps with the install-crds idea) which can attempt to correctly update CRDs by default, and when it cannot, gives the user the right levers to do it, with an eye to building that into Helm's upgrade/install flows.

  17. monotek commented on Jul 6, 2020

    @monotek

    How about that workflow:

    If "helm upgrade" detects that a CRD would be overwritten, it should fail with something like: "CRD has same version as the one installed or no version at all. Use --force (onyl if you know what you're doing) to overwrite it anyway or --skip-crd (recommended) to leave it untouched."

    If "helm upgrade" finds a CRD and the version to be installed has a new / another version it should be installed additionally, keeping the old CRD version in place too.

    Maybe also an additional hint on "helm upgrade" could be added that charts should use versioned CRDs only. Even a "helm install" could already warn about usage of unversioned CRDs.

  18. bacongobbler commented on Aug 14, 2020

    @bacongobbler
    Member

    See helm/community#138 for the explanation why we are not considering that approach.

  19. github-actions commented on Nov 22, 2020

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

  20. KlavsKlavsen commented on Jun 8, 2021

    @KlavsKlavsen

    If I understand this correctly, Helm project has abandoned trying to support CRD lifecycle.. which means "something else" will have to be written to update CRDs in Helm charts?

  21. monotek commented on Jun 8, 2021

    @monotek
  22. kvaps commented on Aug 21, 2023

    @kvaps
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

    Staleproposalv3.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions