From 57a30565ec93f0052d4ad3a33efadd58af1caa8a Mon Sep 17 00:00:00 2001 From: isarns Date: Tue, 25 Feb 2025 21:30:36 +0200 Subject: [PATCH] feat(helm): add --not-in-schema flag --- api/types/helmchartargs.go | 7 ++++ api/types/helmchartargs_test.go | 17 ++++++++ .../HelmChartInflationGenerator_test.go | 40 +++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/api/types/helmchartargs.go b/api/types/helmchartargs.go index 86afc52cf2..ad99a000a6 100644 --- a/api/types/helmchartargs.go +++ b/api/types/helmchartargs.go @@ -102,6 +102,9 @@ type HelmChart struct { // allow for devel release to be used. Devel bool `json:"devel,omitempty" yaml:"devel,omitempty"` + + // SkipSchemaValidation disables JSON schema validation + SkipSchemaValidation bool `json:"skipSchemaValidation,omitempty" yaml:"skipSchemaValidation,omitempty"` } // HelmChartArgs contains arguments to helm. @@ -200,5 +203,9 @@ func (h HelmChart) AsHelmArgs(absChartHome string) []string { if h.Devel { args = append(args, "--devel") } + + if h.SkipSchemaValidation { + args = append(args, "--skip-schema-validation") + } return args } diff --git a/api/types/helmchartargs_test.go b/api/types/helmchartargs_test.go index fd9a7a79a1..ca0f8c7ede 100644 --- a/api/types/helmchartargs_test.go +++ b/api/types/helmchartargs_test.go @@ -101,4 +101,21 @@ func TestAsHelmArgs(t *testing.T) { "-f", "values2", "--devel"}) }) + + t.Run("use skip-schema-validation", func(t *testing.T) { + p := types.HelmChart{ + Name: "chart-name", + Version: "1.0.0", + Repo: "https://helm.releases.hashicorp.com", + ValuesFile: "values", + AdditionalValuesFiles: []string{"values1", "values2"}, + SkipSchemaValidation: true, + } + require.Equal(t, p.AsHelmArgs("/home/charts"), + []string{"template", "--generate-name", "/home/charts/chart-name", + "-f", "values", + "-f", "values1", + "-f", "values2", + "--skip-schema-validation"}) + }) } diff --git a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go index 1e06d4c0a0..7d92f5c14c 100644 --- a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go +++ b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go @@ -1027,3 +1027,43 @@ devel: true assert.Contains(t, string(chartYamlContent), "name: sm-operator") assert.Contains(t, string(chartYamlContent), "version: 0.1.0-Beta") } + +func TestHelmChartInflationGeneratorWithSkipSchemaValidation(t *testing.T) { + th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t). + PrepBuiltin("HelmChartInflationGenerator") + defer th.Reset() + if err := th.ErrIfNoHelm(); err != nil { + t.Skip("skipping: " + err.Error()) + } + copyTestChartsIntoHarness(t, th) + + // minecraftServer.eula must be one of the following: "true", "TRUE", "false", "FALSE" + rm := th.LoadAndRunGenerator(` +apiVersion: builtin +kind: HelmChartInflationGenerator +metadata: + name: myMc +name: minecraft +version: 4.23.7 +repo: https://itzg.github.io/minecraft-server-charts +releaseName: isarns +valuesInline: + minecraftServer: + eula: not-in-schema + difficulty: hard + rcon: + enabled: true + resources: + requests: + cpu: 555m + memory: 111Mi +skipSchemaValidation: true +`) + + cm, err := rm.Resources()[0].GetFieldValue("metadata.name") + require.NoError(t, err) + assert.Equal(t, "isarns-minecraft-rcon", cm) + cm, err =rm.Resources()[4].GetFieldValue("spec.template.spec.containers[0].env[0].value") + require.NoError(t, err) + assert.Equal(t, "not-in-schema", cm) +} \ No newline at end of file