Skip to content

Commit

Permalink
Fix retry node processing (#1694)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaniwaki authored and sarabala1979 committed Oct 21, 2019
1 parent 08f49d0 commit 0d0562a
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ func (woc *wfOperationCtx) requeue() {
woc.controller.wfQueue.Add(key)
}

// processNodeRetries updates the retry node state based on the child node state and the retry strategy and returns the node.
func (woc *wfOperationCtx) processNodeRetries(node *wfv1.NodeStatus, retryStrategy wfv1.RetryStrategy) (*wfv1.NodeStatus, error) {
if node.Completed() {
return node, nil
Expand Down Expand Up @@ -1161,33 +1162,26 @@ func (woc *wfOperationCtx) executeTemplate(nodeName string, orgTmpl wfv1.Templat
}
processedRetryParentNode, err := woc.processNodeRetries(retryParentNode, *processedTmpl.RetryStrategy)
if err != nil {
woc.log.Errorf("Error: %+v", err)
return woc.markNodeError(retryNodeName, err), err
}
retryParentNode = processedRetryParentNode
// The retry node might have completed by now.
if retryParentNode.Completed() {
woc.log.Errorf("Error: %+v", err)
return retryParentNode, nil
}
lastChildNode, err := woc.getLastChildNode(retryParentNode)
if err != nil {
woc.log.Errorf("Error: %+v", err)
return woc.markNodeError(retryNodeName, err), err
}
if lastChildNode != nil {
if !lastChildNode.Completed() {
// Last child node is still running.
return retryParentNode, nil
}
// All work is done in a child
nodeName = lastChildNode.Name
node = lastChildNode
} else {
// This is the first try.
nodeName = fmt.Sprintf("%s(%d)", retryNodeName, len(retryParentNode.Children))
node = nil
if lastChildNode != nil && !lastChildNode.Completed() {
// Last child node is still running.
return retryParentNode, nil
}
// This is the case the child node has been done,
// but the retry node state is still running.
// Create another child node.
nodeName = fmt.Sprintf("%s(%d)", retryNodeName, len(retryParentNode.Children))
node = nil
}

// Initialize node based on the template type.
Expand Down Expand Up @@ -1429,6 +1423,7 @@ func (woc *wfOperationCtx) markNodePhase(nodeName string, phase wfv1.NodePhase,

// markNodeError is a convenience method to mark a node with an error and set the message from the error
func (woc *wfOperationCtx) markNodeError(nodeName string, err error) *wfv1.NodeStatus {
woc.log.Errorf("Mark error node %s: %+v", nodeName, err)
return woc.markNodePhase(nodeName, wfv1.NodeError, err.Error())
}

Expand Down

0 comments on commit 0d0562a

Please sign in to comment.