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

feat: Add lastRetry.message #10987

Merged
merged 2 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/retries.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ access to the following variables:
- `lastRetry.exitCode`: The exit code of the last retry, or "-1" if not available
- `lastRetry.status`: The phase of the last retry: Error, Failed
- `lastRetry.duration`: The duration of the last retry, in seconds
- `lastRetry.message`: The message output from the last retry (available from version 3.5)

If `expression` evaluates to false, the step will not be retried.

Expand Down
5 changes: 3 additions & 2 deletions docs/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ When using the `expression` field within `retryStrategy`, special variables are
| Variable | Description|
|----------|------------|
| `lastRetry.exitCode` | Exit code of the last retry |
| `lastRetry.Status` | Status of the last retry |
| `lastRetry.Duration` | Duration in seconds of the last retry |
| `lastRetry.status` | Status of the last retry |
| `lastRetry.duration` | Duration in seconds of the last retry |
| `lastRetry.message` | Message output from the last retry (available from version 3.5) |

Note: These variables evaluate to a string type. If using advanced expressions, either cast them to int values (`expression: "{{=asInt(lastRetry.exitCode) >= 2}}"`) or compare them to string values (`expression: "{{=lastRetry.exitCode != '2'}}"`).

Expand Down
2 changes: 2 additions & 0 deletions workflow/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ const (
LocalVarRetriesLastStatus = "lastRetry.status"
// LocalVarRetriesLastDuration is a variable that references information about the last retry's duration, in seconds
LocalVarRetriesLastDuration = "lastRetry.duration"
// LocalVarRetriesLastMessage is a variable that references information about the last retry's failure message
LocalVarRetriesLastMessage = "lastRetry.message"

KubeConfigDefaultMountPath = "/kube/config"
KubeConfigDefaultVolumeName = "kubeconfig"
Expand Down
1 change: 1 addition & 0 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ func buildRetryStrategyLocalScope(node *wfv1.NodeStatus, nodes wfv1.Nodes) map[s
localScope[common.LocalVarRetriesLastExitCode] = exitCode
localScope[common.LocalVarRetriesLastStatus] = string(lastChildNode.Phase)
localScope[common.LocalVarRetriesLastDuration] = fmt.Sprint(lastChildNode.GetDuration().Seconds())
localScope[common.LocalVarRetriesLastMessage] = lastChildNode.Message

return localScope
}
Expand Down
3 changes: 2 additions & 1 deletion workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7861,11 +7861,12 @@ func TestBuildRetryStrategyLocalScope(t *testing.T) {

localScope := buildRetryStrategyLocalScope(retryNode, wf.Status.Nodes)

assert.Len(t, localScope, 4)
assert.Len(t, localScope, 5)
assert.Equal(t, "1", localScope[common.LocalVarRetries])
assert.Equal(t, "1", localScope[common.LocalVarRetriesLastExitCode])
assert.Equal(t, string(wfv1.NodeFailed), localScope[common.LocalVarRetriesLastStatus])
assert.Equal(t, "6", localScope[common.LocalVarRetriesLastDuration])
assert.Equal(t, "Error (exit code 1)", localScope[common.LocalVarRetriesLastMessage])
}

var exitHandlerWithRetryNodeParam = `
Expand Down
2 changes: 2 additions & 0 deletions workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,12 @@ func (ctx *templateValidationCtx) validateTemplate(tmpl *wfv1.Template, tmplCtx
localParams[common.LocalVarRetriesLastExitCode] = placeholderGenerator.NextPlaceholder()
localParams[common.LocalVarRetriesLastStatus] = placeholderGenerator.NextPlaceholder()
localParams[common.LocalVarRetriesLastDuration] = placeholderGenerator.NextPlaceholder()
localParams[common.LocalVarRetriesLastMessage] = placeholderGenerator.NextPlaceholder()
scope[common.LocalVarRetries] = placeholderGenerator.NextPlaceholder()
scope[common.LocalVarRetriesLastExitCode] = placeholderGenerator.NextPlaceholder()
scope[common.LocalVarRetriesLastStatus] = placeholderGenerator.NextPlaceholder()
scope[common.LocalVarRetriesLastDuration] = placeholderGenerator.NextPlaceholder()
scope[common.LocalVarRetriesLastMessage] = placeholderGenerator.NextPlaceholder()
}
if tmpl.IsLeaf() {
for _, art := range tmpl.Outputs.Artifacts {
Expand Down