Skip to content

Behaviour of crd-install hook annotation  #4440

Closed

Description

@day0ops

Output of helm version:

Client: &version.Version{SemVer:"v2.10.0-rc.2", GitCommit:"56154102a2f25ebf679c791907fd355bb0377f05", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.10.0-rc.2", GitCommit:"56154102a2f25ebf679c791907fd355bb0377f05", GitTreeState:"clean"}

Output of kubectl version:

Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.7", GitCommit:"dd5e1a2978fd0b97d9b78e1564398aeea7e7fe92", GitTreeState:"clean", BuildDate:"2018-04-19T00:05:56Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.1", GitCommit:"b1b29978270dc22fecc592ac55d903350454310a", GitTreeState:"clean", BuildDate:"2018-07-17T18:43:26Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}

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

Referring to the new crd-install hook annotation https://github.com/helm/helm/blob/master/docs/charts_hooks.md#defining-a-crd-with-the-crd-install-hook
What is the intended behaviour for chart re-install ?

I noticed that it does not automatically remove the custom resource definitions during a chart purge hence the re-install fails due to existing crds.

Activity

  1. technosophos commented on Aug 7, 2018

    @technosophos
    Member

    Yeah, we have this weird case where once you have created a CRD definition, other things on a cluster can become dependent on it -- notably, and CRD instances. So once we've created a CRD, it is risky to delete it. So we implemented CRD installation as a hook, which makes the CRD unmanaged (e.g. Helm doesn't delete it by default)

    So if you want to delete it, you need to explicitly tell the chart to delete it:
    https://github.com/helm/helm/blob/master/docs/charts_hooks.md#hook-resources-are-not-managed-with-corresponding-releases

  2. sdake commented on Aug 7, 2018

    @sdake
    sdake@falkor-07:~/go/src/istio.io/istio$ helm version
    Client: &version.Version{SemVer:"v2.10.0-rc.2", GitCommit:"56154102a2f25ebf679c791907fd355bb0377f05", GitTreeState:"clean"}
    Server: &version.Version{SemVer:"v2.10.0-rc.2", GitCommit:"56154102a2f25ebf679c791907fd355bb0377f05", GitTreeState:"clean"}
    sdake@falkor-07:~/go/src/istio.io/istio$ kubectl version
    Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:55:54Z", GoVersion:"go1.9.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"}
    

    @technosophos I've tried the following in our CRD charts:

        "helm.sh/hook-delete-policy": before-hook-creation
    

    which results in:

    sdake@falkor-07:~/go/src/istio.io/istio$ helm install install/kubernetes/helm/istio --name istio --namespace istio-system
    Error: object is being deleted: customresourcedefinitions.apiextensions.k8s.io "gateways.networking.istio.io" already exists
    

    I've also tried:

        "helm.sh/hook-delete-policy": before-hook-creation
    

    I've also tried the policy

    hook-succeeded: results in immediate deletion of the CRD after registration - which makes sense
    

    I haven't tried hook-failed,before-hook-creation which may render something working - will have to try.

    Is the recommended technique for deleting CRDs when using crd-install to use a post-delete hook?

  3. day0ops commented on Aug 7, 2018

    @day0ops
    Author

    @sdake it sounds like we may require a post-delete job to remove the resources ?

  4. sdake commented on Aug 7, 2018

    @sdake

    @nixgadget hope that isn't the answer but will wait for @technosophos to weigh in.

    Cheers
    -steve

  5. technosophos commented on Aug 7, 2018

    @technosophos
    Member

    CRD deletion is slow, so using a before-hook-creation might not be fast enough.

    In general, for things like CRDs it's better to delete in post-delete if possible.

    There's also the --no-hooks CLI option if you know the CRD is always there.

  6. sdake commented on Aug 7, 2018

    @sdake

    with "before-hook-creation" policy, the CRD is deleted immediately after it is created during helm install on a fresh cluster. It sounds like this isn't expected behavior?

    (edit)
    Sorry that was hook-succeeded which seems like expected behavior.

  7. technosophos commented on Aug 7, 2018

    @technosophos
    Member

    Yeah -- that is used for things like Jobs where you run the job once, then delete it

  8. day0ops commented on Aug 7, 2018

    @day0ops
    Author

    @sdake for me in my baremetal cluster before-hook-creation didnt quite work as @technosophos points out.

  9. sdake commented on Aug 7, 2018

    @sdake

    Thanks, will sort out a post-delete hook.

  10. day0ops commented on Aug 7, 2018

    @day0ops
    Author

    @technosophos thanks for clarifying.

  11. sdake commented on Aug 7, 2018

    @sdake

    @technosophos can you clarify how a post-delete job would work on deleting CRDs with the helm template case?

    For further reference, a quick read of https://istio.io/docs/setup/kubernetes/helm-install/#installation-steps might help set some context. Istio 1.0 supports both helm template and helm install models.

    Our CRD template is here:
    https://github.com/istio/istio/blob/master/install/kubernetes/helm/istio/templates/crds.yaml

    Cheers and thanks for your help - people are restless ;)
    -steve

  12. technosophos commented on Aug 7, 2018

    @technosophos
    Member

    Okay, admittedly this is not my forte. What I have seen people do is launch a post-delete Job that wraps the kubectl docker image, and just runs kubectl delete on the given resource. I imagine that there are other ways of doing this that are a little less heavy handed.

    This is definitely something we're aiming to fix in Helm 3. But in Helm 2 it's just sort of clunky to deal with CRDs.

  13. sdake commented on Aug 7, 2018

    @sdake

    @technosophos right - I understand its clunky and not hounding you up about that :). We had post-install jobs doing CRDs prior (with hyperkube) so it isn't unexpected we would need kubectl wrapped jobs. My question is more about the helm template case. With helm template, everything (including the Job that runs kubectl delete on the list of resources) would be deleted on start, vs helm installwhich will process the job only on delete.

    Wondering how to make the helm template case work with a post install job (IOW ignore the job entirely) while the helm install case only runs at deletion of the chart with the unmanaged resources.

    Cheers
    -steve

  14. vhosakot commented on Aug 22, 2018

    @vhosakot

    I saw the same behavior today and didn't know helm doesn't delete CRDs by default (since helm installs CRDs as hook resources):

    $ helm upgrade --install istio -f ./istio.yaml --namespace istio-system ./istio.tgz
    Release "istio" does not exist. Installing it now.
    Error: customresourcedefinitions.apiextensions.k8s.io "adapters.config.istio.io" already exists
    

    I deleted the CRDs manually.

    @sdake Interesting point about helm template with a post install job vs helm install :)

  15. sdake commented on Nov 25, 2018

    @sdake

    @vhosakot - the helm template case is the main use case that must be preserved. It is far more important than Helm not deleting CRDs. If I have to trade one for another, I'll keep helm template with kubectl apply -f...

  16. BradyWiseman commented on Dec 11, 2018

    @BradyWiseman

    What if I want to leave the crd in place, and have the restarted release continue to use it and its data?
    When delete then reapply the release, it fails because the crd "already exists", due to the crd-install hook.
    Is there any way around that?

  17. jaijitendra commented on Mar 14, 2019

    @jaijitendra

    Any update on this issue? What is the recommeneded way to handle customresourcedefintion create in second helm install?

  18. vsliouniaev commented on Mar 14, 2019

    @vsliouniaev

    @jaijitendra That's exactly the approach we have taken to make this work

  19. natereid72 commented on Apr 29, 2019

    @natereid72

    seems like just accepting that crd exists and moving on would be best option.

  20. allamand commented on Jun 5, 2019

    @allamand

    I like the idea of the cli option --no-hooks to re-install with leaving existing crd in place

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions