mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 01:39:06 +00:00
Add includeCRDs Field to HelmChart
This commit adds functionality for a user to specify that `helm` should include CRDs when inflating a Helm Chart. As of Helm v3, the `install-crd` hook is no more, with `CustomResourceDefinitions` existing in the root of the chart, under the `crds` directory. When calling `helm template`, `helm` does not output these CRDs unless the user passes the `--include-crds` flag to the command. With this commit, users can set `includeCRDs: true` as part of their helm chart definition in `kustomize.yaml` to have these included as part of the output. Signed-off-by: Devon Mizelle <devon.mizelle@onepeloton.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package main_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@@ -458,3 +459,92 @@ valuesMerge: replace
|
||||
111, // memory
|
||||
))
|
||||
}
|
||||
|
||||
func TestHelmChartInflationGeneratorWithIncludeCRDs(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 store this data outside of the _test.go file as its sort of huge
|
||||
// and has backticks, which makes string literals wonky
|
||||
testData, err := ioutil.ReadFile("include_crds_testdata.txt")
|
||||
if err != nil {
|
||||
t.Errorf("unable to read test data for includeCRDs: %w", err)
|
||||
}
|
||||
|
||||
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: true
|
||||
valuesInline:
|
||||
global:
|
||||
enabled: false
|
||||
tests:
|
||||
enabled: false
|
||||
`)
|
||||
th.AssertActualEqualsExpected(rm, string(testData))
|
||||
}
|
||||
|
||||
func TestHelmChartInflationGeneratorWithExcludeCRDs(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
|
||||
valuesInline:
|
||||
global:
|
||||
enabled: false
|
||||
tests:
|
||||
enabled: false
|
||||
`)
|
||||
th.AssertActualEqualsExpected(rm, "")
|
||||
}
|
||||
|
||||
func TestHelmChartInflationGeneratorWithIncludeCRDsNotSpecified(t *testing.T) {
|
||||
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t).
|
||||
PrepBuiltin("HelmChartInflationGenerator")
|
||||
defer th.Reset()
|
||||
if err := th.ErrIfNoHelm(); err != nil {
|
||||
t.Skip("skipping: " + err.Error())
|
||||
}
|
||||
|
||||
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
|
||||
valuesInline:
|
||||
global:
|
||||
enabled: false
|
||||
tests:
|
||||
enabled: false
|
||||
`)
|
||||
th.AssertActualEqualsExpected(rm, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user