From c49d33b94d64683b4f57c5ce7d27696929cf840e Mon Sep 17 00:00:00 2001 From: Alan Clucas Date: Wed, 26 Apr 2023 17:44:22 +0000 Subject: [PATCH] feat: Add lastRetry.message (#10987) Signed-off-by: Alan Clucas --- docs/retries.md | 1 + docs/variables.md | 5 +++-- workflow/common/common.go | 2 ++ workflow/controller/operator.go | 1 + workflow/controller/operator_test.go | 3 ++- workflow/validate/validate.go | 2 ++ 6 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/retries.md b/docs/retries.md index e0618a68d950..0585f03e6034 100644 --- a/docs/retries.md +++ b/docs/retries.md @@ -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. diff --git a/docs/variables.md b/docs/variables.md index 85fd802794d2..22cd07d0496e 100644 --- a/docs/variables.md +++ b/docs/variables.md @@ -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'}}"`). diff --git a/workflow/common/common.go b/workflow/common/common.go index 65b5df466996..b9ffd8e768b5 100644 --- a/workflow/common/common.go +++ b/workflow/common/common.go @@ -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" diff --git a/workflow/controller/operator.go b/workflow/controller/operator.go index df751aa87ec0..92dae54cebc8 100644 --- a/workflow/controller/operator.go +++ b/workflow/controller/operator.go @@ -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 } diff --git a/workflow/controller/operator_test.go b/workflow/controller/operator_test.go index b905b3ae9980..e1315ff0d1c2 100644 --- a/workflow/controller/operator_test.go +++ b/workflow/controller/operator_test.go @@ -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 = ` diff --git a/workflow/validate/validate.go b/workflow/validate/validate.go index 62fb9a6ff995..cb1ad59a5568 100644 --- a/workflow/validate/validate.go +++ b/workflow/validate/validate.go @@ -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 {