fix(action): keep wait progress callback private

Signed-off-by: Karthik Chowdary <21139050+Karthik-Chowdary@users.noreply.github.com>
pull/32549/head
Karthik Chowdary 2 weeks ago
parent 6a1a3d092f
commit 6f1888b783

@ -100,8 +100,8 @@ type Install struct {
Devel bool Devel bool
DependencyUpdate bool DependencyUpdate bool
Timeout time.Duration Timeout time.Duration
// WaitProgress is called immediately before waiting for resources. // waitProgress is called immediately before waiting for resources.
WaitProgress func(time.Duration) waitProgress func(time.Duration)
Namespace string Namespace string
ReleaseName string ReleaseName string
GenerateName bool GenerateName bool
@ -184,6 +184,11 @@ func (i *Install) GetRegistryClient() *registry.Client {
return i.registryClient 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 { func (i *Install) installCRDs(crds []chart.CRD) error {
// We do these one file at a time in the order they were read. // We do these one file at a time in the order they were read.
totalItems := []*resource.Info{} 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) return rel, fmt.Errorf("failed to get waiter: %w", err)
} }
if i.WaitProgress != nil { if i.waitProgress != nil {
i.WaitProgress(i.Timeout) i.waitProgress(i.Timeout)
} }
if i.WaitForJobs { if i.WaitForJobs {

@ -618,6 +618,11 @@ func TestInstallRelease_Wait(t *testing.T) {
failer.WaitError = errors.New("I timed out") failer.WaitError = errors.New("I timed out")
instAction.cfg.KubeClient = failer instAction.cfg.KubeClient = failer
instAction.WaitStrategy = kube.StatusWatcherStrategy instAction.WaitStrategy = kube.StatusWatcherStrategy
progressCalls := 0
instAction.SetWaitProgress(func(timeout time.Duration) {
assert.Equal(t, instAction.Timeout, timeout)
progressCalls++
})
vals := map[string]any{} vals := map[string]any{}
goroutines := instAction.getGoroutineCount() goroutines := instAction.getGoroutineCount()
@ -628,6 +633,7 @@ func TestInstallRelease_Wait(t *testing.T) {
req.NoError(err) req.NoError(err)
is.Contains(res.Info.Description, "I timed out") is.Contains(res.Info.Description, "I timed out")
is.Equal(rcommon.StatusFailed, res.Info.Status) is.Equal(rcommon.StatusFailed, res.Info.Status)
is.Equal(1, progressCalls)
is.Equal(goroutines, instAction.getGoroutineCount()) is.Equal(goroutines, instAction.getGoroutineCount())
} }

@ -76,8 +76,8 @@ type Upgrade struct {
WaitOptions []kube.WaitOption WaitOptions []kube.WaitOption
// WaitForJobs determines whether the wait operation for the Jobs should be performed after the upgrade is requested. // WaitForJobs determines whether the wait operation for the Jobs should be performed after the upgrade is requested.
WaitForJobs bool WaitForJobs bool
// WaitProgress is called immediately before waiting for resources. // waitProgress is called immediately before waiting for resources.
WaitProgress func(time.Duration) waitProgress func(time.Duration)
// DisableHooks disables hook processing if set to true. // DisableHooks disables hook processing if set to true.
DisableHooks bool DisableHooks bool
// DryRunStrategy can be set to prepare, but not execute the operation and whether or not to interact with the remote cluster // 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 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. // Run executes the upgrade on the given release.
func (u *Upgrade) Run(name string, chart chart.Charter, vals map[string]any) (ri.Releaser, error) { func (u *Upgrade) Run(name string, chart chart.Charter, vals map[string]any) (ri.Releaser, error) {
ctx := context.Background() ctx := context.Background()
@ -491,8 +496,8 @@ func (u *Upgrade) releasingUpgrade(c chan<- resultMessage, upgradedRelease *rele
u.reportToPerformUpgrade(c, upgradedRelease, results.Created, err) u.reportToPerformUpgrade(c, upgradedRelease, results.Created, err)
return return
} }
if u.WaitProgress != nil { if u.waitProgress != nil {
u.WaitProgress(u.Timeout) u.waitProgress(u.Timeout)
} }
if u.WaitForJobs { if u.WaitForJobs {

@ -94,6 +94,11 @@ func TestUpgradeRelease_Wait(t *testing.T) {
failer.WaitError = errors.New("I timed out") failer.WaitError = errors.New("I timed out")
upAction.cfg.KubeClient = failer upAction.cfg.KubeClient = failer
upAction.WaitStrategy = kube.StatusWatcherStrategy upAction.WaitStrategy = kube.StatusWatcherStrategy
progressCalls := 0
upAction.SetWaitProgress(func(timeout time.Duration) {
assert.Equal(t, upAction.Timeout, timeout)
progressCalls++
})
vals := map[string]any{} vals := map[string]any{}
resi, err := upAction.Run(rel.Name, buildChart(), vals) resi, err := upAction.Run(rel.Name, buildChart(), vals)
@ -102,6 +107,7 @@ func TestUpgradeRelease_Wait(t *testing.T) {
req.NoError(err) req.NoError(err)
is.Contains(res.Info.Description, "I timed out") is.Contains(res.Info.Description, "I timed out")
is.Equal(common.StatusFailed, res.Info.Status) is.Equal(common.StatusFailed, res.Info.Status)
is.Equal(1, progressCalls)
} }
func TestUpgradeRelease_WaitForJobs(t *testing.T) { func TestUpgradeRelease_WaitForJobs(t *testing.T) {

@ -374,15 +374,16 @@ func checkIfInstallable(ch chart.Accessor) error {
} }
func configureWaitProgress(client *action.Install, out io.Writer, outfmt output.Format) { func configureWaitProgress(client *action.Install, out io.Writer, outfmt output.Format) {
client.SetWaitProgress(nil)
if outfmt != output.Table || client.DryRunStrategy != action.DryRunNone { if outfmt != output.Table || client.DryRunStrategy != action.DryRunNone {
return return
} }
if client.WaitStrategy == kube.HookOnlyStrategy && !client.RollbackOnFailure { if client.WaitStrategy == kube.HookOnlyStrategy && !client.RollbackOnFailure {
return return
} }
client.WaitProgress = func(timeout time.Duration) { client.SetWaitProgress(func(timeout time.Duration) {
printWaitMessage(out, outfmt, kube.StatusWatcherStrategy, false, action.DryRunNone, timeout) 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) { func printWaitMessage(out io.Writer, outfmt output.Format, strategy kube.WaitStrategy, rollbackOnFailure bool, dryRun action.DryRunStrategy, timeout time.Duration) {

@ -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) { func configureUpgradeWaitProgress(client *action.Upgrade, out io.Writer, outfmt output.Format) {
client.SetWaitProgress(nil)
if outfmt != output.Table || client.DryRunStrategy != action.DryRunNone { if outfmt != output.Table || client.DryRunStrategy != action.DryRunNone {
return return
} }
if client.WaitStrategy == kube.HookOnlyStrategy && !client.RollbackOnFailure { if client.WaitStrategy == kube.HookOnlyStrategy && !client.RollbackOnFailure {
return return
} }
client.WaitProgress = func(timeout time.Duration) { client.SetWaitProgress(func(timeout time.Duration) {
printWaitMessage(out, outfmt, kube.StatusWatcherStrategy, false, action.DryRunNone, timeout) printWaitMessage(out, outfmt, kube.StatusWatcherStrategy, false, action.DryRunNone, timeout)
} })
} }
func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {

Loading…
Cancel
Save