From 5c6572b49293625b060f7f0d85110b745e1d4828 Mon Sep 17 00:00:00 2001 From: yxxhero <11087727+yxxhero@users.noreply.github.com> Date: Tue, 17 Sep 2024 20:24:19 +0800 Subject: [PATCH] Add hide notes support (#1710) * add --hide-notes support Signed-off-by: yxxhero --- pkg/app/app.go | 2 ++ pkg/app/app_test.go | 5 +++++ pkg/app/config.go | 2 ++ pkg/config/apply.go | 6 ++++++ pkg/config/sync.go | 6 ++++++ pkg/state/helmx.go | 13 ++++++++++++ pkg/state/helmx_test.go | 45 +++++++++++++++++++++++++++++++++++++++++ pkg/state/state.go | 4 ++++ 8 files changed, 83 insertions(+) diff --git a/pkg/app/app.go b/pkg/app/app.go index b77cad90..eaab62b7 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -1537,6 +1537,7 @@ Do you really want to apply? PostRenderer: c.PostRenderer(), PostRendererArgs: c.PostRendererArgs(), SyncArgs: c.SyncArgs(), + HideNotes: c.HideNotes(), } return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), syncOpts) })) @@ -1930,6 +1931,7 @@ Do you really want to sync? PostRenderer: c.PostRenderer(), PostRendererArgs: c.PostRendererArgs(), SyncArgs: c.SyncArgs(), + HideNotes: c.HideNotes(), } return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), opts) })) diff --git a/pkg/app/app_test.go b/pkg/app/app_test.go index 5dfceb75..50770c2c 100644 --- a/pkg/app/app_test.go +++ b/pkg/app/app_test.go @@ -2235,6 +2235,7 @@ type applyConfig struct { kubeVersion string suppressOutputLineRegex []string showOnly []string + hideNotes bool // template-only options includeCRDs, skipTests bool @@ -2415,6 +2416,10 @@ func (a applyConfig) ShowOnly() []string { return a.showOnly } +func (a applyConfig) HideNotes() bool { + return a.hideNotes +} + type depsConfig struct { skipRepos bool includeTransitiveNeeds bool diff --git a/pkg/app/config.go b/pkg/app/config.go index 655485b7..9d9b377b 100644 --- a/pkg/app/config.go +++ b/pkg/app/config.go @@ -51,6 +51,7 @@ type ApplyConfigProvider interface { PostRenderer() string PostRendererArgs() []string Cascade() string + HideNotes() bool SuppressOutputLineRegex() []string Values() []string @@ -98,6 +99,7 @@ type SyncConfigProvider interface { Args() string PostRenderer() string PostRendererArgs() []string + HideNotes() bool Cascade() string Values() []string diff --git a/pkg/config/apply.go b/pkg/config/apply.go index aab6ae7f..296c17cc 100644 --- a/pkg/config/apply.go +++ b/pkg/config/apply.go @@ -66,6 +66,8 @@ type ApplyOptions struct { SuppressOutputLineRegex []string // SyncArgs is the list of arguments to pass to helm upgrade. SyncArgs string + // HideNotes is the hide notes flag + HideNotes bool } // NewApply creates a new Apply @@ -247,3 +249,7 @@ func (a *ApplyImpl) SuppressOutputLineRegex() []string { func (a *ApplyImpl) SyncArgs() string { return a.ApplyOptions.SyncArgs } + +func (a *ApplyImpl) HideNotes() bool { + return a.ApplyOptions.HideNotes +} diff --git a/pkg/config/sync.go b/pkg/config/sync.go index 6950e39f..7c01598e 100644 --- a/pkg/config/sync.go +++ b/pkg/config/sync.go @@ -34,6 +34,8 @@ type SyncOptions struct { Cascade string // SyncArgs is the list of arguments to pass to the helm upgrade command. SyncArgs string + // HideNotes is the hide notes flag + HideNotes bool } // NewSyncOptions creates a new Apply @@ -139,3 +141,7 @@ func (t *SyncImpl) Cascade() string { func (t *SyncImpl) SyncArgs() string { return t.SyncOptions.SyncArgs } + +func (t *SyncImpl) HideNotes() bool { + return t.SyncOptions.HideNotes +} diff --git a/pkg/state/helmx.go b/pkg/state/helmx.go index 404706ac..b1b2bb8d 100644 --- a/pkg/state/helmx.go +++ b/pkg/state/helmx.go @@ -119,6 +119,19 @@ func (st *HelmState) appendCascadeFlags(flags []string, helm helmexec.Interface, 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 func (st *HelmState) appendShowOnlyFlags(flags []string, showOnly []string) []string { showOnlyFlags := []string{} diff --git a/pkg/state/helmx_test.go b/pkg/state/helmx_test.go index 31f6d71c..fae63bfc 100644 --- a/pkg/state/helmx_test.go +++ b/pkg/state/helmx_test.go @@ -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) + }) + } +} diff --git a/pkg/state/state.go b/pkg/state/state.go index c2e39160..ede14a08 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -774,6 +774,7 @@ type SyncOpts struct { PostRenderer string PostRendererArgs []string SyncArgs string + HideNotes bool } type SyncOpt interface{ Apply(*SyncOpts) } @@ -2727,6 +2728,9 @@ func (st *HelmState) flagsForUpgrade(helm helmexec.Interface, release *ReleaseSp } flags = st.appendPostRenderArgsFlags(flags, release, postRendererArgs) + // append hide-notes flag + flags = st.appendHideNotesFlags(flags, helm, opt) + flags = st.appendExtraSyncFlags(flags, opt) common, clean, err := st.namespaceAndValuesFlags(helm, release, workerIndex)