fix(state): honor skipSchemaValidation in chartify template args
Agent-Logs-Url: https://github.com/helmfile/helmfile/sessions/a695cbff-c37a-403a-9658-09f4fdaa65d0 Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>
This commit is contained in:
parent
8d24c037ed
commit
715fb7b758
|
|
@ -135,20 +135,28 @@ func (st *HelmState) appendPostRenderArgsFlags(flags []string, release *ReleaseS
|
|||
|
||||
// append skip-schema-validation flags to helm flags
|
||||
func (st *HelmState) appendSkipSchemaValidationFlags(flags []string, release *ReleaseSpec, skipSchemaValidation bool) []string {
|
||||
switch {
|
||||
// Check if SkipSchemaValidation is true in the release spec.
|
||||
case release.SkipSchemaValidation != nil && *release.SkipSchemaValidation:
|
||||
flags = append(flags, "--skip-schema-validation")
|
||||
// Check if skipSchemaValidation argument is true.
|
||||
case skipSchemaValidation:
|
||||
flags = append(flags, "--skip-schema-validation")
|
||||
// Check if SkipSchemaValidation is true in HelmDefaults.
|
||||
case st.HelmDefaults.SkipSchemaValidation != nil && *st.HelmDefaults.SkipSchemaValidation:
|
||||
if st.shouldSkipSchemaValidation(release, skipSchemaValidation) {
|
||||
flags = append(flags, "--skip-schema-validation")
|
||||
}
|
||||
return flags
|
||||
}
|
||||
|
||||
func (st *HelmState) shouldSkipSchemaValidation(release *ReleaseSpec, skipSchemaValidation bool) bool {
|
||||
switch {
|
||||
// Check if SkipSchemaValidation is true in the release spec.
|
||||
case release.SkipSchemaValidation != nil && *release.SkipSchemaValidation:
|
||||
return true
|
||||
// Check if skipSchemaValidation argument is true.
|
||||
case skipSchemaValidation:
|
||||
return true
|
||||
// Check if SkipSchemaValidation is true in HelmDefaults.
|
||||
case st.HelmDefaults.SkipSchemaValidation != nil && *st.HelmDefaults.SkipSchemaValidation:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// append suppress-output-line-regex flags to helm diff flags
|
||||
func (st *HelmState) appendSuppressOutputLineRegexFlags(flags []string, release *ReleaseSpec, suppressOutputLineRegex []string) []string {
|
||||
suppressOutputLineRegexFlags := []string{}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
package state
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestAppendSkipSchemaValidationFlagToChartifyTemplateArgs(t *testing.T) {
|
||||
enable := true
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
defaults HelmSpec
|
||||
release *ReleaseSpec
|
||||
templateArgs string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "adds flag from release setting",
|
||||
release: &ReleaseSpec{
|
||||
SkipSchemaValidation: &enable,
|
||||
},
|
||||
want: "--skip-schema-validation",
|
||||
},
|
||||
{
|
||||
name: "adds flag from helm defaults",
|
||||
defaults: HelmSpec{
|
||||
SkipSchemaValidation: &enable,
|
||||
},
|
||||
release: &ReleaseSpec{},
|
||||
want: "--skip-schema-validation",
|
||||
},
|
||||
{
|
||||
name: "appends flag to existing args",
|
||||
release: &ReleaseSpec{
|
||||
SkipSchemaValidation: &enable,
|
||||
},
|
||||
templateArgs: "--kube-context default",
|
||||
want: "--kube-context default --skip-schema-validation",
|
||||
},
|
||||
{
|
||||
name: "does not duplicate existing flag",
|
||||
release: &ReleaseSpec{
|
||||
SkipSchemaValidation: &enable,
|
||||
},
|
||||
templateArgs: "--skip-schema-validation --kube-context default",
|
||||
want: "--skip-schema-validation --kube-context default",
|
||||
},
|
||||
{
|
||||
name: "does not add flag when disabled",
|
||||
release: &ReleaseSpec{},
|
||||
templateArgs: "--kube-context default",
|
||||
want: "--kube-context default",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
st := &HelmState{
|
||||
ReleaseSetSpec: ReleaseSetSpec{
|
||||
HelmDefaults: tt.defaults,
|
||||
},
|
||||
}
|
||||
|
||||
got := st.appendSkipSchemaValidationFlagToChartifyTemplateArgs(tt.templateArgs, tt.release)
|
||||
if got != tt.want {
|
||||
t.Fatalf("appendSkipSchemaValidationFlagToChartifyTemplateArgs() = %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1622,6 +1622,8 @@ func (st *HelmState) processChartification(chartification *Chartify, release *Re
|
|||
}
|
||||
}
|
||||
|
||||
chartifyOpts.TemplateArgs = st.appendSkipSchemaValidationFlagToChartifyTemplateArgs(chartifyOpts.TemplateArgs, release)
|
||||
|
||||
out, err := c.Chartify(release.Name, chartPath, chartify.WithChartifyOpts(chartifyOpts))
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
|
|
@ -1634,6 +1636,18 @@ func (st *HelmState) processChartification(chartification *Chartify, release *Re
|
|||
return chartPath, buildDeps, nil
|
||||
}
|
||||
|
||||
func (st *HelmState) appendSkipSchemaValidationFlagToChartifyTemplateArgs(templateArgs string, release *ReleaseSpec) string {
|
||||
if !st.shouldSkipSchemaValidation(release, false) || strings.Contains(templateArgs, "--skip-schema-validation") {
|
||||
return templateArgs
|
||||
}
|
||||
|
||||
if templateArgs == "" {
|
||||
return "--skip-schema-validation"
|
||||
}
|
||||
|
||||
return templateArgs + " --skip-schema-validation"
|
||||
}
|
||||
|
||||
// processLocalChart handles local chart processing
|
||||
func (st *HelmState) processLocalChart(normalizedChart, dir string, release *ReleaseSpec, helmfileCommand string, opts ChartPrepareOptions, isLocal bool) (string, error) {
|
||||
chartPath := normalizedChart
|
||||
|
|
|
|||
Loading…
Reference in New Issue