Merge pull request #8548 from ywk253100/241223_fix

[cherry-pick]Bug fix: increase the WaitGroup counter before start the goroutine
pull/8551/head
Wenkai Yin(尹文开) 2024-12-23 18:22:56 +08:00 committed by GitHub
commit e725f89906
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 46 deletions

View File

@ -697,6 +697,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)
}
@ -735,7 +736,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 {
@ -806,7 +806,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 {

View File

@ -3464,7 +3464,6 @@ func TestBackupWithHooks(t *testing.T) {
wantBackedUp []string
wantHookExecutionLog []test.HookExecutionEntry
}{
/*
{
name: "pre hook with no resource filters runs for all pods",
backup: defaultBackup().
@ -3516,7 +3515,6 @@ func TestBackupWithHooks(t *testing.T) {
"resources/pods/v1-preferredversion/namespaces/ns-2/pod-2.json",
},
},
*/
{
name: "post hook with no resource filters runs for all pods",
backup: defaultBackup().