From 6f1888b78395af3a42a6b15e47b4ea375e102d36 Mon Sep 17 00:00:00 2001 From: Karthik Chowdary <21139050+Karthik-Chowdary@users.noreply.github.com> Date: Sun, 30 Aug 2026 06:47:45 +0000 Subject: [PATCH] fix(action): keep wait progress callback private Signed-off-by: Karthik Chowdary <21139050+Karthik-Chowdary@users.noreply.github.com> --- pkg/action/install.go | 13 +++++++++---- pkg/action/install_test.go | 6 ++++++ pkg/action/upgrade.go | 13 +++++++++---- pkg/action/upgrade_test.go | 6 ++++++ pkg/cmd/install.go | 5 +++-- pkg/cmd/upgrade.go | 5 +++-- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/pkg/action/install.go b/pkg/action/install.go index a2b4369d6..098e7fe0a 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -100,8 +100,8 @@ type Install struct { Devel bool DependencyUpdate bool Timeout time.Duration - // WaitProgress is called immediately before waiting for resources. - WaitProgress func(time.Duration) + // waitProgress is called immediately before waiting for resources. + waitProgress func(time.Duration) Namespace string ReleaseName string GenerateName bool @@ -184,6 +184,11 @@ func (i *Install) GetRegistryClient() *registry.Client { return i.registryClient } +// SetWaitProgress configures a callback invoked immediately before waiting for resources. +func (i *Install) SetWaitProgress(waitProgress func(time.Duration)) { + i.waitProgress = waitProgress +} + func (i *Install) installCRDs(crds []chart.CRD) error { // We do these one file at a time in the order they were read. totalItems := []*resource.Info{} @@ -545,8 +550,8 @@ func (i *Install) performInstall(rel *release.Release, toBeAdopted kube.Resource return rel, fmt.Errorf("failed to get waiter: %w", err) } - if i.WaitProgress != nil { - i.WaitProgress(i.Timeout) + if i.waitProgress != nil { + i.waitProgress(i.Timeout) } if i.WaitForJobs { diff --git a/pkg/action/install_test.go b/pkg/action/install_test.go index 2d83abe27..209678864 100644 --- a/pkg/action/install_test.go +++ b/pkg/action/install_test.go @@ -618,6 +618,11 @@ func TestInstallRelease_Wait(t *testing.T) { failer.WaitError = errors.New("I timed out") instAction.cfg.KubeClient = failer instAction.WaitStrategy = kube.StatusWatcherStrategy + progressCalls := 0 + instAction.SetWaitProgress(func(timeout time.Duration) { + assert.Equal(t, instAction.Timeout, timeout) + progressCalls++ + }) vals := map[string]any{} goroutines := instAction.getGoroutineCount() @@ -628,6 +633,7 @@ func TestInstallRelease_Wait(t *testing.T) { req.NoError(err) is.Contains(res.Info.Description, "I timed out") is.Equal(rcommon.StatusFailed, res.Info.Status) + is.Equal(1, progressCalls) is.Equal(goroutines, instAction.getGoroutineCount()) } diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index 5a45d4730..30fa11103 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -76,8 +76,8 @@ type Upgrade struct { WaitOptions []kube.WaitOption // WaitForJobs determines whether the wait operation for the Jobs should be performed after the upgrade is requested. WaitForJobs bool - // WaitProgress is called immediately before waiting for resources. - WaitProgress func(time.Duration) + // waitProgress is called immediately before waiting for resources. + waitProgress func(time.Duration) // DisableHooks disables hook processing if set to true. DisableHooks bool // DryRunStrategy can be set to prepare, but not execute the operation and whether or not to interact with the remote cluster @@ -162,6 +162,11 @@ func (u *Upgrade) SetRegistryClient(client *registry.Client) { u.registryClient = client } +// SetWaitProgress configures a callback invoked immediately before waiting for resources. +func (u *Upgrade) SetWaitProgress(waitProgress func(time.Duration)) { + u.waitProgress = waitProgress +} + // Run executes the upgrade on the given release. func (u *Upgrade) Run(name string, chart chart.Charter, vals map[string]any) (ri.Releaser, error) { ctx := context.Background() @@ -491,8 +496,8 @@ func (u *Upgrade) releasingUpgrade(c chan<- resultMessage, upgradedRelease *rele u.reportToPerformUpgrade(c, upgradedRelease, results.Created, err) return } - if u.WaitProgress != nil { - u.WaitProgress(u.Timeout) + if u.waitProgress != nil { + u.waitProgress(u.Timeout) } if u.WaitForJobs { diff --git a/pkg/action/upgrade_test.go b/pkg/action/upgrade_test.go index 53419b6a8..70d088bb9 100644 --- a/pkg/action/upgrade_test.go +++ b/pkg/action/upgrade_test.go @@ -94,6 +94,11 @@ func TestUpgradeRelease_Wait(t *testing.T) { failer.WaitError = errors.New("I timed out") upAction.cfg.KubeClient = failer upAction.WaitStrategy = kube.StatusWatcherStrategy + progressCalls := 0 + upAction.SetWaitProgress(func(timeout time.Duration) { + assert.Equal(t, upAction.Timeout, timeout) + progressCalls++ + }) vals := map[string]any{} resi, err := upAction.Run(rel.Name, buildChart(), vals) @@ -102,6 +107,7 @@ func TestUpgradeRelease_Wait(t *testing.T) { req.NoError(err) is.Contains(res.Info.Description, "I timed out") is.Equal(common.StatusFailed, res.Info.Status) + is.Equal(1, progressCalls) } func TestUpgradeRelease_WaitForJobs(t *testing.T) { diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go index d31958a60..b44c7b72a 100644 --- a/pkg/cmd/install.go +++ b/pkg/cmd/install.go @@ -374,15 +374,16 @@ func checkIfInstallable(ch chart.Accessor) error { } func configureWaitProgress(client *action.Install, out io.Writer, outfmt output.Format) { + client.SetWaitProgress(nil) if outfmt != output.Table || client.DryRunStrategy != action.DryRunNone { return } if client.WaitStrategy == kube.HookOnlyStrategy && !client.RollbackOnFailure { return } - client.WaitProgress = func(timeout time.Duration) { + client.SetWaitProgress(func(timeout time.Duration) { printWaitMessage(out, outfmt, kube.StatusWatcherStrategy, false, action.DryRunNone, timeout) - } + }) } func printWaitMessage(out io.Writer, outfmt output.Format, strategy kube.WaitStrategy, rollbackOnFailure bool, dryRun action.DryRunStrategy, timeout time.Duration) { diff --git a/pkg/cmd/upgrade.go b/pkg/cmd/upgrade.go index acf247cbd..28b514311 100644 --- a/pkg/cmd/upgrade.go +++ b/pkg/cmd/upgrade.go @@ -84,15 +84,16 @@ which can contain sensitive values. To hide Kubernetes Secrets use the ` func configureUpgradeWaitProgress(client *action.Upgrade, out io.Writer, outfmt output.Format) { + client.SetWaitProgress(nil) if outfmt != output.Table || client.DryRunStrategy != action.DryRunNone { return } if client.WaitStrategy == kube.HookOnlyStrategy && !client.RollbackOnFailure { return } - client.WaitProgress = func(timeout time.Duration) { + client.SetWaitProgress(func(timeout time.Duration) { printWaitMessage(out, outfmt, kube.StatusWatcherStrategy, false, action.DryRunNone, timeout) - } + }) } func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {