diff --git a/pkg/action/hooks.go b/pkg/action/hooks.go index ecca1d997..c32b9b3ce 100644 --- a/pkg/action/hooks.go +++ b/pkg/action/hooks.go @@ -22,7 +22,6 @@ import ( "github.com/pkg/errors" - "helm.sh/helm/v4/pkg/kube" "helm.sh/helm/v4/pkg/release" helmtime "helm.sh/helm/v4/pkg/time" ) @@ -138,11 +137,8 @@ func (cfg *Configuration) deleteHookByPolicy(h *release.Hook, policy release.Hoo return errors.New(joinErrors(errs)) } - //wait for resources until they are deleted to avoid conflicts - if kubeClient, ok := cfg.KubeClient.(kube.InterfaceExt); ok { - if err := kubeClient.WaitForDelete(resources, timeout); err != nil { - return err - } + if err := cfg.KubeClient.WaitForDelete(resources, timeout); err != nil { + return err } } return nil diff --git a/pkg/action/uninstall.go b/pkg/action/uninstall.go index dda7d6978..75d999976 100644 --- a/pkg/action/uninstall.go +++ b/pkg/action/uninstall.go @@ -131,10 +131,8 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error) res.Info = kept if u.Wait { - if kubeClient, ok := u.cfg.KubeClient.(kube.InterfaceExt); ok { - if err := kubeClient.WaitForDelete(deletedResources, u.Timeout); err != nil { - errs = append(errs, err) - } + if err := u.cfg.KubeClient.WaitForDelete(deletedResources, u.Timeout); err != nil { + errs = append(errs, err) } } diff --git a/pkg/kube/client.go b/pkg/kube/client.go index fe830747d..968e1b951 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -331,15 +331,6 @@ func getResource(info *resource.Info) (runtime.Object, error) { return obj, nil } -// WaitForDelete wait up to the given timeout for the specified resources to be deleted. -func (c *Client) WaitForDelete(resources ResourceList, timeout time.Duration) error { - w := HelmWaiter{ - log: c.Log, - timeout: timeout, - } - return w.waitForDeletedResources(resources) -} - func (c *Client) namespace() string { if c.Namespace != "" { return c.Namespace diff --git a/pkg/kube/interface.go b/pkg/kube/interface.go index 6cf33c515..30be37f7c 100644 --- a/pkg/kube/interface.go +++ b/pkg/kube/interface.go @@ -67,12 +67,7 @@ type Waiter interface { // WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs. WaitWithJobs(resources ResourceList, timeout time.Duration) error -} -// InterfaceExt is introduced to avoid breaking backwards compatibility for Interface implementers. -// -// TODO Helm 4: Remove InterfaceExt and integrate its method(s) into the Interface. -type InterfaceExt interface { // WaitForDelete wait up to the given timeout for the specified resources to be deleted. WaitForDelete(resources ResourceList, timeout time.Duration) error } @@ -108,6 +103,5 @@ type InterfaceResources interface { } var _ Interface = (*Client)(nil) -var _ InterfaceExt = (*Client)(nil) var _ InterfaceDeletionPropagation = (*Client)(nil) var _ InterfaceResources = (*Client)(nil) diff --git a/pkg/kube/statuswait.go b/pkg/kube/statuswait.go index 8268598e6..b1c39948c 100644 --- a/pkg/kube/statuswait.go +++ b/pkg/kube/statuswait.go @@ -50,6 +50,12 @@ func (w *statusWaiter) WaitWithJobs(resourceList ResourceList, timeout time.Dura return w.wait(ctx, resourceList, true) } +func (w *statusWaiter) WaitForDelete(resourceList ResourceList, timeout time.Duration) error { + ctx, cancel := context.WithTimeout(context.TODO(), timeout) + defer cancel() + return w.waitForDelete(ctx, resourceList) +} + func (w *statusWaiter) waitForDelete(ctx context.Context, resourceList ResourceList) error { deadline, _ := ctx.Deadline() w.log("beginning wait for %d resources to be deleted with timeout of %v", len(resourceList), time.Until(deadline)) diff --git a/pkg/kube/statuswait_test.go b/pkg/kube/statuswait_test.go index ecd18e183..0084606cf 100644 --- a/pkg/kube/statuswait_test.go +++ b/pkg/kube/statuswait_test.go @@ -153,8 +153,6 @@ func TestStatusWaitForDelete(t *testing.T) { sw: statusWatcher, log: t.Logf, } - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() createdObjs := []runtime.Object{} for _, objYaml := range tt.objToCreate { m := make(map[string]interface{}) @@ -184,7 +182,7 @@ func TestStatusWaitForDelete(t *testing.T) { assert.NoError(t, err) resourceList = append(resourceList, list...) } - err := statusWaiter.waitForDelete(ctx, resourceList) + err := statusWaiter.WaitForDelete(resourceList, timeout) if tt.expectErrs != nil { assert.EqualError(t, err, errors.Join(tt.expectErrs...).Error()) return diff --git a/pkg/kube/wait.go b/pkg/kube/wait.go index e74753e57..97fa8b3e1 100644 --- a/pkg/kube/wait.go +++ b/pkg/kube/wait.go @@ -43,29 +43,26 @@ import ( // Helm 4 now uses the StatusWaiter interface instead type HelmWaiter struct { c ReadyChecker - timeout time.Duration log func(string, ...interface{}) kubeClient *kubernetes.Clientset } func (w *HelmWaiter) Wait(resources ResourceList, timeout time.Duration) error { w.c = NewReadyChecker(w.kubeClient, w.log, PausedAsReady(true)) - w.timeout = timeout - return w.waitForResources(resources) + return w.waitForResources(resources, timeout) } func (w *HelmWaiter) WaitWithJobs(resources ResourceList, timeout time.Duration) error { w.c = NewReadyChecker(w.kubeClient, w.log, PausedAsReady(true), CheckJobs(true)) - w.timeout = timeout - return w.waitForResources(resources) + return w.waitForResources(resources, timeout) } // waitForResources polls to get the current status of all pods, PVCs, Services and // Jobs(optional) until all are ready or a timeout is reached -func (w *HelmWaiter) waitForResources(created ResourceList) error { - w.log("beginning wait for %d resources with timeout of %v", len(created), w.timeout) +func (w *HelmWaiter) waitForResources(created ResourceList, timeout time.Duration) error { + w.log("beginning wait for %d resources with timeout of %v", len(created), timeout) - ctx, cancel := context.WithTimeout(context.Background(), w.timeout) + ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() numberOfErrors := make([]int, len(created)) @@ -116,10 +113,10 @@ func (w *HelmWaiter) isRetryableHTTPStatusCode(httpStatusCode int32) bool { } // waitForDeletedResources polls to check if all the resources are deleted or a timeout is reached -func (w *HelmWaiter) waitForDeletedResources(deleted ResourceList) error { - w.log("beginning wait for %d resources to be deleted with timeout of %v", len(deleted), w.timeout) +func (w *HelmWaiter) WaitForDelete(deleted ResourceList, timeout time.Duration) error { + w.log("beginning wait for %d resources to be deleted with timeout of %v", len(deleted), timeout) - ctx, cancel := context.WithTimeout(context.Background(), w.timeout) + ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() return wait.PollUntilContextCancel(ctx, 2*time.Second, true, func(_ context.Context) (bool, error) {