fix issues

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2024-02-10 12:25:38 +08:00
parent ac25cc5d47
commit c710e2b01c
3 changed files with 26 additions and 29 deletions

View File

@ -109,15 +109,16 @@ 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") {
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 != "":
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 != "":

View File

@ -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,29 +301,25 @@ 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",
dryRun: "server",
helm: testutil.NewVersionHelmExec("3.12.1"),
expected: []string{},
},
@ -333,7 +328,7 @@ func TestAppendDryRunFlags(t *testing.T) {
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)

View File

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