mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-03 11:45:20 +00:00
Run backup post hooks inside ItemBlock synchronously
Run backup post hooks inside ItemBlock synchronously as the ItemBlocks are handled asynchronously Fixes #8516 Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
This commit is contained in:
@@ -759,8 +759,7 @@ func (kb *kubernetesBackupper) backupItemBlock(itemBlock *BackupItemBlock) []sch
|
||||
|
||||
if len(postHookPods) > 0 {
|
||||
itemBlock.Log.Debug("Executing post hooks")
|
||||
itemBlock.itemBackupper.hookTracker.AsyncItemBlocks.Add(1)
|
||||
go kb.handleItemBlockPostHooks(itemBlock, postHookPods)
|
||||
kb.handleItemBlockPostHooks(itemBlock, postHookPods)
|
||||
}
|
||||
|
||||
return grList
|
||||
@@ -798,7 +797,6 @@ func (kb *kubernetesBackupper) handleItemBlockPreHooks(itemBlock *BackupItemBloc
|
||||
// The hooks cannot execute until the PVBs to be processed
|
||||
func (kb *kubernetesBackupper) handleItemBlockPostHooks(itemBlock *BackupItemBlock, hookPods []itemblock.ItemBlockItem) {
|
||||
log := itemBlock.Log
|
||||
defer itemBlock.itemBackupper.hookTracker.AsyncItemBlocks.Done()
|
||||
|
||||
// the post hooks will not execute until all PVBs of the item block pods are processed
|
||||
if err := kb.waitUntilPVBsProcessed(kb.podVolumeContext, log, itemBlock, hookPods); err != nil {
|
||||
|
||||
@@ -3995,17 +3995,7 @@ func TestBackupWithHooks(t *testing.T) {
|
||||
require.NoError(t, h.backupper.Backup(h.log, req, backupFile, nil, tc.actions, nil))
|
||||
|
||||
if tc.wantHookExecutionLog != nil {
|
||||
// as the post hook execution in async way, check the existence rather than the exact order
|
||||
assert.Equal(t, len(tc.wantHookExecutionLog), len(podCommandExecutor.HookExecutionLog))
|
||||
m := map[string]struct{}{}
|
||||
for _, entry := range podCommandExecutor.HookExecutionLog {
|
||||
m[entry.String()] = struct{}{}
|
||||
}
|
||||
|
||||
for _, entry := range tc.wantHookExecutionLog {
|
||||
_, exist := m[entry.String()]
|
||||
assert.True(t, exist)
|
||||
}
|
||||
assert.Equal(t, tc.wantHookExecutionLog, podCommandExecutor.HookExecutionLog)
|
||||
}
|
||||
assertTarballContents(t, backupFile, append(tc.wantBackedUp, "metadata/version")...)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user