Skip to content

helm.sh/hook pre-install does not work with ThirdPartyResources #2680

Closed

Description

@lhopki01

According to https://github.com/kubernetes/helm/blob/master/docs/chart_best_practices/third_party_resources.md option 2 you can phase the creation of ThirdPartyResources using a pre-install hook however this doesn't work.

When trying to use helm to install the following test templates:

% ls templates
00-thirdpartyresource.yaml	20-certificate.yaml

% cat templates/00-thirdpartyresource.yaml
---
apiVersion: extensions/v1beta1
kind: ThirdPartyResource
description: "A test tpr resource defintion to test pre-hooks"
metadata:
  name: "testtpr.helm.something"
  annotations:
    "helm.sh/hook": pre-install
versions:
  - name: v1

% cat templates/20-certificate.yaml
---
apiVersion: "helm.something/v1"
kind: "Testtpr"
metadata:
  name: "test-testtpr"
spec:
  domain: "test.domain"

I get the following

% helm install .
Error: apiVersion "helm.something/v1" in helm-test/templates/20-certificate.yaml is not available

Tiller logs show this:

[tiller] 2017/07/12 14:20:47 preparing install for
[storage] 2017/07/12 14:20:47 getting release "rolling-olm.v1"
[tiller] 2017/07/12 14:20:47 rendering helm-test chart using values
[tiller] 2017/07/12 14:20:47 failed install prepare step: apiVersion "helm.something/v1" in helm-test/templates/20-certificate.yaml is not available

When I create these sequentially using kubectl it works fine

% kubectl create -f templates/00-thirdpartyresource.yaml
thirdpartyresource "testtpr.helm.something" created
% kubectl create -f templates/20-certificate.yaml
testtpr "test-testtpr" created

% kubectl get thirdpartyresource
NAME                            DESCRIPTION                                                 VERSION(S)
testtpr.helm.something          A test tpr resource defintion to test pre-hooks             v1
% kubectl get testtpr
NAME           KIND
test-testtpr   Testtpr.v1.helm.something

If I try and do something similar with helm by moving 20-certifcate.yaml out of the templates folder and doing a helm install it fails yet still creates the resource. However the helm chart isn't created.

% mv templates/20-certificate.yaml ./
% ls templates
00-thirdpartyresource.yaml
% helm install .
Error: the server rejected our request for an unknown reason (get thirdpartyresources.extensions)
% kubectl get thirdpartyresource
NAME                            DESCRIPTION                                                 VERSION(S)
testtpr.helm.something          A test tpr resource defintion to test pre-hooks             v1
% helm list
NAME             	REVISION	UPDATED                 	STATUS  	CHART                  	NAMESPACE

If I remove the hook though it works.

% cat templates/00-thirdpartyresource.yaml
---
apiVersion: extensions/v1beta1
kind: ThirdPartyResource
description: "A test tpr resource defintion to test pre-hooks"
metadata:
  name: "testtpr.helm.something"
  #annotations:
  #  "helm.sh/hook": pre-install
versions:
  - name: v1
% helm install .
NAME:   existing-jaguar
LAST DEPLOYED: Wed Jul 12 15:38:43 2017
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1beta1/ThirdPartyResource
NAME                    DESCRIPTION                                      VERSION(S)
testtpr.helm.something  A test tpr resource defintion to test pre-hooks  v1

I can then move the second template back into the folder and do a helm upgrade.

% mv 20-certificate.yaml templates
% ls templates
00-thirdpartyresource.yaml	20-certificate.yaml
% helm upgrade existing-jaguar .
Release "existing-jaguar" has been upgraded. Happy Helming!
LAST DEPLOYED: Wed Jul 12 15:40:56 2017
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/Testtpr
NAME          KIND
test-testtpr  Testtpr.v1.helm.something

==> v1beta1/ThirdPartyResource
NAME                    DESCRIPTION                                      VERSION(S)
testtpr.helm.something  A test tpr resource defintion to test pre-hooks  v1

I have tested hooks without ThirdPartyResources and they seem fine so the issue seems to lie with ThirdPartyResources and hooks. I have tested using a post-install hook for ThirdPartyResources to similar effect.

Helm and Kubernetes versions

% helm version
Client: &version.Version{SemVer:"v2.5.0", GitCommit:"012cb0ac1a1b2f888144ef5a67b8dab6c2d45be6", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.5.0", GitCommit:"012cb0ac1a1b2f888144ef5a67b8dab6c2d45be6", GitTreeState:"clean"}
% kubectl version
Client Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.4", GitCommit:"d6f433224538d4f9ca2f7ae19b252e6fcb66a3ae", GitTreeState:"clean", BuildDate:"2017-05-19T18:44:27Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.4", GitCommit:"d6f433224538d4f9ca2f7ae19b252e6fcb66a3ae", GitTreeState:"clean", BuildDate:"2017-05-19T18:33:17Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}

