From dbcf64b72cd6f549f01996595e71e002f81e731c Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Fri, 11 Oct 2024 13:06:21 +0200 Subject: [PATCH] fix: handle optional steps --- .../model_test_workflow_result_extended.go | 18 ++++++++++++++---- .../testworkflowcontroller/notifier.go | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/api/v1/testkube/model_test_workflow_result_extended.go b/pkg/api/v1/testkube/model_test_workflow_result_extended.go index af2bb4c6ce..74ad947e48 100644 --- a/pkg/api/v1/testkube/model_test_workflow_result_extended.go +++ b/pkg/api/v1/testkube/model_test_workflow_result_extended.go @@ -334,7 +334,16 @@ func (r *TestWorkflowResult) HealMissingPauseStatuses() { } } -func (r *TestWorkflowResult) healPredictedStatus() { +func isStepOptional(sigSequence []TestWorkflowSignature, ref string) bool { + for i := range sigSequence { + if sigSequence[i].Ref == ref { + return sigSequence[i].Optional + } + } + return false +} + +func (r *TestWorkflowResult) healPredictedStatus(sigSequence []TestWorkflowSignature) { // Mark as aborted, when any step is aborted if r.IsAnyStepAborted() || r.Initialization.Status.AnyError() { r.PredictedStatus = common.Ptr(ABORTED_TestWorkflowStatus) @@ -343,7 +352,8 @@ func (r *TestWorkflowResult) healPredictedStatus() { // Determine if there are some steps failed for ref := range r.Steps { - if r.Steps[ref].Status != nil && r.Steps[ref].Status.AnyError() { + optional := isStepOptional(sigSequence, ref) + if r.Steps[ref].Status.Aborted() || (!optional && r.Steps[ref].Status.AnyError()) { r.PredictedStatus = common.Ptr(FAILED_TestWorkflowStatus) return } @@ -361,8 +371,8 @@ func (r *TestWorkflowResult) healStatus() { } } -func (r *TestWorkflowResult) HealStatus() { - r.healPredictedStatus() +func (r *TestWorkflowResult) HealStatus(sigSequence []TestWorkflowSignature) { + r.healPredictedStatus(sigSequence) r.healStatus() } diff --git a/pkg/testworkflows/testworkflowcontroller/notifier.go b/pkg/testworkflows/testworkflowcontroller/notifier.go index 2b418b41ad..f18d162b4e 100644 --- a/pkg/testworkflows/testworkflowcontroller/notifier.go +++ b/pkg/testworkflows/testworkflowcontroller/notifier.go @@ -358,7 +358,7 @@ func (n *notifier) reconcile() { n.result.HealTimestamps(n.sigSequence, n.scheduledAt, containerStartTs, completionTs, n.ended) n.result.HealDuration() n.result.HealMissingPauseStatuses() - n.result.HealStatus() + n.result.HealStatus(n.sigSequence) } // TODO: Optimize memory