Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commands/.../new,pkg/scaffold/helm: source chart flag for new projects #949

Merged
merged 21 commits into from
Feb 26, 2019

Conversation

joelanford
Copy link
Member

@joelanford joelanford commented Jan 17, 2019

Description of the change:
This PR adds new flags to the operator-sdk new command that enable new Helm projects to be created from existing Helm charts.

  • --helm-chart - The chart to use when creating the project. Format is:
    • <url>
    • <repo>/<chart_name>
    • <chart_name> (with --helm-chart-repo specified)
    • /path/to/chart.tgz (local chart archive)
    • /path/to/chartDir (local chart directory)
  • --helm-chart-version - The version of the chart to fetch from a remote repository.
  • --helm-chart-repo - The URL of the Helm chart repo in which to find the chart specified by --helm-chart

It also makes --api-version and --kind optional if --helm-chart is set, If left unset, --api-version is defaulted to charts.helm.k8s.io/v1alpha1 and --kind is deduced from the fetched chart.

Examples:

  • From a URL:

    operator-sdk new memcached-operator --type=helm --helm-chart=https://storage.googleapis.com/kubernetes-charts/memcached-2.4.0.tgz
    
  • From stable repo:

    operator-sdk new memcached-operator --type=helm --helm-chart=stable/memcached
    
  • From custom repo:

    operator-sdk new memcached-operator --type=helm --helm-chart=memcached --helm-chart-repo=https://storage.googleapis.com/kubernetes-charts
    
  • From local archive:

    operator-sdk new memcached-operator --type=helm --helm-chart=/path/to/memcached-2.4.0.tgz
    
  • From a local directory:

    operator-sdk new memcached-operator --type=helm --helm-chart=/path/to/memcached/
    

Motivation for the change:
At the suggestion of @robszumski, I put together this PR to simplify the UX for building operators from existing Helm charts.

NOTE: This PR exposes only some of the flags that helm fetch does, so not all use cases are supported (e.g. users will not be able to authenticate to a remote repo using the operator-sdk CLI from this PR).

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 17, 2019
…r helm CLI, add helm-chart-version flag, general cleanup
@joelanford joelanford changed the title [POC] Allow specifying source chart and repo for new Helm projects commands/.../new,pkg/scaffold/helm: source chart flag for new projects Jan 24, 2019
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 31, 2019
@openshift-ci-robot openshift-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jan 31, 2019
Copy link
Member

@lilic lilic left a comment

Choose a reason for hiding this comment

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

Overall lgtm 👍 Left few suggestions and questions. Thanks for the detailed description of the PR!

commands/operator-sdk/cmd/new.go Outdated Show resolved Hide resolved
commands/operator-sdk/cmd/new.go Show resolved Hide resolved
pkg/scaffold/helm/chart.go Outdated Show resolved Hide resolved
pkg/scaffold/helm/chart.go Outdated Show resolved Hide resolved
pkg/scaffold/helm/chart.go Outdated Show resolved Hide resolved
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 4, 2019
@joelanford joelanford force-pushed the helm-new-source-chart branch from dddd92d to b7c93b9 Compare February 5, 2019 17:26
Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

LGTM, two nits.

commands/operator-sdk/cmd/new.go Outdated Show resolved Hide resolved
pkg/scaffold/helm/chart.go Outdated Show resolved Hide resolved
@hasbro17
Copy link
Contributor

hasbro17 commented Feb 6, 2019

@joelanford We can probably mention this feature in the CHANGELOG.

Also the godocs for CreateChart are pretty detailed 👍 but we might still want to update the CLI reference and user-guide to showcase the --helm-chart flag. It's fine if we do a follow up based on this PR. Just wanted to point it out.

@joelanford
Copy link
Member Author

joelanford commented Feb 6, 2019

@hasbro17 Thanks! I'll go ahead and update the CLI doc so I can reference it in the CHANGELOG.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 6, 2019
@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 6, 2019
Copy link
Member

@lilic lilic left a comment

Choose a reason for hiding this comment

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

lgtm 👍

return s.Input, nil
}

const watchesYAMLTmpl = `---
- version: {{.Resource.Version}}
group: {{.Resource.FullGroup}}
kind: {{.Resource.Kind}}
chart: /opt/helm/{{.HelmChartsDir}}/{{.Resource.LowerKind}}
chart: /opt/helm/{{.HelmChartsDir}}/{{.ChartName}}
Copy link
Member

Choose a reason for hiding this comment

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

Quick question: Can ChartName be allowed to contain uppercase chars? If yes, should we convert it to lowercase here?

Copy link
Member Author

Choose a reason for hiding this comment

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

According to the chart name conventions, chart names SHOULD be lower case. However, the directory name MUST match the name in Chart.yaml. It seems the chart name case is not enforced, but the directory matching the name in Chart.yaml is.

$ helm create Test
Creating Test

$ helm package Test
Successfully packaged chart and saved it to: /tmp/Test-0.1.0.tgz

$ mv Test test

$ helm package test
Error: directory name (test) and Chart.yaml name (Test) must match

Since our code works by using Helm's packages to load the chart metadata, .ChartName is effectively a read-only field provided by Helm. For that reason, I think I lean toward accepting what Helm gives us without modification. I would expect Helm to error out if a user tried to create or fetch an invalid chart.

Copy link
Contributor

@hasbro17 hasbro17 left a comment

Choose a reason for hiding this comment

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

LGTM

@joelanford joelanford merged commit f6da5ed into operator-framework:master Feb 26, 2019
@joelanford joelanford deleted the helm-new-source-chart branch February 26, 2019 21:05
lilic pushed a commit to lilic/operator-sdk that referenced this pull request Feb 27, 2019
operator-framework#949)

* commands/operator-sdk/cmd/new,pkg/scaffold/helm: allow source helm chart when creating new helm projects

* pkg/scaffold/helm/chart.go,commands/.../new.go: remove requirement for helm CLI, add helm-chart-version flag, general cleanup

* commands/operator-sdk/cmd/new.go: improve helm-chart flags' help texts

* commands/operator-sdk/cmd/new.go: comment to describe verifyFlags logic with --helm-chart

* pkg/scaffold/helm/chart.go: revert to using r.LowerKind for scaffolded chart name

* commands/.../new.go,pkg/scaffold/helm/chart.go: improve function signatures and add CreateChart godoc comment

* pkg/scaffold/helm/chart.go: comment to explain decision not to use hyphens in scaffolded chart name

* commands/operator-sdk/cmd/new.go: fix typo in help text

* commands/operator-sdk/cmd/new.go: fix helm verify flags logic

* pkg/scaffold/helm/chart.go: log tmpDir remove failure

* CHANGELOG.md,doc,pkg/scaffold/helm: update docs

* vendor: add necessary vendor dirs

* CHANGELOG.md: moving updates to Unreleased section

* Gopkg.lock,vendor: removing non-go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants