fix more issue

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2024-06-02 15:03:54 +08:00
parent cc3202e9b9
commit 61b4199c80
12 changed files with 64 additions and 25 deletions
+4 -2
View File
@@ -70,8 +70,10 @@ func NewApplyCmd(globalCfg *config.GlobalImpl) *cobra.Command {
f.StringArrayVar(&applyOptions.PostRendererArgs, "post-renderer-args", nil, `pass --post-renderer-args to "helm template" or "helm upgrade --install"`)
f.StringVar(&applyOptions.Cascade, "cascade", "", "pass cascade to helm exec, default: background")
f.StringArrayVar(&applyOptions.SuppressOutputLineRegex, "suppress-output-line-regex", nil, "a list of regex patterns to suppress output lines from the diff output")
f.StringVar(&applyOptions.DryRun, "dry-run", "", "pass dry-run to helm exec")
f.Lookup("dry-run").NoOptDefVal = "client"
f.StringVar(&applyOptions.DiffDryRun, "diff-dry-run", "", "pass dry-run to helm-diff exec")
f.Lookup("diff-dry-run").NoOptDefVal = "client"
f.StringVar(&applyOptions.DiffDryRun, "sync-dry-run", "", "pass dry-run to helm exec")
f.Lookup("sync-dry-run").NoOptDefVal = "client"
return cmd
}
+2
View File
@@ -55,6 +55,8 @@ func NewDiffCmd(globalCfg *config.GlobalImpl) *cobra.Command {
f.StringVar(&diffOptions.PostRenderer, "post-renderer", "", `pass --post-renderer to "helm template" or "helm upgrade --install"`)
f.StringArrayVar(&diffOptions.PostRendererArgs, "post-renderer-args", nil, `pass --post-renderer-args to "helm template" or "helm upgrade --install"`)
f.StringArrayVar(&diffOptions.SuppressOutputLineRegex, "suppress-output-line-regex", nil, "a list of regex patterns to suppress output lines from the diff output")
f.StringVar(&diffOptions.DryRun, "dry-run", "", "pass dry-run to helm-diff")
f.Lookup("dry-run").NoOptDefVal = "client"
return cmd
}
+4 -2
View File
@@ -1424,6 +1424,7 @@ func (a *App) apply(r *Run, c ApplyConfigProvider) (bool, bool, []error) {
PostRenderer: c.PostRenderer(),
PostRendererArgs: c.PostRendererArgs(),
SuppressOutputLineRegex: c.SuppressOutputLineRegex(),
DryRun: c.DryRun("diff"),
}
infoMsg, releasesToBeUpdated, releasesToBeDeleted, errs := r.diff(false, detailedExitCode, c, diffOpts)
@@ -1536,7 +1537,7 @@ Do you really want to apply?
PostRenderer: c.PostRenderer(),
PostRendererArgs: c.PostRendererArgs(),
SyncArgs: c.SyncArgs(),
DryRun: c.DryRun(),
DryRun: c.DryRun("sync"),
}
return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), syncOpts)
}))
@@ -1663,6 +1664,7 @@ func (a *App) diff(r *Run, c DiffConfigProvider) (*string, bool, bool, []error)
PostRenderer: c.PostRenderer(),
PostRendererArgs: c.PostRendererArgs(),
SuppressOutputLineRegex: c.SuppressOutputLineRegex(),
DryRun: c.DryRun("diff"),
}
filtered := &Run{
@@ -1930,7 +1932,7 @@ Do you really want to sync?
PostRenderer: c.PostRenderer(),
PostRendererArgs: c.PostRendererArgs(),
SyncArgs: c.SyncArgs(),
DryRun: c.DryRun(),
DryRun: c.DryRun("sync"),
}
return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), opts)
}))
+14 -6
View File
@@ -2194,10 +2194,11 @@ func (c configImpl) ShowOnly() []string {
}
type applyConfig struct {
args string
cascade string
dryRun string
values []string
args string
cascade string
diffDryRun string
syncDryRun string
values []string
// TODO: Remove this function once Helmfile v0.x
retainValuesFiles bool
@@ -2416,8 +2417,15 @@ func (a applyConfig) ShowOnly() []string {
return a.showOnly
}
func (a applyConfig) DryRun() string {
return a.dryRun
func (a applyConfig) DryRun(stage string) string {
switch stage {
case "diff":
return a.diffDryRun
case "sync":
return a.syncDryRun
default:
return ""
}
}
type depsConfig struct {
+3 -2
View File
@@ -52,7 +52,7 @@ type ApplyConfigProvider interface {
PostRendererArgs() []string
Cascade() string
SuppressOutputLineRegex() []string
DryRun() string
DryRun(string) string
Values() []string
Set() []string
@@ -100,7 +100,7 @@ type SyncConfigProvider interface {
PostRenderer() string
PostRendererArgs() []string
Cascade() string
DryRun() string
DryRun(string) string
Values() []string
Set() []string
@@ -134,6 +134,7 @@ type DiffConfigProvider interface {
Validate() bool
SkipCRDs() bool
SkipDeps() bool
DryRun(string) string
IncludeTests() bool
+4
View File
@@ -44,6 +44,7 @@ type diffConfig struct {
skipDiffOnInstall bool
reuseValues bool
logger *zap.SugaredLogger
dryRun string
}
func (a diffConfig) Args() string {
@@ -174,6 +175,9 @@ func (a diffConfig) SuppressOutputLineRegex() []string {
return a.suppressOutputLineRegex
}
func (a diffConfig) DryRun(string) string {
return a.dryRun
}
func TestDiff(t *testing.T) {
type flags struct {
skipNeeds bool
+14 -5
View File
@@ -66,8 +66,10 @@ type ApplyOptions struct {
SuppressOutputLineRegex []string
// SyncArgs is the list of arguments to pass to helm upgrade.
SyncArgs string
// DryRun is for helm dry-run flag
DryRun string
// DiffDryRun is for helm dry-run flag
DiffDryRun string
// SyncDryRun is for helm dry-run flag
SyncDryRun string
}
// NewApply creates a new Apply
@@ -250,7 +252,14 @@ func (a *ApplyImpl) SyncArgs() string {
return a.ApplyOptions.SyncArgs
}
// DryRun returns dry-run flag
func (a *ApplyImpl) DryRun() string {
return a.ApplyOptions.DryRun
// DiffDryRun returns dry-run flag
func (a *ApplyImpl) DryRun(stage string) string {
switch stage {
case "diff":
return a.ApplyOptions.DiffDryRun
case "sync":
return a.ApplyOptions.SyncDryRun
default:
return ""
}
}
+7
View File
@@ -48,6 +48,8 @@ type DiffOptions struct {
DiffArgs string
// SuppressOutputLineRegex is a list of regexes to suppress output lines
SuppressOutputLineRegex []string
// DryRun is for helm-diff dry-run flag
DryRun string
}
// NewDiffOptions creates a new Apply
@@ -199,3 +201,8 @@ func (t *DiffImpl) PostRendererArgs() []string {
func (t *DiffImpl) SuppressOutputLineRegex() []string {
return t.DiffOptions.SuppressOutputLineRegex
}
// DryRun returns dry-run flag
func (t *DiffImpl) DryRun(string) string {
return t.DiffOptions.DryRun
}
+1 -1
View File
@@ -143,6 +143,6 @@ func (t *SyncImpl) SyncArgs() string {
}
// DryRun returns dry-run flag
func (t *SyncImpl) DryRun() string {
func (t *SyncImpl) DryRun(string) string {
return t.SyncOptions.DryRun
}
+3 -3
View File
@@ -109,12 +109,12 @@ 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, helm helmexec.Interface, opt *SyncOpts) []string {
func (st *HelmState) appendDryRunFlags(flags []string, helm helmexec.Interface, dryRun string) []string {
if !helm.IsVersionAtLeast("3.13.0") {
return flags
}
if opt != nil && opt.DryRun != "" {
flags = append(flags, fmt.Sprintf("--dry-run=%s", opt.DryRun))
if dryRun != "" {
flags = append(flags, fmt.Sprintf("--dry-run=%s", dryRun))
}
return flags
}
+1 -3
View File
@@ -328,9 +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{}, tt.args.helm, &SyncOpts{
DryRun: tt.args.dryRun,
})
got := st.appendDryRunFlags([]string{}, tt.args.helm, tt.args.dryRun)
require.Equalf(t, tt.args.expected, got, "appendDryRunFlags() = %v, want %v", got, tt.args.expected)
})
}
+7 -1
View File
@@ -1967,6 +1967,7 @@ type DiffOpts struct {
PostRenderer string
PostRendererArgs []string
SuppressOutputLineRegex []string
DryRun string
}
func (o *DiffOpts) Apply(opts *DiffOpts) {
@@ -2673,7 +2674,9 @@ func (st *HelmState) flagsForUpgrade(helm helmexec.Interface, release *ReleaseSp
postRendererArgs = opt.PostRendererArgs
}
flags = st.appendPostRenderArgsFlags(flags, release, postRendererArgs)
flags = st.appendDryRunFlags(flags, helm, opt)
if opt != nil && opt.DryRun != "" {
flags = st.appendDryRunFlags(flags, helm, opt.DryRun)
}
flags = st.appendExtraSyncFlags(flags, opt)
@@ -2795,6 +2798,9 @@ func (st *HelmState) flagsForDiff(helm helmexec.Interface, release *ReleaseSpec,
if err != nil {
return nil, files, err
}
if opt != nil && opt.DryRun != "" {
flags = st.appendDryRunFlags(flags, helm, opt.DryRun)
}
return append(flags, common...), files, nil
}