Activity

  1. seh commented on Jul 13, 2017

    @seh
    Contributor

    The Kubernetes client used by Tiller is not using a runtime.Scheme impregnated with knowledge of your TPR types. kubectl uses the "discovery" interface to learn of such types before interacting further with the API server.

  2. lhopki01 commented on Jul 13, 2017

    @lhopki01
    Author

    @seh my understanding of a pre-install hook is that it should install the TPR kind first before it tries to install the TPR types so it shouldn't have this conflict.

    Also why would having a pre-install hook create issues when only a TPR kind is being installed by helm?

    % mv templates/20-certificate.yaml ./
    % ls templates
    00-thirdpartyresource.yaml
    % helm install .
    Error: the server rejected our request for an unknown reason (get thirdpartyresources.extensions)
    % kubectl get thirdpartyresource
    NAME                            DESCRIPTION                                                 VERSION(S)
    testtpr.helm.something          A test tpr resource defintion to test pre-hooks             v1
    % helm list
    NAME             	REVISION	UPDATED                 	STATUS  	CHART                  	NAMESPACE
    
  3. seh commented on Jul 15, 2017

    @seh
    Contributor

    I'm still having trouble following your description of what works and what doesn't work, but I suspect this problem has nothing to do with hooks. The following possibilities come to mind:

    • Tiller lacks permission to use these TPRs.
      That doesn't look like the case here, as we're not seeing failures that look to be related to authorization.
    • The TPR's API resource (sort of redundant) is not available quickly enough after creating it for Tiller to then create a corresponding data object.
      Normally after one creates a TPR kind, the client must poll the API server to wait until the TPR is ready for use. What happens if you add another intervening hook that stalls after creating the TPR for, say, 20 seconds?
    • As mentioned earlier, the Tiller Kubernetes client is not aware of the TPR, and can't deal with creating objects of its kind.
      I am not sure of the consequences of not registering the TPR's kinds with the Kubernetes client's runtime.Scheme, but in my own project I've done that, following approximately the (now deprecated) example in the kubernetes/client-go repository.
  4. lhopki01 commented on Jul 18, 2017

    @lhopki01
    Author

    @seh

    Option 1 doesn't apply because it can create TPRs when there is no hook set.

    Option 2 won't work because as above when I try and only create a TPR with a pre-install hook it fails.

    % ls templates
    00-thirdpartyresource.yaml
    % helm install .
    Error: the server rejected our request for an unknown reason (get thirdpartyresources.extensions)
    % kubectl get thirdpartyresource
    NAME                            DESCRIPTION                                                 VERSION(S)
    testtpr.helm.something          A test tpr resource defintion to test pre-hooks             v1
    % helm list
    NAME             	REVISION	UPDATED                 	STATUS  	CHART                  	NAMESPACE
    

    I don't even know what option 3 is quite but Tiller Kubernetes client can create TPRs just not when a hook is specified.

  5. fejta-bot commented on Jan 1, 2018

    @fejta-bot

    Issues go stale after 90d of inactivity.
    Mark the issue as fresh with /remove-lifecycle stale.
    Stale issues rot after an additional 30d of inactivity and eventually close.

    Prevent issues from auto-closing with an /lifecycle frozen comment.

    If this issue is safe to close now please do so with /close.

    Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
    /lifecycle stale

  6. fejta-bot commented on Jan 31, 2018

    @fejta-bot

    Stale issues rot after 30d of inactivity.
    Mark the issue as fresh with /remove-lifecycle rotten.
    Rotten issues close after an additional 30d of inactivity.

    If this issue is safe to close now please do so with /close.

    Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
    /lifecycle rotten
    /remove-lifecycle stale

  7. fejta-bot commented on Mar 2, 2018

    @fejta-bot

    Rotten issues close after 30d of inactivity.
    Reopen the issue with /reopen.
    Mark the issue as fresh with /remove-lifecycle rotten.

    Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
    /close

  8. dotw commented on Mar 22, 2018

    @dotw

    I have the same issue when my chart has a subchart of cert-manager. it reports the similar issue when an Issuer.yam is in the parent chart.

  9. brbarnett commented on May 22, 2018

    @brbarnett

    I have the same issue as @dotw, specifically with cert-manager. I've forked cert-manager and even added the crd-install hook annotation to the issuer CRD, but I still get apiVersion "certmanager.k8s.io/v1alpha1" in app/templates/issuer.yaml is not available

  10. qrevel commented on Jun 5, 2018

    @qrevel

    /reopen
    /remove-lifecycle rotten
    exactly the same problem than @brbarnett

  11. mikluko commented on Jul 26, 2018

    @mikluko

    I managed to work that around by scheduling deployment job. Snippet below is rke specific, but can probably be adapted to any cluster implementation.
    system is my top-level chart.

    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: {{ template "system.fullname" . }}-issuer-deploy-config
      labels:
        app: {{ template "system.name" . }}
        chart: {{ template "system.chart" . }}
        release: {{ .Release.Name }}
        heritage: {{ .Release.Service }}
    data:
      resource.yml: |
        apiVersion: certmanager.k8s.io/v1alpha1
        kind: ClusterIssuer
        metadata:
          name: {{ template "system.fullname" . }}-acme
        spec:
          acme:
            email: {{ .Values.acme.email }}
            server: {{ .Values.acme.endpoint }}
            privateKeySecretRef:
              name: {{ template "system.fullname" . }}-acme
            http01: {}
            dns01: {}
    ---
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: {{ template "system.fullname" . }}-issuer-deploy-job
      labels:
        app: {{ template "system.name" . }}
        chart: {{ template "system.chart" . }}
        release: {{ .Release.Name }}
        heritage: {{ .Release.Service }}
    spec:
      backoffLimit: 5
      template:
        spec:
          serviceAccountName: rke-job-deployer
          restartPolicy: Never
          containers:
          - name: {{ template "system.fullname" . }}-issuer-deploy-job-pod
            image: rancher/hyperkube:v1.11.1-rancher1
            command:
            - kubectl
            - apply
            - -f
            - /etc/config/resource.yml
            volumeMounts:
            - name: config-volume
              mountPath: /etc/config
          volumes:
          - name: config-volume
            configMap:
              defaultMode: 420
              name: {{ template "system.fullname" . }}-issuer-deploy-config
          restartPolicy: Never
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