From c710e2b01cea83fc6e3baf75a1db638e85651b1d Mon Sep 17 00:00:00 2001 From: yxxhero Date: Sat, 10 Feb 2024 12:25:38 +0800 Subject: [PATCH] fix issues Signed-off-by: yxxhero --- pkg/state/helmx.go | 18 ++++++++++-------- pkg/state/helmx_test.go | 35 +++++++++++++++-------------------- pkg/state/state.go | 2 +- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/pkg/state/helmx.go b/pkg/state/helmx.go index 0f727e06..9f9ec485 100644 --- a/pkg/state/helmx.go +++ b/pkg/state/helmx.go @@ -109,14 +109,15 @@ func (st *HelmState) appendWaitFlags(flags []string, release *ReleaseSpec, ops * // appendDryRunFlags appends the necessary flags for a dry run to the given flags slice. // If the opt parameter is not nil and opt.DryRun is not empty, the "--dry-run" flag and the value of opt.DryRun are appended to the flags slice. // The updated flags slice is returned. -func (st *HelmState) appendDryRunFlags(flags []string, opt *SyncOpts) []string { - if helm.IsVersionAtLeast("3.13.0") { - switch { - case opt != nil && opt.DryRun != "": - flags = append(flags, "--dry-run", opt.DryRun) - case opt != nil && opt.DryRun != "": - flags = append(flags, "--dry-run", "client") - } +func (st *HelmState) appendDryRunFlags(flags []string, helm helmexec.Interface, opt *SyncOpts) []string { + if !helm.IsVersionAtLeast("3.13.0") { + return flags + } + switch { + case opt != nil && opt.DryRun != "": + flags = append(flags, "--dry-run", opt.DryRun) + case opt != nil && opt.DryRun == "": + flags = append(flags, "--dry-run", "client") } return flags } @@ -127,6 +128,7 @@ func (st *HelmState) appendCascadeFlags(flags []string, helm helmexec.Interface, if !helm.IsVersionAtLeast("3.12.1") { return flags } + switch { // postRenderer arg comes from cmd flag. case release.Cascade != nil && *release.Cascade != "": diff --git a/pkg/state/helmx_test.go b/pkg/state/helmx_test.go index 6c326cee..ef27a4d8 100644 --- a/pkg/state/helmx_test.go +++ b/pkg/state/helmx_test.go @@ -281,6 +281,8 @@ func TestAppendDryRunFlags(t *testing.T) { type args struct { dryRun string expected []string + helm helmexec.Interface + flags []string } tests := []struct { name string @@ -289,11 +291,8 @@ func TestAppendDryRunFlags(t *testing.T) { { name: "do dry-run on client", args: args{ -<<<<<<< Updated upstream - dryRun: "client", -======= flags: []string{}, - dry-run: "client", + dryRun: "client", helm: testutil.NewVersionHelmExec("3.13.0"), expected: []string{"--dry-run", "client"}, }, @@ -302,38 +301,34 @@ func TestAppendDryRunFlags(t *testing.T) { name: "empty dry-run means client", args: args{ flags: []string{}, - dry-run: "", + dryRun: "", helm: testutil.NewVersionHelmExec("3.13.0"), ->>>>>>> Stashed changes expected: []string{"--dry-run", "client"}, }, }, { name: "do dry-run on server", args: args{ -<<<<<<< Updated upstream - dryRun: "server", -======= flags: []string{}, - dry-run: "server", + dryRun: "server", helm: testutil.NewVersionHelmExec("3.13.0"), ->>>>>>> Stashed changes expected: []string{"--dry-run", "server"}, }, - { - name: "no version below 3.13.0", - args: args{ - flags: []string{}, - dry-run: "server", - helm: testutil.NewVersionHelmExec("3.12.1"), - expected: []string{}, - }, + }, + { + name: "no version below 3.13.0", + args: args{ + flags: []string{}, + dryRun: "server", + helm: testutil.NewVersionHelmExec("3.12.1"), + expected: []string{}, + }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { st := &HelmState{} - got := st.appendDryRunFlags([]string{}, &SyncOpts{ + got := st.appendDryRunFlags([]string{}, tt.args.helm, &SyncOpts{ DryRun: tt.args.dryRun, }) require.Equalf(t, tt.args.expected, got, "appendDryRunFlags() = %v, want %v", got, tt.args.expected) diff --git a/pkg/state/state.go b/pkg/state/state.go index 6e6395c2..56824cb9 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -2673,7 +2673,7 @@ func (st *HelmState) flagsForUpgrade(helm helmexec.Interface, release *ReleaseSp postRendererArgs = opt.PostRendererArgs } flags = st.appendPostRenderArgsFlags(flags, release, postRendererArgs) - flags = st.appendDryRunFlags(flags, opt) + flags = st.appendDryRunFlags(flags, helm, opt) flags = st.appendExtraSyncFlags(flags, opt)