diff --git a/pkg/app/app_test.go b/pkg/app/app_test.go index cf38aa2e..c9216cb8 100644 --- a/pkg/app/app_test.go +++ b/pkg/app/app_test.go @@ -2588,7 +2588,7 @@ func (helm *mockHelmExec) Fetch(chart string, flags ...string) error { func (helm *mockHelmExec) Lint(name, chart string, flags ...string) error { return nil } -func (helm *mockHelmExec) IsHelm3() bool { +func (helm *mockHelmExec) IsOverHelm3() bool { return true } diff --git a/pkg/app/run.go b/pkg/app/run.go index 2beab11a..1860ad1d 100644 --- a/pkg/app/run.go +++ b/pkg/app/run.go @@ -28,7 +28,7 @@ func NewRun(st *state.HelmState, helm helmexec.Interface, ctx Context) (*Run, er return nil, fmt.Errorf("Assertion failed: helmexec.Interface must not be nil") } - if !helm.IsHelm3() { + if !helm.IsOverHelm3() { return nil, fmt.Errorf("helmfile has deprecated helm2 since v0.150.0") } diff --git a/pkg/exectest/helm.go b/pkg/exectest/helm.go index 5857d398..2af1316d 100644 --- a/pkg/exectest/helm.go +++ b/pkg/exectest/helm.go @@ -206,7 +206,7 @@ func (helm *Helm) ChartPull(chart string, path string, flags ...string) error { func (helm *Helm) ChartExport(chart string, path string) error { return nil } -func (helm *Helm) IsHelm3() bool { +func (helm *Helm) IsOverHelm3() bool { if helm.Version == nil { return helm.Helm3 } diff --git a/pkg/helmexec/exec.go b/pkg/helmexec/exec.go index 08001a4f..410050d7 100644 --- a/pkg/helmexec/exec.go +++ b/pkg/helmexec/exec.go @@ -646,7 +646,7 @@ func (helm *execer) write(w io.Writer, out []byte) { } } -func (helm *execer) IsHelm3() bool { +func (helm *execer) IsOverHelm3() bool { return helm.version.Major() >= 3 } diff --git a/pkg/helmexec/exec_test.go b/pkg/helmexec/exec_test.go index 045d9248..f81eaf95 100644 --- a/pkg/helmexec/exec_test.go +++ b/pkg/helmexec/exec_test.go @@ -1063,14 +1063,14 @@ exec: helm --kubeconfig config --kube-context dev template release https://examp } } -func Test_IsHelm3(t *testing.T) { +func Test_IsOverHelm3(t *testing.T) { helm2Runner := mockRunner{output: []byte("Client: v2.16.0+ge13bc94\n")} helm, err := New("helm", HelmExecOptions{}, NewLogger(os.Stdout, "info"), "", "dev", &helm2Runner) if err != nil { t.Errorf("unexpected error: %v", err) } - if helm.IsHelm3() { - t.Error("helmexec.IsHelm3() - Detected Helm 3 with Helm 2 version") + if helm.IsOverHelm3() { + t.Error("helmexec.IsOverHelm3() - Detected Helm 3 with Helm 2 version") } helm3Runner := mockRunner{output: []byte("v3.0.0+ge29ce2a\n")} @@ -1078,8 +1078,8 @@ func Test_IsHelm3(t *testing.T) { if err != nil { t.Errorf("unexpected error: %v", err) } - if !helm.IsHelm3() { - t.Error("helmexec.IsHelm3() - Failed to detect Helm 3") + if !helm.IsOverHelm3() { + t.Error("helmexec.IsOverHelm3() - Failed to detect Helm 3") } } diff --git a/pkg/helmexec/helmexec.go b/pkg/helmexec/helmexec.go index 62cc2aa1..74e58c7a 100644 --- a/pkg/helmexec/helmexec.go +++ b/pkg/helmexec/helmexec.go @@ -33,7 +33,7 @@ type Interface interface { TestRelease(context HelmContext, name string, flags ...string) error List(context HelmContext, filter string, flags ...string) (string, error) DecryptSecret(context HelmContext, name string, flags ...string) (string, error) - IsHelm3() bool + IsOverHelm3() bool GetVersion() Version IsVersionAtLeast(versionStr string) bool ShowChart(chart string) (chart.Metadata, error) @@ -41,5 +41,5 @@ type Interface interface { type DependencyUpdater interface { UpdateDeps(chart string) error - IsHelm3() bool + IsOverHelm3() bool } diff --git a/pkg/state/state.go b/pkg/state/state.go index d8e4013c..204ec2b1 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -576,7 +576,7 @@ func (st *HelmState) ApplyOverrides(spec *ReleaseSpec) { } type RepoUpdater interface { - IsHelm3() bool + IsOverHelm3() bool AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials, skipTLSVerify bool) error UpdateRepo() error RegistryLogin(name, username, password, caFile, certFile, keyFile string, skipTLSVerify bool) error @@ -1640,7 +1640,11 @@ func (st *HelmState) TemplateReleases(helm helmexec.Interface, outputDir string, } if validate { - flags = append(flags, "--validate") + if helm.IsVersionAtLeast("4.0.0") { + flags = append(flags, "--dry-run=server") + } else { + flags = append(flags, "--validate") + } } if opts.IncludeCRDs { diff --git a/pkg/testutil/mocks.go b/pkg/testutil/mocks.go index 507dd8d4..0d434bf5 100644 --- a/pkg/testutil/mocks.go +++ b/pkg/testutil/mocks.go @@ -28,7 +28,7 @@ func NewVersionHelmExec(version string) *VersionHelmExec { return &VersionHelmExec{noCallHelmExec: &noCallHelmExec{}, version: version} } -func (helm *V3HelmExec) IsHelm3() bool { +func (helm *V3HelmExec) IsOverHelm3() bool { return helm.isHelm3 } @@ -127,7 +127,7 @@ func (helm *noCallHelmExec) Lint(name, chart string, flags ...string) error { helm.doPanic() return nil } -func (helm *noCallHelmExec) IsHelm3() bool { +func (helm *noCallHelmExec) IsOverHelm3() bool { helm.doPanic() return false }