Skip to content

Commit

Permalink
feat: Add helmfile template --include-crds (helm#1568)
Browse files Browse the repository at this point in the history
This allows you to use helmfile-template output as a GitOps source, when the template output contains CRDs and you use Helm 3.

Helm 3 by default removes CRDs from the template output. If you want to git-commit helmfile-template containing CRDs for GitOps and you use Helm 3 for templating, the only way is provide this newly added `--include-crds` flag.
  • Loading branch information
mumoshu committed Nov 5, 2020
1 parent bdbaa00 commit 6b86408
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ func main() {
Name: "validate",
Usage: "validate your manifests against the Kubernetes cluster you are currently pointing at",
},
cli.BoolFlag{
Name: "include-crds",
Usage: "include CRDs in the templated output",
},
cli.BoolFlag{
Name: "skip-deps",
Usage: "skip running `helm repo update` and `helm dependency build`",
Expand Down Expand Up @@ -717,6 +721,10 @@ func (c configImpl) EmbedValues() bool {
return c.c.Bool("embed-values")
}

func (c configImpl) IncludeCRDs() bool {
return c.c.Bool("include-crds")
}

func (c configImpl) Logger() *zap.SugaredLogger {
return c.c.App.Metadata["logger"].(*zap.SugaredLogger)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,7 @@ func (a *App) template(r *Run, c TemplateConfigProvider) (bool, []error) {

opts := &state.TemplateOpts{
Set: c.Set(),
IncludeCRDs: c.IncludeCRDs(),
OutputDirTemplate: c.OutputDirTemplate(),
}
return subst.TemplateReleases(helm, c.OutputDir(), c.Values(), args, c.Concurrency(), c.Validate(), opts)
Expand Down
13 changes: 9 additions & 4 deletions pkg/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2237,10 +2237,11 @@ services:
}

type configImpl struct {
selectors []string
set []string
output string
skipDeps bool
selectors []string
set []string
output string
includeCRDs bool
skipDeps bool
}

func (a configImpl) Selectors() []string {
Expand Down Expand Up @@ -2275,6 +2276,10 @@ func (c configImpl) OutputDirTemplate() string {
return ""
}

func (c configImpl) IncludeCRDs() bool {
return c.includeCRDs
}

func (c configImpl) Concurrency() int {
return 1
}
Expand Down
1 change: 1 addition & 0 deletions pkg/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ type TemplateConfigProvider interface {
Validate() bool
SkipDeps() bool
OutputDir() string
IncludeCRDs() bool

concurrencyConfig
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@ func (st *HelmState) runHelmDepBuilds(helm helmexec.Interface, concurrency int,
type TemplateOpts struct {
Set []string
OutputDirTemplate string
IncludeCRDs bool
}

type TemplateOpt interface{ Apply(*TemplateOpts) }
Expand Down Expand Up @@ -1197,6 +1198,10 @@ func (st *HelmState) TemplateReleases(helm helmexec.Interface, outputDir string,
flags = append(flags, "--validate")
}

if opts.IncludeCRDs {
flags = append(flags, "--include-crds")
}

if len(errs) == 0 {
if err := helm.TemplateRelease(release.Name, release.Chart, flags...); err != nil {
errs = append(errs, err)
Expand Down

0 comments on commit 6b86408

Please sign in to comment.