@@ -72,7 +72,7 @@ func (ev *subscriberEvents) startWatchWorkflow(stopCh <-chan struct{}, s cache.S
7272 handlers := cache.ResourceEventHandlerFuncs {
7373 AddFunc : func (obj interface {}) {
7474 workflowObj := obj .(* v1alpha1.Workflow )
75- workflow , err := ev .WorkflowEventHandler (workflowObj , "ADD" , startTime )
75+ workflow , err := ev .WorkflowEventHandler (nil , workflowObj , "ADD" , startTime )
7676 if err != nil {
7777 logrus .Error (err )
7878 }
@@ -81,9 +81,10 @@ func (ev *subscriberEvents) startWatchWorkflow(stopCh <-chan struct{}, s cache.S
8181 stream <- workflow
8282
8383 },
84- UpdateFunc : func (oldObj , obj interface {}) {
85- workflowObj := obj .(* v1alpha1.Workflow )
86- workflow , err := ev .WorkflowEventHandler (workflowObj , "UPDATE" , startTime )
84+ UpdateFunc : func (oldState , newState interface {}) {
85+ oldObj := oldState .(* v1alpha1.Workflow )
86+ workflowObj := newState .(* v1alpha1.Workflow )
87+ workflow , err := ev .WorkflowEventHandler (oldObj , workflowObj , "UPDATE" , startTime )
8788 if err != nil {
8889 logrus .Error (err )
8990 }
@@ -97,7 +98,7 @@ func (ev *subscriberEvents) startWatchWorkflow(stopCh <-chan struct{}, s cache.S
9798}
9899
99100// WorkflowEventHandler is responsible for extracting the required data from the event and streaming
100- func (ev * subscriberEvents ) WorkflowEventHandler (workflowObj * v1alpha1.Workflow , eventType string , startTime int64 ) (types.WorkflowEvent , error ) {
101+ func (ev * subscriberEvents ) WorkflowEventHandler (oldObj , workflowObj * v1alpha1.Workflow , eventType string , startTime int64 ) (types.WorkflowEvent , error ) {
101102 if workflowObj .Labels ["workflow_id" ] == "" {
102103 logrus .WithFields (map [string ]interface {}{
103104 "uid" : string (workflowObj .ObjectMeta .UID ),
@@ -124,7 +125,7 @@ func (ev *subscriberEvents) WorkflowEventHandler(workflowObj *v1alpha1.Workflow,
124125 nodes := make (map [string ]types.Node )
125126 logrus .Info ("Workflow RUN_ID: " , workflowObj .UID , " and event type: " , eventType )
126127
127- for _ , nodeStatus := range workflowObj .Status .Nodes {
128+ for i , nodeStatus := range workflowObj .Status .Nodes {
128129
129130 var (
130131 nodeType = string (nodeStatus .Type )
@@ -150,9 +151,16 @@ func (ev *subscriberEvents) WorkflowEventHandler(workflowObj *v1alpha1.Workflow,
150151 ChaosExp : cd ,
151152 Message : nodeStatus .Message ,
152153 }
154+
153155 if nodeType == "ChaosEngine" && cd != nil {
154- details .Phase = cd .ExperimentStatus
156+ // this happens if cd.ChaosResult == nil
157+ if oldNodeStatus , ok := oldObj .Status .Nodes [i ]; ok && oldNodeStatus .Phase == "Pending" && nodeStatus .Phase == "Running" {
158+ details .Phase = "Running"
159+ } else {
160+ details .Phase = cd .ExperimentStatus
161+ }
155162 }
163+
156164 nodes [nodeStatus .ID ] = details
157165 }
158166
0 commit comments