From 3967dbc51cfc252fd9f40d29a0ce62e7a3f7fd2a Mon Sep 17 00:00:00 2001 From: Mark White Date: Fri, 12 Jul 2019 16:21:07 +0100 Subject: [PATCH 1/2] Exposed workflow priority as a variable --- docs/variables.md | 2 +- workflow/common/common.go | 4 +++- workflow/controller/operator.go | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/variables.md b/docs/variables.md index c1635b279c88..bf775fae4497 100644 --- a/docs/variables.md +++ b/docs/variables.md @@ -51,7 +51,7 @@ The following variables are made available to reference various metadata of a wo | `workflow.labels.` | Workflow labels | | `workflow.creationTimestamp` | Workflow creation timestamp formatted in RFC 3339 (e.g. `2018-08-23T05:42:49Z`) | | `workflow.creationTimestamp.` | Creation timestamp formatted with a [strftime](http://strftime.org) format character | - +| `workflow.priority` | Workflow priority | ## Exit Handler: | Variable | Description| diff --git a/workflow/common/common.go b/workflow/common/common.go index 68909a755877..c42980e436c0 100644 --- a/workflow/common/common.go +++ b/workflow/common/common.go @@ -109,8 +109,10 @@ const ( GlobalVarWorkflowUID = "workflow.uid" // GlobalVarWorkflowStatus is a global workflow variable referencing the workflow's status.phase field GlobalVarWorkflowStatus = "workflow.status" - // GlobalVarWorkflowCreationTimestamp is the workflow variable referencing the workflows metadata.creationTimestamp field + // GlobalVarWorkflowCreationTimestamp is the workflow variable referencing the workflow's metadata.creationTimestamp field GlobalVarWorkflowCreationTimestamp = "workflow.creationTimestamp" + // GlobalVarWorkflowPriority is the workflow variable referencing the workflow's priority field + GlobalVarWorkflowPriority = "workflow.priority" // LocalVarPodName is a step level variable that references the name of the pod LocalVarPodName = "pod.name" diff --git a/workflow/controller/operator.go b/workflow/controller/operator.go index 9b354a96b275..c3edc99ca5f2 100644 --- a/workflow/controller/operator.go +++ b/workflow/controller/operator.go @@ -265,6 +265,7 @@ func (woc *wfOperationCtx) setGlobalParameters() { woc.globalParams[common.GlobalVarWorkflowNamespace] = woc.wf.ObjectMeta.Namespace woc.globalParams[common.GlobalVarWorkflowUID] = string(woc.wf.ObjectMeta.UID) woc.globalParams[common.GlobalVarWorkflowCreationTimestamp] = woc.wf.ObjectMeta.CreationTimestamp.String() + woc.globalParams[common.GlobalVarWorkflowPriority] = strconv.Itoa(int(*woc.wf.Spec.Priority)) for char := range strftime.FormatChars { cTimeVar := fmt.Sprintf("%s.%s", common.GlobalVarWorkflowCreationTimestamp, string(char)) woc.globalParams[cTimeVar] = strftime.Format("%"+string(char), woc.wf.ObjectMeta.CreationTimestamp.Time) From 4e6d05cecbbccffbfaaa7a5bd5aa21bb5b01d150 Mon Sep 17 00:00:00 2001 From: Mark White Date: Thu, 18 Jul 2019 11:14:26 +0100 Subject: [PATCH 2/2] Test fix --- workflow/controller/operator.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/workflow/controller/operator.go b/workflow/controller/operator.go index c3edc99ca5f2..0971d0226772 100644 --- a/workflow/controller/operator.go +++ b/workflow/controller/operator.go @@ -265,7 +265,9 @@ func (woc *wfOperationCtx) setGlobalParameters() { woc.globalParams[common.GlobalVarWorkflowNamespace] = woc.wf.ObjectMeta.Namespace woc.globalParams[common.GlobalVarWorkflowUID] = string(woc.wf.ObjectMeta.UID) woc.globalParams[common.GlobalVarWorkflowCreationTimestamp] = woc.wf.ObjectMeta.CreationTimestamp.String() - woc.globalParams[common.GlobalVarWorkflowPriority] = strconv.Itoa(int(*woc.wf.Spec.Priority)) + if woc.wf.Spec.Priority != nil { + woc.globalParams[common.GlobalVarWorkflowPriority] = strconv.Itoa(int(*woc.wf.Spec.Priority)) + } for char := range strftime.FormatChars { cTimeVar := fmt.Sprintf("%s.%s", common.GlobalVarWorkflowCreationTimestamp, string(char)) woc.globalParams[cTimeVar] = strftime.Format("%"+string(char), woc.wf.ObjectMeta.CreationTimestamp.Time)