mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 13:55:20 +00:00
issue 8232: ensure the ending event sinked before shutdown
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
@@ -95,7 +95,7 @@ func NewBackupMicroService(ctx context.Context, client client.Client, kubeClient
|
||||
}
|
||||
|
||||
func (r *BackupMicroService) Init() error {
|
||||
r.eventRecorder = kube.NewEventRecorder(r.kubeClient, r.client.Scheme(), r.dataUploadName, r.nodeName)
|
||||
r.eventRecorder = kube.NewEventRecorder(r.kubeClient, r.client.Scheme(), r.dataUploadName, r.nodeName, r.logger)
|
||||
|
||||
handler, err := r.duInformer.AddEventHandler(
|
||||
cachetool.ResourceEventHandlerFuncs{
|
||||
@@ -222,6 +222,8 @@ func (r *BackupMicroService) RunCancelableDataPath(ctx context.Context) (string,
|
||||
log.WithError(err).Error("Async fs backup was not completed")
|
||||
}
|
||||
|
||||
r.eventRecorder.EndingEvent(du, false, datapath.EventReasonStopped, "Data path for %s stopped", du.Name)
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,15 @@ func (bt *backupMsTestHelper) Event(_ runtime.Object, _ bool, reason string, mes
|
||||
bt.eventReason = reason
|
||||
bt.eventMsg = fmt.Sprintf(message, a...)
|
||||
}
|
||||
|
||||
func (bt *backupMsTestHelper) EndingEvent(_ runtime.Object, _ bool, reason string, message string, a ...any) {
|
||||
bt.eventLock.Lock()
|
||||
defer bt.eventLock.Unlock()
|
||||
|
||||
bt.withEvent = true
|
||||
bt.eventReason = reason
|
||||
bt.eventMsg = fmt.Sprintf(message, a...)
|
||||
}
|
||||
func (bt *backupMsTestHelper) Shutdown() {}
|
||||
|
||||
func (bt *backupMsTestHelper) Marshal(v any) ([]byte, error) {
|
||||
@@ -336,7 +345,7 @@ func TestRunCancelableDataPath(t *testing.T) {
|
||||
ctx: ctxTimeout,
|
||||
kubeClientObj: []runtime.Object{duInProgress},
|
||||
dataPathStarted: true,
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s started", dataUploadName),
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s stopped", dataUploadName),
|
||||
expectedErr: "timed out waiting for fs backup to complete",
|
||||
},
|
||||
{
|
||||
@@ -347,7 +356,7 @@ func TestRunCancelableDataPath(t *testing.T) {
|
||||
result: &dataPathResult{
|
||||
err: errors.New("fake-data-path-error"),
|
||||
},
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s started", dataUploadName),
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s stopped", dataUploadName),
|
||||
expectedErr: "fake-data-path-error",
|
||||
},
|
||||
{
|
||||
@@ -358,7 +367,7 @@ func TestRunCancelableDataPath(t *testing.T) {
|
||||
result: &dataPathResult{
|
||||
result: "fake-succeed-result",
|
||||
},
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s started", dataUploadName),
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s stopped", dataUploadName),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ func NewRestoreMicroService(ctx context.Context, client client.Client, kubeClien
|
||||
}
|
||||
|
||||
func (r *RestoreMicroService) Init() error {
|
||||
r.eventRecorder = kube.NewEventRecorder(r.kubeClient, r.client.Scheme(), r.dataDownloadName, r.nodeName)
|
||||
r.eventRecorder = kube.NewEventRecorder(r.kubeClient, r.client.Scheme(), r.dataDownloadName, r.nodeName, r.logger)
|
||||
|
||||
handler, err := r.ddInformer.AddEventHandler(
|
||||
cachetool.ResourceEventHandlerFuncs{
|
||||
@@ -199,6 +199,8 @@ func (r *RestoreMicroService) RunCancelableDataPath(ctx context.Context) (string
|
||||
log.WithError(err).Error("Async fs restore was not completed")
|
||||
}
|
||||
|
||||
r.eventRecorder.EndingEvent(dd, false, datapath.EventReasonStopped, "Data path for %s stopped", dd.Name)
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
|
||||
@@ -289,7 +289,7 @@ func TestRunCancelableRestore(t *testing.T) {
|
||||
ctx: ctxTimeout,
|
||||
kubeClientObj: []runtime.Object{ddInProgress},
|
||||
dataPathStarted: true,
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s started", dataDownloadName),
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s stopped", dataDownloadName),
|
||||
expectedErr: "timed out waiting for fs restore to complete",
|
||||
},
|
||||
{
|
||||
@@ -300,7 +300,7 @@ func TestRunCancelableRestore(t *testing.T) {
|
||||
result: &dataPathResult{
|
||||
err: errors.New("fake-data-path-error"),
|
||||
},
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s started", dataDownloadName),
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s stopped", dataDownloadName),
|
||||
expectedErr: "fake-data-path-error",
|
||||
},
|
||||
{
|
||||
@@ -311,7 +311,7 @@ func TestRunCancelableRestore(t *testing.T) {
|
||||
result: &dataPathResult{
|
||||
result: "fake-succeed-result",
|
||||
},
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s started", dataDownloadName),
|
||||
expectedEventMsg: fmt.Sprintf("Data path for %s stopped", dataDownloadName),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user