fix more issue
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
		
							parent
							
								
									cc3202e9b9
								
							
						
					
					
						commit
						61b4199c80
					
				|  | @ -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.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.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.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.StringVar(&applyOptions.DiffDryRun, "diff-dry-run", "", "pass dry-run to helm-diff exec") | ||||||
| 	f.Lookup("dry-run").NoOptDefVal = "client" | 	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 | 	return cmd | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -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.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.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.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 | 	return cmd | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1424,6 +1424,7 @@ func (a *App) apply(r *Run, c ApplyConfigProvider) (bool, bool, []error) { | ||||||
| 		PostRenderer:            c.PostRenderer(), | 		PostRenderer:            c.PostRenderer(), | ||||||
| 		PostRendererArgs:        c.PostRendererArgs(), | 		PostRendererArgs:        c.PostRendererArgs(), | ||||||
| 		SuppressOutputLineRegex: c.SuppressOutputLineRegex(), | 		SuppressOutputLineRegex: c.SuppressOutputLineRegex(), | ||||||
|  | 		DryRun:                  c.DryRun("diff"), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	infoMsg, releasesToBeUpdated, releasesToBeDeleted, errs := r.diff(false, detailedExitCode, c, diffOpts) | 	infoMsg, releasesToBeUpdated, releasesToBeDeleted, errs := r.diff(false, detailedExitCode, c, diffOpts) | ||||||
|  | @ -1536,7 +1537,7 @@ Do you really want to apply? | ||||||
| 					PostRenderer:     c.PostRenderer(), | 					PostRenderer:     c.PostRenderer(), | ||||||
| 					PostRendererArgs: c.PostRendererArgs(), | 					PostRendererArgs: c.PostRendererArgs(), | ||||||
| 					SyncArgs:         c.SyncArgs(), | 					SyncArgs:         c.SyncArgs(), | ||||||
| 					DryRun:           c.DryRun(), | 					DryRun:           c.DryRun("sync"), | ||||||
| 				} | 				} | ||||||
| 				return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), syncOpts) | 				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(), | 			PostRenderer:            c.PostRenderer(), | ||||||
| 			PostRendererArgs:        c.PostRendererArgs(), | 			PostRendererArgs:        c.PostRendererArgs(), | ||||||
| 			SuppressOutputLineRegex: c.SuppressOutputLineRegex(), | 			SuppressOutputLineRegex: c.SuppressOutputLineRegex(), | ||||||
|  | 			DryRun:                  c.DryRun("diff"), | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		filtered := &Run{ | 		filtered := &Run{ | ||||||
|  | @ -1930,7 +1932,7 @@ Do you really want to sync? | ||||||
| 					PostRenderer:     c.PostRenderer(), | 					PostRenderer:     c.PostRenderer(), | ||||||
| 					PostRendererArgs: c.PostRendererArgs(), | 					PostRendererArgs: c.PostRendererArgs(), | ||||||
| 					SyncArgs:         c.SyncArgs(), | 					SyncArgs:         c.SyncArgs(), | ||||||
| 					DryRun:           c.DryRun(), | 					DryRun:           c.DryRun("sync"), | ||||||
| 				} | 				} | ||||||
| 				return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), opts) | 				return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), opts) | ||||||
| 			})) | 			})) | ||||||
|  |  | ||||||
|  | @ -2196,7 +2196,8 @@ func (c configImpl) ShowOnly() []string { | ||||||
| type applyConfig struct { | type applyConfig struct { | ||||||
| 	args       string | 	args       string | ||||||
| 	cascade    string | 	cascade    string | ||||||
| 	dryRun  string | 	diffDryRun string | ||||||
|  | 	syncDryRun string | ||||||
| 	values     []string | 	values     []string | ||||||
| 
 | 
 | ||||||
| 	// TODO: Remove this function once Helmfile v0.x
 | 	// TODO: Remove this function once Helmfile v0.x
 | ||||||
|  | @ -2416,8 +2417,15 @@ func (a applyConfig) ShowOnly() []string { | ||||||
| 	return a.showOnly | 	return a.showOnly | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (a applyConfig) DryRun() string { | func (a applyConfig) DryRun(stage string) string { | ||||||
| 	return a.dryRun | 	switch stage { | ||||||
|  | 	case "diff": | ||||||
|  | 		return a.diffDryRun | ||||||
|  | 	case "sync": | ||||||
|  | 		return a.syncDryRun | ||||||
|  | 	default: | ||||||
|  | 		return "" | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type depsConfig struct { | type depsConfig struct { | ||||||
|  |  | ||||||
|  | @ -52,7 +52,7 @@ type ApplyConfigProvider interface { | ||||||
| 	PostRendererArgs() []string | 	PostRendererArgs() []string | ||||||
| 	Cascade() string | 	Cascade() string | ||||||
| 	SuppressOutputLineRegex() []string | 	SuppressOutputLineRegex() []string | ||||||
| 	DryRun() string | 	DryRun(string) string | ||||||
| 
 | 
 | ||||||
| 	Values() []string | 	Values() []string | ||||||
| 	Set() []string | 	Set() []string | ||||||
|  | @ -100,7 +100,7 @@ type SyncConfigProvider interface { | ||||||
| 	PostRenderer() string | 	PostRenderer() string | ||||||
| 	PostRendererArgs() []string | 	PostRendererArgs() []string | ||||||
| 	Cascade() string | 	Cascade() string | ||||||
| 	DryRun() string | 	DryRun(string) string | ||||||
| 
 | 
 | ||||||
| 	Values() []string | 	Values() []string | ||||||
| 	Set() []string | 	Set() []string | ||||||
|  | @ -134,6 +134,7 @@ type DiffConfigProvider interface { | ||||||
| 	Validate() bool | 	Validate() bool | ||||||
| 	SkipCRDs() bool | 	SkipCRDs() bool | ||||||
| 	SkipDeps() bool | 	SkipDeps() bool | ||||||
|  | 	DryRun(string) string | ||||||
| 
 | 
 | ||||||
| 	IncludeTests() bool | 	IncludeTests() bool | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -44,6 +44,7 @@ type diffConfig struct { | ||||||
| 	skipDiffOnInstall       bool | 	skipDiffOnInstall       bool | ||||||
| 	reuseValues             bool | 	reuseValues             bool | ||||||
| 	logger                  *zap.SugaredLogger | 	logger                  *zap.SugaredLogger | ||||||
|  | 	dryRun                  string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (a diffConfig) Args() string { | func (a diffConfig) Args() string { | ||||||
|  | @ -174,6 +175,9 @@ func (a diffConfig) SuppressOutputLineRegex() []string { | ||||||
| 	return a.suppressOutputLineRegex | 	return a.suppressOutputLineRegex | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (a diffConfig) DryRun(string) string { | ||||||
|  | 	return a.dryRun | ||||||
|  | } | ||||||
| func TestDiff(t *testing.T) { | func TestDiff(t *testing.T) { | ||||||
| 	type flags struct { | 	type flags struct { | ||||||
| 		skipNeeds    bool | 		skipNeeds    bool | ||||||
|  |  | ||||||
|  | @ -66,8 +66,10 @@ type ApplyOptions struct { | ||||||
| 	SuppressOutputLineRegex []string | 	SuppressOutputLineRegex []string | ||||||
| 	// SyncArgs is the list of arguments to pass to helm upgrade.
 | 	// SyncArgs is the list of arguments to pass to helm upgrade.
 | ||||||
| 	SyncArgs string | 	SyncArgs string | ||||||
| 	// DryRun is for helm dry-run flag
 | 	// DiffDryRun is for helm dry-run flag
 | ||||||
| 	DryRun string | 	DiffDryRun string | ||||||
|  | 	// SyncDryRun is for helm dry-run flag
 | ||||||
|  | 	SyncDryRun string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // NewApply creates a new Apply
 | // NewApply creates a new Apply
 | ||||||
|  | @ -250,7 +252,14 @@ func (a *ApplyImpl) SyncArgs() string { | ||||||
| 	return a.ApplyOptions.SyncArgs | 	return a.ApplyOptions.SyncArgs | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // DryRun returns dry-run flag
 | // DiffDryRun returns dry-run flag
 | ||||||
| func (a *ApplyImpl) DryRun() string { | func (a *ApplyImpl) DryRun(stage string) string { | ||||||
| 	return a.ApplyOptions.DryRun | 	switch stage { | ||||||
|  | 	case "diff": | ||||||
|  | 		return a.ApplyOptions.DiffDryRun | ||||||
|  | 	case "sync": | ||||||
|  | 		return a.ApplyOptions.SyncDryRun | ||||||
|  | 	default: | ||||||
|  | 		return "" | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -48,6 +48,8 @@ type DiffOptions struct { | ||||||
| 	DiffArgs string | 	DiffArgs string | ||||||
| 	// SuppressOutputLineRegex is a list of regexes to suppress output lines
 | 	// SuppressOutputLineRegex is a list of regexes to suppress output lines
 | ||||||
| 	SuppressOutputLineRegex []string | 	SuppressOutputLineRegex []string | ||||||
|  | 	// DryRun is for helm-diff dry-run flag
 | ||||||
|  | 	DryRun string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // NewDiffOptions creates a new Apply
 | // NewDiffOptions creates a new Apply
 | ||||||
|  | @ -199,3 +201,8 @@ func (t *DiffImpl) PostRendererArgs() []string { | ||||||
| func (t *DiffImpl) SuppressOutputLineRegex() []string { | func (t *DiffImpl) SuppressOutputLineRegex() []string { | ||||||
| 	return t.DiffOptions.SuppressOutputLineRegex | 	return t.DiffOptions.SuppressOutputLineRegex | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | // DryRun returns dry-run flag
 | ||||||
|  | func (t *DiffImpl) DryRun(string) string { | ||||||
|  | 	return t.DiffOptions.DryRun | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -143,6 +143,6 @@ func (t *SyncImpl) SyncArgs() string { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // DryRun returns dry-run flag
 | // DryRun returns dry-run flag
 | ||||||
| func (t *SyncImpl) DryRun() string { | func (t *SyncImpl) DryRun(string) string { | ||||||
| 	return t.SyncOptions.DryRun | 	return t.SyncOptions.DryRun | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -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.
 | // 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.
 | // 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.
 | // 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") { | 	if !helm.IsVersionAtLeast("3.13.0") { | ||||||
| 		return flags | 		return flags | ||||||
| 	} | 	} | ||||||
| 	if opt != nil && opt.DryRun != "" { | 	if dryRun != "" { | ||||||
| 		flags = append(flags, fmt.Sprintf("--dry-run=%s", opt.DryRun)) | 		flags = append(flags, fmt.Sprintf("--dry-run=%s", dryRun)) | ||||||
| 	} | 	} | ||||||
| 	return flags | 	return flags | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -328,9 +328,7 @@ func TestAppendDryRunFlags(t *testing.T) { | ||||||
| 	for _, tt := range tests { | 	for _, tt := range tests { | ||||||
| 		t.Run(tt.name, func(t *testing.T) { | 		t.Run(tt.name, func(t *testing.T) { | ||||||
| 			st := &HelmState{} | 			st := &HelmState{} | ||||||
| 			got := st.appendDryRunFlags([]string{}, tt.args.helm, &SyncOpts{ | 			got := st.appendDryRunFlags([]string{}, tt.args.helm, tt.args.dryRun) | ||||||
| 				DryRun: tt.args.dryRun, |  | ||||||
| 			}) |  | ||||||
| 			require.Equalf(t, tt.args.expected, got, "appendDryRunFlags() = %v, want %v", got, tt.args.expected) | 			require.Equalf(t, tt.args.expected, got, "appendDryRunFlags() = %v, want %v", got, tt.args.expected) | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -1967,6 +1967,7 @@ type DiffOpts struct { | ||||||
| 	PostRenderer            string | 	PostRenderer            string | ||||||
| 	PostRendererArgs        []string | 	PostRendererArgs        []string | ||||||
| 	SuppressOutputLineRegex []string | 	SuppressOutputLineRegex []string | ||||||
|  | 	DryRun                  string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (o *DiffOpts) Apply(opts *DiffOpts) { | func (o *DiffOpts) Apply(opts *DiffOpts) { | ||||||
|  | @ -2673,7 +2674,9 @@ func (st *HelmState) flagsForUpgrade(helm helmexec.Interface, release *ReleaseSp | ||||||
| 		postRendererArgs = opt.PostRendererArgs | 		postRendererArgs = opt.PostRendererArgs | ||||||
| 	} | 	} | ||||||
| 	flags = st.appendPostRenderArgsFlags(flags, release, 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) | 	flags = st.appendExtraSyncFlags(flags, opt) | ||||||
| 
 | 
 | ||||||
|  | @ -2795,6 +2798,9 @@ func (st *HelmState) flagsForDiff(helm helmexec.Interface, release *ReleaseSpec, | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, files, err | 		return nil, files, err | ||||||
| 	} | 	} | ||||||
|  | 	if opt != nil && opt.DryRun != "" { | ||||||
|  | 		flags = st.appendDryRunFlags(flags, helm, opt.DryRun) | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	return append(flags, common...), files, nil | 	return append(flags, common...), files, nil | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue