Add hide notes support (#1710)
* add --hide-notes support Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
		
							parent
							
								
									fc9f0b66c0
								
							
						
					
					
						commit
						5c6572b492
					
				|  | @ -1537,6 +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(), | ||||||
|  | 					HideNotes:        c.HideNotes(), | ||||||
| 				} | 				} | ||||||
| 				return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), syncOpts) | 				return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), syncOpts) | ||||||
| 			})) | 			})) | ||||||
|  | @ -1930,6 +1931,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(), | ||||||
|  | 					HideNotes:        c.HideNotes(), | ||||||
| 				} | 				} | ||||||
| 				return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), opts) | 				return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), opts) | ||||||
| 			})) | 			})) | ||||||
|  |  | ||||||
|  | @ -2235,6 +2235,7 @@ type applyConfig struct { | ||||||
| 	kubeVersion             string | 	kubeVersion             string | ||||||
| 	suppressOutputLineRegex []string | 	suppressOutputLineRegex []string | ||||||
| 	showOnly                []string | 	showOnly                []string | ||||||
|  | 	hideNotes               bool | ||||||
| 
 | 
 | ||||||
| 	// template-only options
 | 	// template-only options
 | ||||||
| 	includeCRDs, skipTests       bool | 	includeCRDs, skipTests       bool | ||||||
|  | @ -2415,6 +2416,10 @@ func (a applyConfig) ShowOnly() []string { | ||||||
| 	return a.showOnly | 	return a.showOnly | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (a applyConfig) HideNotes() bool { | ||||||
|  | 	return a.hideNotes | ||||||
|  | } | ||||||
|  | 
 | ||||||
| type depsConfig struct { | type depsConfig struct { | ||||||
| 	skipRepos              bool | 	skipRepos              bool | ||||||
| 	includeTransitiveNeeds bool | 	includeTransitiveNeeds bool | ||||||
|  |  | ||||||
|  | @ -51,6 +51,7 @@ type ApplyConfigProvider interface { | ||||||
| 	PostRenderer() string | 	PostRenderer() string | ||||||
| 	PostRendererArgs() []string | 	PostRendererArgs() []string | ||||||
| 	Cascade() string | 	Cascade() string | ||||||
|  | 	HideNotes() bool | ||||||
| 	SuppressOutputLineRegex() []string | 	SuppressOutputLineRegex() []string | ||||||
| 
 | 
 | ||||||
| 	Values() []string | 	Values() []string | ||||||
|  | @ -98,6 +99,7 @@ type SyncConfigProvider interface { | ||||||
| 	Args() string | 	Args() string | ||||||
| 	PostRenderer() string | 	PostRenderer() string | ||||||
| 	PostRendererArgs() []string | 	PostRendererArgs() []string | ||||||
|  | 	HideNotes() bool | ||||||
| 	Cascade() string | 	Cascade() string | ||||||
| 
 | 
 | ||||||
| 	Values() []string | 	Values() []string | ||||||
|  |  | ||||||
|  | @ -66,6 +66,8 @@ 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 | ||||||
|  | 	// HideNotes is the hide notes flag
 | ||||||
|  | 	HideNotes bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // NewApply creates a new Apply
 | // NewApply creates a new Apply
 | ||||||
|  | @ -247,3 +249,7 @@ func (a *ApplyImpl) SuppressOutputLineRegex() []string { | ||||||
| func (a *ApplyImpl) SyncArgs() string { | func (a *ApplyImpl) SyncArgs() string { | ||||||
| 	return a.ApplyOptions.SyncArgs | 	return a.ApplyOptions.SyncArgs | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func (a *ApplyImpl) HideNotes() bool { | ||||||
|  | 	return a.ApplyOptions.HideNotes | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -34,6 +34,8 @@ type SyncOptions struct { | ||||||
| 	Cascade string | 	Cascade string | ||||||
| 	// SyncArgs is the list of arguments to pass to the helm upgrade command.
 | 	// SyncArgs is the list of arguments to pass to the helm upgrade command.
 | ||||||
| 	SyncArgs string | 	SyncArgs string | ||||||
|  | 	// HideNotes is the hide notes flag
 | ||||||
|  | 	HideNotes bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // NewSyncOptions creates a new Apply
 | // NewSyncOptions creates a new Apply
 | ||||||
|  | @ -139,3 +141,7 @@ func (t *SyncImpl) Cascade() string { | ||||||
| func (t *SyncImpl) SyncArgs() string { | func (t *SyncImpl) SyncArgs() string { | ||||||
| 	return t.SyncOptions.SyncArgs | 	return t.SyncOptions.SyncArgs | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func (t *SyncImpl) HideNotes() bool { | ||||||
|  | 	return t.SyncOptions.HideNotes | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -119,6 +119,19 @@ func (st *HelmState) appendCascadeFlags(flags []string, helm helmexec.Interface, | ||||||
| 	return flags | 	return flags | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // append hide-notes flags to helm flags
 | ||||||
|  | func (st *HelmState) appendHideNotesFlags(flags []string, helm helmexec.Interface, ops *SyncOpts) []string { | ||||||
|  | 	// see https://github.com/helm/helm/releases/tag/v3.16.0
 | ||||||
|  | 	if !helm.IsVersionAtLeast("3.16.0") { | ||||||
|  | 		return flags | ||||||
|  | 	} | ||||||
|  | 	switch { | ||||||
|  | 	case ops.HideNotes: | ||||||
|  | 		flags = append(flags, "--hide-notes") | ||||||
|  | 	} | ||||||
|  | 	return flags | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // append show-only flags to helm flags
 | // append show-only flags to helm flags
 | ||||||
| func (st *HelmState) appendShowOnlyFlags(flags []string, showOnly []string) []string { | func (st *HelmState) appendShowOnlyFlags(flags []string, showOnly []string) []string { | ||||||
| 	showOnlyFlags := []string{} | 	showOnlyFlags := []string{} | ||||||
|  |  | ||||||
|  | @ -276,3 +276,48 @@ func TestAppendShowOnlyFlags(t *testing.T) { | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func TestAppendHideNotesFlags(t *testing.T) { | ||||||
|  | 	type args struct { | ||||||
|  | 		flags    []string | ||||||
|  | 		helm     helmexec.Interface | ||||||
|  | 		helmSpec HelmSpec | ||||||
|  | 		opt      *SyncOpts | ||||||
|  | 		expected []string | ||||||
|  | 	} | ||||||
|  | 	tests := []struct { | ||||||
|  | 		name string | ||||||
|  | 		args args | ||||||
|  | 	}{ | ||||||
|  | 		{ | ||||||
|  | 			name: "no hide-notes when helm less than 3.16.0", | ||||||
|  | 			args: args{ | ||||||
|  | 				flags: []string{}, | ||||||
|  | 				helm:  testutil.NewVersionHelmExec("3.15.0"), | ||||||
|  | 				opt: &SyncOpts{ | ||||||
|  | 					HideNotes: true, | ||||||
|  | 				}, | ||||||
|  | 				expected: []string{}, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "hide-notes from cmd flag", | ||||||
|  | 			args: args{ | ||||||
|  | 				flags: []string{}, | ||||||
|  | 				helm:  testutil.NewVersionHelmExec("3.16.0"), | ||||||
|  | 				opt: &SyncOpts{ | ||||||
|  | 					HideNotes: true, | ||||||
|  | 				}, | ||||||
|  | 				expected: []string{"--hide-notes"}, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  | 	for _, tt := range tests { | ||||||
|  | 		t.Run(tt.name, func(t *testing.T) { | ||||||
|  | 			st := &HelmState{} | ||||||
|  | 			st.HelmDefaults = tt.args.helmSpec | ||||||
|  | 			got := st.appendHideNotesFlags(tt.args.flags, tt.args.helm, tt.args.opt) | ||||||
|  | 			require.Equalf(t, tt.args.expected, got, "appendHideNotesFlags() = %v, want %v", got, tt.args.expected) | ||||||
|  | 		}) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -774,6 +774,7 @@ type SyncOpts struct { | ||||||
| 	PostRenderer     string | 	PostRenderer     string | ||||||
| 	PostRendererArgs []string | 	PostRendererArgs []string | ||||||
| 	SyncArgs         string | 	SyncArgs         string | ||||||
|  | 	HideNotes        bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type SyncOpt interface{ Apply(*SyncOpts) } | type SyncOpt interface{ Apply(*SyncOpts) } | ||||||
|  | @ -2727,6 +2728,9 @@ func (st *HelmState) flagsForUpgrade(helm helmexec.Interface, release *ReleaseSp | ||||||
| 	} | 	} | ||||||
| 	flags = st.appendPostRenderArgsFlags(flags, release, postRendererArgs) | 	flags = st.appendPostRenderArgsFlags(flags, release, postRendererArgs) | ||||||
| 
 | 
 | ||||||
|  | 	// append hide-notes flag
 | ||||||
|  | 	flags = st.appendHideNotesFlags(flags, helm, opt) | ||||||
|  | 
 | ||||||
| 	flags = st.appendExtraSyncFlags(flags, opt) | 	flags = st.appendExtraSyncFlags(flags, opt) | ||||||
| 
 | 
 | ||||||
| 	common, clean, err := st.namespaceAndValuesFlags(helm, release, workerIndex) | 	common, clean, err := st.namespaceAndValuesFlags(helm, release, workerIndex) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue