From 1760099fe7ed1794c925bb7ea1a4a05145440720 Mon Sep 17 00:00:00 2001 From: Tianchu Zhao Date: Tue, 20 Jul 2021 23:21:00 +1000 Subject: [PATCH] fix(controller): allow workflow.duration to pass validator Signed-off-by: Tianchu Zhao --- examples/README.md | 2 +- examples/exit-handlers.yaml | 2 +- workflow/controller/operator_test.go | 2 +- workflow/validate/validate.go | 1 + workflow/validate/validate_test.go | 9 ++++++--- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/README.md b/examples/README.md index ae2deb042b51..04c4b114c8d4 100644 --- a/examples/README.md +++ b/examples/README.md @@ -956,7 +956,7 @@ spec: container: image: alpine:latest command: [sh, -c] - args: ["echo send e-mail: {{workflow.name}} {{workflow.status}}"] + args: ["echo send e-mail: {{workflow.name}} {{workflow.status}} {{workflow.duration}}"] - name: celebrate container: image: alpine:latest diff --git a/examples/exit-handlers.yaml b/examples/exit-handlers.yaml index 2694fd06eec1..919bd185b6c5 100644 --- a/examples/exit-handlers.yaml +++ b/examples/exit-handlers.yaml @@ -46,7 +46,7 @@ spec: # # Will print a list of all the failed steps and their messages. For more info look up the jq docs. # Note: jq is not installed by default on the "alpine:latest" image, however it can be installed with "apk add jq" - args: ["echo send e-mail: {{workflow.name}} {{workflow.status}}. Failed steps {{workflow.failures}}"] + args: ["echo send e-mail: {{workflow.name}} {{workflow.status}} {{workflow.duration}}. Failed steps {{workflow.failures}}"] - name: celebrate container: image: alpine:latest diff --git a/workflow/controller/operator_test.go b/workflow/controller/operator_test.go index b98c08760322..dda5526c6f23 100644 --- a/workflow/controller/operator_test.go +++ b/workflow/controller/operator_test.go @@ -3202,7 +3202,7 @@ spec: container: image: alpine:latest command: [sh, -c] - args: ["echo send e-mail: {{workflow.name}} {{workflow.status}}. Failed steps {{workflow.failures}}"] + args: ["echo send e-mail: {{workflow.name}} {{workflow.status}} {{workflow.duration}}. Failed steps {{workflow.failures}}"] ` func TestStepsOnExitFailures(t *testing.T) { diff --git a/workflow/validate/validate.go b/workflow/validate/validate.go index 7340897862ac..f6641c2f0f10 100644 --- a/workflow/validate/validate.go +++ b/workflow/validate/validate.go @@ -561,6 +561,7 @@ func resolveAllVariables(scope map[string]interface{}, tmplStr string) error { } else if strings.HasPrefix(tag, common.GlobalVarWorkflowCreationTimestamp) { } else if strings.HasPrefix(tag, common.GlobalVarWorkflowCronScheduleTime) { // Allow runtime resolution for "scheduledTime" which will pass from CronWorkflow + } else if strings.HasPrefix(tag, common.GlobalVarWorkflowDuration) { } else { return fmt.Errorf("failed to resolve {{%s}}", tag) } diff --git a/workflow/validate/validate_test.go b/workflow/validate/validate_test.go index af374d5f9ee0..59a155834b6a 100644 --- a/workflow/validate/validate_test.go +++ b/workflow/validate/validate_test.go @@ -970,7 +970,7 @@ spec: container: image: alpine:latest command: [sh, -c] - args: ["echo {{workflow.status}} {{workflow.uid}}"] + args: ["echo {{workflow.status}} {{workflow.uid}} {{workflow.duration}}"] ` var workflowStatusNotOnExit = ` @@ -2172,7 +2172,9 @@ spec: - name: uid value: "{{workflow.uid}}" - name: priority - value: "{{workflow.priority}}" + value: "{{workflow.priority}}" + - name: duration + value: "{{workflow.duration}}" - name: whalesay inputs: @@ -2182,10 +2184,11 @@ spec: - name: serviceAccountName - name: uid - name: priority + - name: duration container: image: docker/whalesay:latest command: [cowsay] - args: ["name: {{inputs.parameters.name}} namespace: {{inputs.parameters.namespace}} serviceAccountName: {{inputs.parameters.serviceAccountName}} uid: {{inputs.parameters.uid}} priority: {{inputs.parameters.priority}}"] + args: ["name: {{inputs.parameters.name}} namespace: {{inputs.parameters.namespace}} serviceAccountName: {{inputs.parameters.serviceAccountName}} uid: {{inputs.parameters.uid}} priority: {{inputs.parameters.priority}} duration: {{inputs.parameters.duration}}"] ` func TestWorkflowGlobalVariables(t *testing.T) {