From 38da7ca15c0cd79ef7b1a47c1d924313544f3d2c Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Mon, 26 Sep 2022 11:41:05 -0400 Subject: [PATCH] Add support for helm --no-hooks flag This commit adds the `skipHooks` option to the helm chart support in order to expose the --no-hooks flag introduced to Helm in [1]. Using Kustomize to inflate a Helm chart would in some situations result in different results than using `helm install`. This is because `helm template`, by default, will render chart tests in the `templates/test` directory, which can lead to undesired resources in the output. See [2] for additional discussion. [1]: https://github.com/helm/helm/pull/6444 [2]: https://github.com/helm/helm/issues/6443 Signed-off-by: Lars Kellogg-Stedman --- .../builtins/HelmChartInflationGenerator.go | 3 ++ api/types/helmchartargs.go | 4 +++ .../HelmChartInflationGenerator.go | 3 ++ .../HelmChartInflationGenerator_test.go | 28 +++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/api/internal/builtins/HelmChartInflationGenerator.go b/api/internal/builtins/HelmChartInflationGenerator.go index 2ce0469f9..b19d291bf 100644 --- a/api/internal/builtins/HelmChartInflationGenerator.go +++ b/api/internal/builtins/HelmChartInflationGenerator.go @@ -282,6 +282,9 @@ func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string { if p.IncludeCRDs { args = append(args, "--include-crds") } + if p.SkipHooks { + args = append(args, "--no-hooks") + } return args } diff --git a/api/types/helmchartargs.go b/api/types/helmchartargs.go index 9c1c06aac..693012275 100644 --- a/api/types/helmchartargs.go +++ b/api/types/helmchartargs.go @@ -72,6 +72,10 @@ type HelmChart struct { // IncludeCRDs specifies if Helm should also generate CustomResourceDefinitions. // Defaults to 'false'. IncludeCRDs bool `json:"includeCRDs,omitempty" yaml:"includeCRDs,omitempty"` //nolint: tagliatelle + + // SkipHooks sets the --no-hooks flag when calling helm template. This prevents + // helm from erroneously rendering test templates. + SkipHooks bool `json:"skipHooks,omitempty" yaml:"skipHooks,omitempty"` } // HelmChartArgs contains arguments to helm. diff --git a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go index 41e6ffac7..5d41b3dcd 100644 --- a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go +++ b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go @@ -287,6 +287,9 @@ func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string { if p.IncludeCRDs { args = append(args, "--include-crds") } + if p.SkipHooks { + args = append(args, "--no-hooks") + } return args } diff --git a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go index 48d388920..0c2b4932c 100644 --- a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go +++ b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go @@ -526,6 +526,34 @@ valuesInline: th.AssertActualEqualsExpected(rm, "") } +func TestHelmChartInflationGeneratorWithSkipHooks(t *testing.T) { + th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t). + PrepBuiltin("HelmChartInflationGenerator") + defer th.Reset() + if err := th.ErrIfNoHelm(); err != nil { + t.Skip("skipping: " + err.Error()) + } + + // we choose this helm chart as it has the ability to turn + // everything off, except CRDs. + rm := th.LoadAndRunGenerator(` +apiVersion: builtin +kind: HelmChartInflationGenerator +metadata: + name: terraform +name: terraform +version: 1.0.0 +repo: https://helm.releases.hashicorp.com +releaseName: terraforming-mars +includeCRDs: false +skipHooks: true +valuesInline: + global: + enabled: false +`) + th.AssertActualEqualsExpected(rm, "") +} + func TestHelmChartInflationGeneratorWithIncludeCRDsNotSpecified(t *testing.T) { th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t). PrepBuiltin("HelmChartInflationGenerator")