Merge pull request #8548 from ywk253100/241223_fix
[cherry-pick]Bug fix: increase the WaitGroup counter before start the goroutinepull/8551/head
commit
e725f89906
|
@ -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 {
|
||||
|
|
|
@ -3464,59 +3464,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().
|
||||
|
|
Loading…
Reference in New Issue