diff --git a/flytepropeller/pkg/controller/nodes/array/handler.go b/flytepropeller/pkg/controller/nodes/array/handler.go index 0f9e95f19b..7068b5a432 100644 --- a/flytepropeller/pkg/controller/nodes/array/handler.go +++ b/flytepropeller/pkg/controller/nodes/array/handler.go @@ -564,17 +564,7 @@ func (a *arrayNodeHandler) Handle(ctx context.Context, nCtx interfaces.NodeExecu // report to admin through a TaskExecutionEvent. if eventRecorder.finalizeRequired(ctx) { // determine task phase from ArrayNodePhase - taskPhase := idlcore.TaskExecution_UNDEFINED - switch currentArrayNodePhase { - case v1alpha1.ArrayNodePhaseNone: - taskPhase = idlcore.TaskExecution_QUEUED - case v1alpha1.ArrayNodePhaseExecuting: - taskPhase = idlcore.TaskExecution_RUNNING - case v1alpha1.ArrayNodePhaseSucceeding: - taskPhase = idlcore.TaskExecution_SUCCEEDED - case v1alpha1.ArrayNodePhaseFailing: - taskPhase = idlcore.TaskExecution_FAILED - } + taskPhase := mapTaskPhase(arrayNodeState.Phase) // if the ArrayNode phase has changed we need to reset the taskPhaseVersion to 0, otherwise // increment it if we detect any changes in subNode state. @@ -641,6 +631,22 @@ func New(nodeExecutor interfaces.Node, eventConfig *config.EventConfig, scope pr }, nil } +func mapTaskPhase(arrayNodePhase v1alpha1.ArrayNodePhase) idlcore.TaskExecution_Phase { + taskPhase := idlcore.TaskExecution_UNDEFINED + switch arrayNodePhase { + case v1alpha1.ArrayNodePhaseNone: + taskPhase = idlcore.TaskExecution_QUEUED + case v1alpha1.ArrayNodePhaseExecuting: + taskPhase = idlcore.TaskExecution_RUNNING + case v1alpha1.ArrayNodePhaseSucceeding: + taskPhase = idlcore.TaskExecution_SUCCEEDED + case v1alpha1.ArrayNodePhaseFailing: + taskPhase = idlcore.TaskExecution_FAILED + } + + return taskPhase +} + // buildArrayNodeContext creates a custom environment to execute the ArrayNode subnode. This is uniquely required for // the arrayNodeHandler because we require the same node execution entrypoint (ie. recursiveNodeExecutor.RecursiveNodeHandler) // but need many different execution details, for example setting input values as a singular item rather than a collection, diff --git a/flytepropeller/pkg/controller/nodes/array/handler_test.go b/flytepropeller/pkg/controller/nodes/array/handler_test.go index ba0815fee6..90fdac542b 100644 --- a/flytepropeller/pkg/controller/nodes/array/handler_test.go +++ b/flytepropeller/pkg/controller/nodes/array/handler_test.go @@ -442,6 +442,7 @@ func TestHandleArrayNodePhaseNone(t *testing.T) { if len(test.expectedExternalResourcePhases) > 0 { assert.Equal(t, 1, len(eventRecorder.taskExecutionEvents)) + assert.Equal(t, mapTaskPhase(test.expectedArrayNodePhase), eventRecorder.taskExecutionEvents[0].Phase) externalResources := eventRecorder.taskExecutionEvents[0].Metadata.GetExternalResources() assert.Equal(t, len(test.expectedExternalResourcePhases), len(externalResources)) @@ -753,6 +754,7 @@ func TestHandleArrayNodePhaseExecuting(t *testing.T) { if len(test.expectedExternalResourcePhases) > 0 { assert.Equal(t, 1, len(eventRecorder.taskExecutionEvents)) + assert.Equal(t, mapTaskPhase(test.expectedArrayNodePhase), eventRecorder.taskExecutionEvents[0].Phase) externalResources := eventRecorder.taskExecutionEvents[0].Metadata.GetExternalResources() assert.Equal(t, len(test.expectedExternalResourcePhases), len(externalResources))