diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index 12ee939f38..6af875874a 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -681,6 +681,7 @@ func (kb *kubernetesBackupper) backupItemBlock(ctx context.Context, itemBlock Ba if len(postHookPods) > 0 { itemBlock.Log.Debug("Executing post hooks") + itemBlock.itemBackupper.hookTracker.AsyncItemBlocks.Add(1) go kb.handleItemBlockPostHooks(ctx, itemBlock, postHookPods) } @@ -719,7 +720,6 @@ func (kb *kubernetesBackupper) handleItemBlockPreHooks(itemBlock BackupItemBlock // The hooks cannot execute until the PVBs to be processed func (kb *kubernetesBackupper) handleItemBlockPostHooks(ctx context.Context, itemBlock BackupItemBlock, hookPods []itemblock.ItemBlockItem) { log := itemBlock.Log - itemBlock.itemBackupper.hookTracker.AsyncItemBlocks.Add(1) defer itemBlock.itemBackupper.hookTracker.AsyncItemBlocks.Done() if err := kb.waitUntilPVBsProcessed(ctx, log, itemBlock, hookPods); err != nil { @@ -790,7 +790,7 @@ func (kb *kubernetesBackupper) waitUntilPVBsProcessed(ctx context.Context, log l return allProcessed, nil } - return wait.PollUntilContextCancel(ctx, 5*time.Second, false, checkFunc) + return wait.PollUntilContextCancel(ctx, 5*time.Second, true, checkFunc) } func (kb *kubernetesBackupper) backupItem(log logrus.FieldLogger, gr schema.GroupResource, itemBackupper *itemBackupper, unstructured *unstructured.Unstructured, preferredGVR schema.GroupVersionResource, itemBlock *BackupItemBlock) bool { diff --git a/pkg/backup/backup_test.go b/pkg/backup/backup_test.go index 88ccb705a7..d646783bbd 100644 --- a/pkg/backup/backup_test.go +++ b/pkg/backup/backup_test.go @@ -3433,59 +3433,57 @@ func TestBackupWithHooks(t *testing.T) { wantBackedUp []string wantHookExecutionLog []test.HookExecutionEntry }{ - /* - { - name: "pre hook with no resource filters runs for all pods", - backup: defaultBackup(). - Hooks(velerov1.BackupHooks{ - Resources: []velerov1.BackupResourceHookSpec{ - { - Name: "hook-1", - PreHooks: []velerov1.BackupResourceHook{ - { - Exec: &velerov1.ExecHook{ - Command: []string{"ls", "/tmp"}, - }, + { + name: "pre hook with no resource filters runs for all pods", + backup: defaultBackup(). + Hooks(velerov1.BackupHooks{ + Resources: []velerov1.BackupResourceHookSpec{ + { + Name: "hook-1", + PreHooks: []velerov1.BackupResourceHook{ + { + Exec: &velerov1.ExecHook{ + Command: []string{"ls", "/tmp"}, }, }, }, }, - }). - Result(), - apiResources: []*test.APIResource{ - test.Pods( - builder.ForPod("ns-1", "pod-1").Result(), - builder.ForPod("ns-2", "pod-2").Result(), - ), - }, - wantExecutePodCommandCalls: []*expectedCall{ - { - podNamespace: "ns-1", - podName: "pod-1", - hookName: "hook-1", - hook: &velerov1.ExecHook{ - Command: []string{"ls", "/tmp"}, - }, - err: nil, }, - { - podNamespace: "ns-2", - podName: "pod-2", - hookName: "hook-1", - hook: &velerov1.ExecHook{ - Command: []string{"ls", "/tmp"}, - }, - err: nil, + }). + Result(), + apiResources: []*test.APIResource{ + test.Pods( + builder.ForPod("ns-1", "pod-1").Result(), + builder.ForPod("ns-2", "pod-2").Result(), + ), + }, + wantExecutePodCommandCalls: []*expectedCall{ + { + podNamespace: "ns-1", + podName: "pod-1", + hookName: "hook-1", + hook: &velerov1.ExecHook{ + Command: []string{"ls", "/tmp"}, }, + err: nil, }, - wantBackedUp: []string{ - "resources/pods/namespaces/ns-1/pod-1.json", - "resources/pods/namespaces/ns-2/pod-2.json", - "resources/pods/v1-preferredversion/namespaces/ns-1/pod-1.json", - "resources/pods/v1-preferredversion/namespaces/ns-2/pod-2.json", + { + podNamespace: "ns-2", + podName: "pod-2", + hookName: "hook-1", + hook: &velerov1.ExecHook{ + Command: []string{"ls", "/tmp"}, + }, + err: nil, }, }, - */ + wantBackedUp: []string{ + "resources/pods/namespaces/ns-1/pod-1.json", + "resources/pods/namespaces/ns-2/pod-2.json", + "resources/pods/v1-preferredversion/namespaces/ns-1/pod-1.json", + "resources/pods/v1-preferredversion/namespaces/ns-2/pod-2.json", + }, + }, { name: "post hook with no resource filters runs for all pods", backup: defaultBackup().