Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
Signed-off-by: yxxhero <[email protected]>
  • Loading branch information
yxxhero committed Feb 10, 2024
1 parent 7566731 commit 7b8468c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
18 changes: 10 additions & 8 deletions pkg/state/helmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,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
}
Expand All @@ -114,6 +115,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 != "":
Expand Down
35 changes: 15 additions & 20 deletions pkg/state/helmx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ func TestAppendDryRunFlags(t *testing.T) {
type args struct {
dryRun string
expected []string
helm helmexec.Interface
flags []string
}
tests := []struct {
name string
Expand All @@ -210,11 +212,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"},
},
Expand All @@ -223,38 +222,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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2581,7 +2581,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)

common, clean, err := st.namespaceAndValuesFlags(helm, release, workerIndex)
if err != nil {
Expand Down

0 comments on commit 7b8468c

Please sign in to comment.