Repository: helm/helm
Pull request #30766 (2025-04-17 09:16:35)

Fix main branch by defining wait strategy parameter on hooks
<!--  Thanks for sending a pull request!  Here are some tips for you:
1. Make sure to read the Contributing Guide before submitting your PR: https://github.com/helm/helm/blob/main/CONTRIBUTING.md
2. If this PR closes another issue, add 'closes #<issue number>' somewhere in the PR summary. GitHub will automatically close that issue when this PR gets merged. Alternatively, adding 'refs #<issue number>' will not close the issue, but help provide the reviewer more context.-->

**What this PR does / why we need it**:

https://github.com/helm/helm/pull/30673 's merge broke `main` because of changes on wait strategy, `Log` parameter and different testing strategy. This PR try to fix linting and testing.

**Special notes for your reviewer**:

**If applicable**:
- [ ] this PR contains user facing changes (the `docs needed` label should be applied if so)
- [ ] this PR contains unit tests
- [ ] this PR has been tested for backwards compatibility



Patch:
diff --git a/pkg/action/hooks.go b/pkg/action/hooks.go
index 37e134c48..dbacb123e 100644
--- a/pkg/action/hooks.go
+++ b/pkg/action/hooks.go
@@ -112,7 +112,7 @@ func (cfg *Configuration) execHook(rl *release.Release, hook release.HookEvent,
 
 			// If a hook is failed, check the annotation of the previous successful hooks to determine whether the hooks
 			// should be deleted under succeeded condition.
-			if err := cfg.deleteHooksByPolicy(executingHooks[0:i], release.HookSucceeded, timeout); err != nil {
+			if err := cfg.deleteHooksByPolicy(executingHooks[0:i], release.HookSucceeded, waitStrategy, timeout); err != nil {
 				return err
 			}
 
@@ -178,9 +178,9 @@ func (cfg *Configuration) deleteHookByPolicy(h *release.Hook, policy release.Hoo
 }
 
 // deleteHooksByPolicy deletes all hooks if the hook policy instructs it to
-func (cfg *Configuration) deleteHooksByPolicy(hooks []*release.Hook, policy release.HookDeletePolicy, timeout time.Duration) error {
+func (cfg *Configuration) deleteHooksByPolicy(hooks []*release.Hook, policy release.HookDeletePolicy, waitStrategy kube.WaitStrategy, timeout time.Duration) error {
 	for _, h := range hooks {
-		if err := cfg.deleteHookByPolicy(h, policy, timeout); err != nil {
+		if err := cfg.deleteHookByPolicy(h, policy, waitStrategy, timeout); err != nil {
 			return err
 		}
 	}


Test patch:
diff --git a/pkg/action/hooks_test.go b/pkg/action/hooks_test.go
index 68379add8..9ca42ec6a 100644
--- a/pkg/action/hooks_test.go
+++ b/pkg/action/hooks_test.go
@@ -228,6 +228,11 @@ type HookFailingKubeClient struct {
 	deleteRecord []resource.Info
 }
 
+type HookFailingKubeWaiter struct {
+	*kubefake.PrintingKubeWaiter
+	failOn resource.Info
+}
+
 func (*HookFailingKubeClient) Build(reader io.Reader, _ bool) (kube.ResourceList, error) {
 	configMap := &v1.ConfigMap{}
 
@@ -243,14 +248,13 @@ func (*HookFailingKubeClient) Build(reader io.Reader, _ bool) (kube.ResourceList
 	}}, nil
 }
 
-func (h *HookFailingKubeClient) WatchUntilReady(resources kube.ResourceList, duration time.Duration) error {
+func (h *HookFailingKubeWaiter) WatchUntilReady(resources kube.ResourceList, _ time.Duration) error {
 	for _, res := range resources {
 		if res.Name == h.failOn.Name && res.Namespace == h.failOn.Namespace {
 			return &HookFailedError{}
 		}
 	}
-
-	return h.PrintingKubeClient.WatchUntilReady(resources, duration)
+	return nil
 }
 
 func (h *HookFailingKubeClient) Delete(resources kube.ResourceList) (*kube.Result, []error) {
@@ -264,6 +268,14 @@ func (h *HookFailingKubeClient) Delete(resources kube.ResourceList) (*kube.Resul
 	return h.PrintingKubeClient.Delete(resources)
 }
 
+func (h *HookFailingKubeClient) GetWaiter(strategy kube.WaitStrategy) (kube.Waiter, error) {
+	waiter, _ := h.PrintingKubeClient.GetWaiter(strategy)
+	return &HookFailingKubeWaiter{
+		PrintingKubeWaiter: waiter.(*kubefake.PrintingKubeWaiter),
+		failOn:             h.failOn,
+	}, nil
+}
+
 func TestHooksCleanUp(t *testing.T) {
 	hookEvent := release.HookPreInstall
 
@@ -369,15 +381,9 @@ data:
 				Releases:     storage.Init(driver.NewMemory()),
 				KubeClient:   kubeClient,
 				Capabilities: chartutil.DefaultCapabilities,
-				Log: func(format string, v ...interface{}) {
-					t.Helper()
-					if *verbose {
-						t.Logf(format, v...)
-					}
-				},
 			}
 
-			err := configuration.execHook(&tc.inputRelease, hookEvent, 600)
+			err := configuration.execHook(&tc.inputRelease, hookEvent, kube.StatusWatcherStrategy, 600)
 
 			if !reflect.DeepEqual(kubeClient.deleteRecord, tc.expectedDeleteRecord) {
 				t.Fatalf("Got unexpected delete record, expected: %#v, but got: %#v", kubeClient.deleteRecord, tc.expectedDeleteRecord)