From dc8c5f5d15873e4f26151d373ea42d0316a5aa0c Mon Sep 17 00:00:00 2001 From: KingsonKai <562419972@qq.com> Date: Fri, 30 Jun 2023 11:50:44 +0800 Subject: [PATCH] fix: Fix recovery processing logic when there is no attack target --- .../pkg/phasehandler/inject/handler.go | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/chaosmeta-inject-operator/pkg/phasehandler/inject/handler.go b/chaosmeta-inject-operator/pkg/phasehandler/inject/handler.go index 4fedc60..a962c72 100644 --- a/chaosmeta-inject-operator/pkg/phasehandler/inject/handler.go +++ b/chaosmeta-inject-operator/pkg/phasehandler/inject/handler.go @@ -265,19 +265,24 @@ func solveFinalStatus(ctx context.Context, exp *v1alpha1.Experiment) { } injectDetail := exp.Status.Detail.Inject - recoverDetail := make([]v1alpha1.ExperimentDetailUnit, len(injectDetail)) nowTime := time.Now().Format(model.TimeFormat) - for i := range injectDetail { - recoverDetail[i] = v1alpha1.ExperimentDetailUnit{ - InjectObjectName: injectDetail[i].InjectObjectName, - UID: injectDetail[i].UID, - Status: v1alpha1.CreatedStatusType, - Message: "start to recover", - StartTime: nowTime, - Backup: injectDetail[i].Backup, + exp.Status.Phase, exp.Status.UpdateTime = v1alpha1.RecoverPhaseType, nowTime + + if len(injectDetail) != 0 { + recoverDetail := make([]v1alpha1.ExperimentDetailUnit, len(injectDetail)) + for i := range injectDetail { + recoverDetail[i] = v1alpha1.ExperimentDetailUnit{ + InjectObjectName: injectDetail[i].InjectObjectName, + UID: injectDetail[i].UID, + Status: v1alpha1.CreatedStatusType, + Message: "start to recover", + StartTime: nowTime, + Backup: injectDetail[i].Backup, + } } - } - exp.Status.Phase, exp.Status.Status, exp.Status.Detail.Recover = v1alpha1.RecoverPhaseType, v1alpha1.CreatedStatusType, recoverDetail - exp.Status.UpdateTime = nowTime + exp.Status.Status, exp.Status.Detail.Recover = v1alpha1.CreatedStatusType, recoverDetail + } else { + exp.Status.Status = v1alpha1.SuccessStatusType + } }