Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse exit code when Outputs is not populated #13228

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,10 @@ func (woc *wfOperationCtx) processNodeRetries(node *wfv1.NodeStatus, retryStrate
if err != nil {
return nil, false, err
}
if !shouldContinue && lastChildNode.Fulfilled() {
if !shouldContinue {
return woc.markNodePhase(node.Name, lastChildNode.Phase, "retryStrategy.expression evaluated to false"), true, nil
} else {
woc.log.Debugf("node %s phase %s retryStrategy.expression evaluated to true", node.Name, lastChildNode.Phase)
}
}

Expand Down Expand Up @@ -1836,6 +1838,16 @@ func getRetryNodeChildrenIds(node *wfv1.NodeStatus, nodes wfv1.Nodes) []string {
return childrenIds
}

func extractExitCode(input string) (string, error) {
re := regexp.MustCompile(`exit code (\d+)\)`)
matches := re.FindStringSubmatch(input)
if len(matches) < 2 {
return "", fmt.Errorf("no exit code found")
}
exitCode := strings.TrimSpace(matches[1])
return exitCode, nil
}

func buildRetryStrategyLocalScope(node *wfv1.NodeStatus, nodes wfv1.Nodes) map[string]interface{} {
localScope := make(map[string]interface{})

Expand All @@ -1850,12 +1862,18 @@ func buildRetryStrategyLocalScope(node *wfv1.NodeStatus, nodes wfv1.Nodes) map[s
exitCode := "-1"
if lastChildNode.Outputs != nil && lastChildNode.Outputs.ExitCode != nil {
exitCode = *lastChildNode.Outputs.ExitCode
} else {
tmpexitCode, err := extractExitCode(lastChildNode.Message)
if err == nil {
exitCode = tmpexitCode
log.Debugf("retryStrategy extracted exit code: %s", exitCode)
}
}
localScope[common.LocalVarRetriesLastExitCode] = exitCode
localScope[common.LocalVarRetriesLastStatus] = string(lastChildNode.Phase)
localScope[common.LocalVarRetriesLastDuration] = fmt.Sprint(lastChildNode.GetDuration().Seconds())
localScope[common.LocalVarRetriesLastMessage] = lastChildNode.Message

log.Debugf("retryStrategy localScope: %v for node: %s", localScope, lastChildNode.Name)
return localScope
}

Expand Down
Loading