diff --git a/pkg/kube/kwait.go b/pkg/kube/kwait.go index e72e4b93d..3d8cfb616 100644 --- a/pkg/kube/kwait.go +++ b/pkg/kube/kwait.go @@ -40,16 +40,18 @@ type kstatusWaiter struct { } func (w *kstatusWaiter) Wait(resourceList ResourceList, timeout time.Duration) error { - return w.wait(resourceList, timeout, false) + ctx, cancel := context.WithTimeout(context.TODO(), timeout) + defer cancel() + return w.wait(ctx, resourceList, false) } func (w *kstatusWaiter) WaitWithJobs(resourceList ResourceList, timeout time.Duration) error { - return w.wait(resourceList, timeout, true) -} - -func (w *kstatusWaiter) wait(resourceList ResourceList, timeout time.Duration, waitForJobs bool) error { ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() + return w.wait(ctx, resourceList, true) +} + +func (w *kstatusWaiter) wait(ctx context.Context, resourceList ResourceList, waitForJobs bool) error { cancelCtx, cancel := context.WithCancel(ctx) defer cancel() runtimeObjs := []runtime.Object{} diff --git a/pkg/kube/kwait_test.go b/pkg/kube/kwait_test.go index 1bc80d8ee..9598ca216 100644 --- a/pkg/kube/kwait_test.go +++ b/pkg/kube/kwait_test.go @@ -17,6 +17,7 @@ limitations under the License. package kube // import "helm.sh/helm/v3/pkg/kube" import ( + "context" "errors" "log" "testing" @@ -194,7 +195,10 @@ func TestKWaitJob(t *testing.T) { resourceList = append(resourceList, list...) } - err := kwaiter.wait(resourceList, time.Second*3, tt.waitForJobs) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*3) + defer cancel() + + err := kwaiter.wait(ctx, resourceList, tt.waitForJobs) 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 de00aae47..34eb55e7c 100644 --- a/pkg/kube/wait.go +++ b/pkg/kube/wait.go @@ -51,8 +51,9 @@ func (w *waiter) Wait(resources ResourceList, timeout time.Duration) error { func (w *waiter) WaitWithJobs(resources ResourceList, timeout time.Duration) error { // Implementation - // TODO this function doesn't make sense unless you pass a readyChecker to it + // TODO this function doesn't make sense unless you pass a readyChecker to it // TODO pass context instead + // checker := NewReadyChecker(cs, w.c.Log, PausedAsReady(true), CheckJobs(true)) w.timeout = timeout return w.waitForResources(resources) }