fix validate options

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2025-11-09 12:10:51 +08:00
parent c506caa33f
commit a38b07bd4a
8 changed files with 19 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 {

View File

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