Skip to content

feat(tiller): support CRD installation#3982

Merged
technosophos merged 1 commit intohelm:masterfrom
technosophos:feat/2994-crd-hook
May 11, 2018
Merged

feat(tiller): support CRD installation#3982
technosophos merged 1 commit intohelm:masterfrom
technosophos:feat/2994-crd-hook

Conversation

@technosophos
Copy link
Copy Markdown
Member

This adds support for installing CRDs well before any other resource
kinds are installed.

This PR introduces a new hook, crd-install, that fires before
manifests are even validated. It is used to install a CRD before any
other part of a chart is installed.

Currently, this hook is only implemented for install. That means we
currently cannot add new CRDs during helm upgrade, nor can they
be rolled back. This is the safest configuration, as the update/rollback
cycle gets very challenging when CRDs are added and removed.

@technosophos technosophos self-assigned this Apr 27, 2018
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 27, 2018
@rimusz
Copy link
Copy Markdown
Contributor

rimusz commented Apr 27, 2018

yay, long awaited feature 😀

@technosophos technosophos force-pushed the feat/2994-crd-hook branch 3 times, most recently from ed70473 to 8de8ab9 Compare April 28, 2018 00:19
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 28, 2018
@technosophos technosophos changed the title WIP feat(tiller): support CRD installation feat(tiller): support CRD installation Apr 28, 2018
@technosophos
Copy link
Copy Markdown
Member Author

Okay, here's how this works

First, if you are just creating a CRD with no instances of that CRD, you do nothing (just as always). This is designed to allow for a CRD and instances of the CRD to be installed in the same chart. It is also designed to be maximally backward compatible, though I did have to eliminate one set of validations in order to do this.

To add a CRD to a chart, create a CRD template and set an annotation on the template:

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
  # THE IMPORTANT PART!!!
  annotations:
    "helm.sh/hook": crd-install
spec:
  group: stable.example.com
  version: v1
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct

You can also create a template that references that CRD:

apiVersion: stable.example.com/v1
kind: CronTab
metadata:
  name: {{ .Release.Name }}-inst

Now, when you run helm install ./mychart, the following will happen:

  • Manifests will be sorted and rendered as usual
  • crd-install hooks will be separated
  • If dry-run and there's a CRD hook, validation will be skipped and the user will be warned
  • Otherwise, execute the crd-install hook (install the CRD)
  • Validate the remaining normal manifests
  • Run pre-install
  • Continue on the normal installation path

If helm install --no-crd-hook is specified, then the crd-install hook is skipped, and no CRDs are installed. If --no-hooks is specified, crd-install is skipped. If --no-crd-hook --dry-run are specified together, the validator will run.

This adds support for installing CRDs well before any other resource
kinds are installed.

This PR introduces a new hook, `crd-install`, that fires before
manifests are even validated. It is used to install a CRD before any
other part of a chart is installed.

Currently, this hook is _only implemented for install_. That means we
currently cannot add new CRDs during `helm upgrade`, nor can they
be rolled back. This is the safest configuration, as the update/rollback
cycle gets very challenging when CRDs are added and removed.
return e
}

if entry.Version != "" && !file.apis.Has(entry.Version) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be really clear: I am removing this set of checks. It appears to duplicate the check in validateManifest, and it fires well before we have a chance to install the CRD.

@technosophos technosophos merged commit 0699ec4 into helm:master May 11, 2018
@technosophos technosophos deleted the feat/2994-crd-hook branch May 11, 2018 18:09
@tamalsaha
Copy link
Copy Markdown
Contributor

tamalsaha commented May 23, 2018

@technosophos , what should I do if I want to support last 2-3 version of helm with the same chart? Is there a better option that use if-else with Capabilities.TillerVersion ?

@bamb00
Copy link
Copy Markdown

bamb00 commented Jun 22, 2018

What helm version is this feature going to be in?

@bacongobbler
Copy link
Copy Markdown
Member

2.10

@gyliu513
Copy link
Copy Markdown

What is the difference of this fix with #3019 ? @technosophos

@gyliu513
Copy link
Copy Markdown

/cc @morvencao

@bacongobbler
Copy link
Copy Markdown
Member

bacongobbler commented Jul 27, 2018

#3019 is for custom resources (CRs) to the sorting list, whereas this PR adds support for custom resource definitions (CRDs). Prior to this hook being available, charts could not install CRs and CRDs because the manifests would be validated all in one step prior to the CRDs being installed.

The docs that were added to this PR goes into a little more detail on this new hook, which can be found here: https://docs.helm.sh/developing_charts/#defining-a-crd-with-the-crd-install-hook

Does that help explain this fix, or is there something else we should document?

@gyliu513
Copy link
Copy Markdown

@bacongobbler I think #3019 is also for CRD but not CR, #3019 is trying to enable all of the CRDs should be created first before other resources take reference of this CRD. Am I missing anything?

splisson pushed a commit to splisson/helm that referenced this pull request Dec 6, 2018
This adds support for installing CRDs well before any other resource
kinds are installed.

This PR introduces a new hook, `crd-install`, that fires before
manifests are even validated. It is used to install a CRD before any
other part of a chart is installed.

Currently, this hook is _only implemented for install_. That means we
currently cannot add new CRDs during `helm upgrade`, nor can they
be rolled back. This is the safest configuration, as the update/rollback
cycle gets very challenging when CRDs are added and removed.

Signed-off-by: Sebastien Plisson <sebastien.plisson@gmail.com>
splisson pushed a commit to splisson/helm that referenced this pull request Dec 6, 2018
This adds support for installing CRDs well before any other resource
kinds are installed.

This PR introduces a new hook, `crd-install`, that fires before
manifests are even validated. It is used to install a CRD before any
other part of a chart is installed.

Currently, this hook is _only implemented for install_. That means we
currently cannot add new CRDs during `helm upgrade`, nor can they
be rolled back. This is the safest configuration, as the update/rollback
cycle gets very challenging when CRDs are added and removed.

Signed-off-by: Sebastien Plisson <sebastien.plisson@gmail.com>
splisson pushed a commit to splisson/helm that referenced this pull request Dec 6, 2018
This adds support for installing CRDs well before any other resource
kinds are installed.

This PR introduces a new hook, `crd-install`, that fires before
manifests are even validated. It is used to install a CRD before any
other part of a chart is installed.

Currently, this hook is _only implemented for install_. That means we
currently cannot add new CRDs during `helm upgrade`, nor can they
be rolled back. This is the safest configuration, as the update/rollback
cycle gets very challenging when CRDs are added and removed.
splisson pushed a commit to splisson/helm that referenced this pull request Dec 6, 2018
This adds support for installing CRDs well before any other resource
kinds are installed.

This PR introduces a new hook, `crd-install`, that fires before
manifests are even validated. It is used to install a CRD before any
other part of a chart is installed.

Currently, this hook is _only implemented for install_. That means we
currently cannot add new CRDs during `helm upgrade`, nor can they
be rolled back. This is the safest configuration, as the update/rollback
cycle gets very challenging when CRDs are added and removed.
jianghang8421 pushed a commit to jianghang8421/helm that referenced this pull request Feb 17, 2019
This adds support for installing CRDs well before any other resource
kinds are installed.

This PR introduces a new hook, `crd-install`, that fires before
manifests are even validated. It is used to install a CRD before any
other part of a chart is installed.

Currently, this hook is _only implemented for install_. That means we
currently cannot add new CRDs during `helm upgrade`, nor can they
be rolled back. This is the safest configuration, as the update/rollback
cycle gets very challenging when CRDs are added and removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants