confusion with helm "*-delete" hooks. Not delete previous resources when upgrade or install command

6/27/2019

I am trying to implement a "helm.sh/hook": crd-install hook on CustomResourceDefinition object of course, of this way

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  annotations:
    "helm.sh/hook": crd-install
    "helm.sh/hook-delete-policy": "before-hook-creation"
  name: certificates.certmanager.k8s.io

and when I am going to update or deploy a new instance with different name of my helm chart in the same cluster, I get this error

Error: customresourcedefinitions.apiextensions.k8s.io "certificates.certmanager.k8s.io" already exists

I suppose that "before-hook-creation" delete policy specifies Tiller should delete the previous hook before the new hook is launched.

But I can't to make a deletion and re-creation of my different CustomResourceDefinition objects

I have my chart in a CI/CD process, and the idea is that when I execute a helm upgrade operation or even an a new helm install operation with a new name of the chart in the same cluster, I don't have to force to delete the CRDs objects manually in order to it works

How can I get this purpose?

I have used "helm.sh/resource-policy": delete and also the "helm.sh/hook-delete-policy": "hook-succeeded" and "helm.sh/hook-delete-policy": "hook-failed" hooks all together but I am confused in this point

I am using the following versions of helm

helm version
Client: &version.Version{SemVer:"v2.13.1", GitCommit:"618447cbf203d147601b4b9bd7f8c37a5d39fbb4", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.13.1", GitCommit:"618447cbf203d147601b4b9bd7f8c37a5d39fbb4", GitTreeState:"clean"}

Like anecdote, I have the same YAML configuration in a secret resource, I mean I am creating that secret resource, but as a pre-install hook, but also using "helm.sh/hook-delete-policy": "before-hook-creation" and when I want to upgrade or install a new instance of my chart, it works.

I have made the same installing a CRDs as a pre-install hooks and it works

Why it works as a pre-install hook and not for crd-install hook? Can I deploy CRDs kubernetes objects as a pre-install hooks? I mean it isn't a bad practice or it is recommendable?

Any support I will be highly grateful

UPDATE

Even having the CRDs object resources a a pre-install hook, if I delete the helm chart helm delete --purge ... and I create it again, I get the same error

Error: object is being deleted: customresourcedefinitions.apiextensions.k8s.io "certificates.certmanager.k8s.io" already exists

The previous hook resources are not being deleted in order to continue with the installation workflow without generate errors.

I mean, it process only works when I am going to make a helm install for first time and its post-correspondent upgrades operations

-- bgarcial
devops
kubernetes-helm

0 Answers