diff --git a/changelogs/unreleased/9672-Lyndon-Li‎‎ b/changelogs/unreleased/9672-Lyndon-Li‎‎ new file mode 100644 index 000000000..35ae4d5cb --- /dev/null +++ b/changelogs/unreleased/9672-Lyndon-Li‎‎ @@ -0,0 +1 @@ +Fix issue #9659, in the case that PVB/PVR/DU/DD is cancelled before the data path is really started, call EndEvent to prevent data mover pod from crashing because of delay event distribution \ No newline at end of file diff --git a/pkg/datamover/backup_micro_service.go b/pkg/datamover/backup_micro_service.go index 3c6601cbf..61c308f15 100644 --- a/pkg/datamover/backup_micro_service.go +++ b/pkg/datamover/backup_micro_service.go @@ -310,6 +310,7 @@ func (r *BackupMicroService) cancelDataUpload(du *velerov2alpha1api.DataUpload) fsBackup := r.dataPathMgr.GetAsyncBR(du.Name) if fsBackup == nil { r.OnDataUploadCancelled(r.ctx, du.GetNamespace(), du.GetName()) + r.eventRecorder.EndingEvent(du, false, datapath.EventReasonStopped, "Data path for %s exited without start", du.Name) } else { fsBackup.Cancel() } diff --git a/pkg/datamover/backup_micro_service_test.go b/pkg/datamover/backup_micro_service_test.go index 160fcaac7..c5a9a4487 100644 --- a/pkg/datamover/backup_micro_service_test.go +++ b/pkg/datamover/backup_micro_service_test.go @@ -259,8 +259,8 @@ func TestCancelDataUpload(t *testing.T) { }{ { name: "no fs backup", - expectedEventReason: datapath.EventReasonCancelled, - expectedEventMsg: "Data path for data upload fake-data-upload canceled", + expectedEventReason: datapath.EventReasonStopped, + expectedEventMsg: "Data path for fake-data-upload exited without start", expectedErr: datapath.ErrCancelled, }, } diff --git a/pkg/datamover/restore_micro_service.go b/pkg/datamover/restore_micro_service.go index 1b7ebcc09..0cb5f18ec 100644 --- a/pkg/datamover/restore_micro_service.go +++ b/pkg/datamover/restore_micro_service.go @@ -288,6 +288,7 @@ func (r *RestoreMicroService) cancelDataDownload(dd *velerov2alpha1api.DataDownl fsBackup := r.dataPathMgr.GetAsyncBR(dd.Name) if fsBackup == nil { r.OnDataDownloadCancelled(r.ctx, dd.GetNamespace(), dd.GetName()) + r.eventRecorder.EndingEvent(dd, false, datapath.EventReasonStopped, "Data path for %s exited without start", dd.Name) } else { fsBackup.Cancel() } diff --git a/pkg/datamover/restore_micro_service_test.go b/pkg/datamover/restore_micro_service_test.go index f315ef639..a53e4d6d5 100644 --- a/pkg/datamover/restore_micro_service_test.go +++ b/pkg/datamover/restore_micro_service_test.go @@ -203,8 +203,8 @@ func TestCancelDataDownload(t *testing.T) { }{ { name: "no fs restore", - expectedEventReason: datapath.EventReasonCancelled, - expectedEventMsg: "Data path for data download fake-data-download canceled", + expectedEventReason: datapath.EventReasonStopped, + expectedEventMsg: "Data path for fake-data-download exited without start", expectedErr: datapath.ErrCancelled, }, } diff --git a/pkg/podvolume/backup_micro_service.go b/pkg/podvolume/backup_micro_service.go index 3c9cbab61..11ca66676 100644 --- a/pkg/podvolume/backup_micro_service.go +++ b/pkg/podvolume/backup_micro_service.go @@ -307,6 +307,7 @@ func (r *BackupMicroService) cancelPodVolumeBackup(pvb *velerov1api.PodVolumeBac fsBackup := r.dataPathMgr.GetAsyncBR(pvb.Name) if fsBackup == nil { r.OnDataPathCancelled(r.ctx, pvb.GetNamespace(), pvb.GetName()) + r.eventRecorder.EndingEvent(pvb, false, datapath.EventReasonStopped, "Data path for %s exited without start", pvb.Name) } else { fsBackup.Cancel() } diff --git a/pkg/podvolume/backup_micro_service_test.go b/pkg/podvolume/backup_micro_service_test.go index eb10b622a..a5b6cd1f4 100644 --- a/pkg/podvolume/backup_micro_service_test.go +++ b/pkg/podvolume/backup_micro_service_test.go @@ -258,8 +258,8 @@ func TestCancelPodVolumeBackup(t *testing.T) { }{ { name: "no fs backup", - expectedEventReason: datapath.EventReasonCancelled, - expectedEventMsg: "Data path for PVB fake-pvb canceled", + expectedEventReason: datapath.EventReasonStopped, + expectedEventMsg: "Data path for fake-pvb exited without start", expectedErr: datapath.ErrCancelled, }, } diff --git a/pkg/podvolume/restore_micro_service.go b/pkg/podvolume/restore_micro_service.go index 40d6aa1fb..decf94b1b 100644 --- a/pkg/podvolume/restore_micro_service.go +++ b/pkg/podvolume/restore_micro_service.go @@ -302,6 +302,7 @@ func (r *RestoreMicroService) cancelPodVolumeRestore(pvr *velerov1api.PodVolumeR fsBackup := r.dataPathMgr.GetAsyncBR(pvr.Name) if fsBackup == nil { r.OnPvrCancelled(r.ctx, pvr.GetNamespace(), pvr.GetName()) + r.eventRecorder.EndingEvent(pvr, false, datapath.EventReasonStopped, "Data path for %s exited without start", pvr.Name) } else { fsBackup.Cancel() } diff --git a/pkg/podvolume/restore_micro_service_test.go b/pkg/podvolume/restore_micro_service_test.go index 07e2056b0..2c94ddf46 100644 --- a/pkg/podvolume/restore_micro_service_test.go +++ b/pkg/podvolume/restore_micro_service_test.go @@ -284,8 +284,8 @@ func TestCancelPodVolumeRestore(t *testing.T) { }{ { name: "no fs restore", - expectedEventReason: datapath.EventReasonCancelled, - expectedEventMsg: "Data path for PVR fake-pvr canceled", + expectedEventReason: datapath.EventReasonStopped, + expectedEventMsg: "Data path for fake-pvr exited without start", expectedErr: datapath.ErrCancelled, }, }