Skip to content

Commit

Permalink
feat(helm): add --not-in-schema flag
Browse files Browse the repository at this point in the history
  • Loading branch information
isarns committed Feb 25, 2025
1 parent 447a609 commit b6dd2a6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/types/helmchartargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ type HelmChart struct {

// debug enables debug output from the Helm chart inflator generator.
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"`

// SkipSchemaValidation disables JSON schema validation
SkipSchemaValidation bool `json:"skipSchemaValidation,omitempty" yaml:"skipSchemaValidation,omitempty"`
}

// HelmChartArgs contains arguments to helm.
Expand Down Expand Up @@ -194,5 +197,8 @@ func (h HelmChart) AsHelmArgs(absChartHome string) []string {
if h.Debug {
args = append(args, "--debug")
}
if h.SkipSchemaValidation {
args = append(args, "--skip-schema-validation")
}
return args
}
17 changes: 17 additions & 0 deletions api/types/helmchartargs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,21 @@ func TestAsHelmArgs(t *testing.T) {
"-f", "values2",
"--debug"})
})

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"})
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -993,3 +993,43 @@ debug: true
assert.Contains(t, string(chartYamlContent), "name: test-chart")
assert.Contains(t, string(chartYamlContent), "version: 1.0.0")
}

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)
}

0 comments on commit b6dd2a6

Please sign in to comment.