From 925994ec34d6227aad9905af9f691d185bcf83a0 Mon Sep 17 00:00:00 2001 From: Amit Oren Date: Tue, 25 Apr 2023 00:07:53 +0300 Subject: [PATCH] feat(operator): Add hostNodeName as a template variable (#10950) Signed-off-by: Amit Oren --- USERS.md | 1 + docs/variables.md | 2 ++ workflow/controller/operator.go | 4 ++++ workflow/controller/operator_test.go | 2 ++ workflow/validate/validate.go | 1 + workflow/validate/validate_dag_test.go | 7 +++++++ 6 files changed, 17 insertions(+) diff --git a/USERS.md b/USERS.md index 74f1b6cc96a0..778a8fa1924b 100644 --- a/USERS.md +++ b/USERS.md @@ -53,6 +53,7 @@ Currently, the following organizations are **officially** using Argo Workflows: 1. [Commodus Tech](https://www.commodus.tech) 1. [Concierge Render](https://www.conciergerender.com) 1. [Cookpad](https://cookpad.com/) +1. [Coralogix](https://coralogix.com) 1. [CoreFiling](https://www.corefiling.com/) 1. [CoreWeave Cloud](https://www.coreweave.com) 1. [Cratejoy](https://www.cratejoy.com/) diff --git a/docs/variables.md b/docs/variables.md index bf7a2f334848..85fd802794d2 100644 --- a/docs/variables.md +++ b/docs/variables.md @@ -143,6 +143,7 @@ returns `0`. Please review the Sprig documentation to understand which functions | `steps..exitCode` | Exit code of any previous script or container step | | `steps..startedAt` | Time-stamp when the step started | | `steps..finishedAt` | Time-stamp when the step finished | +| `steps..hostNodeName` | Host node where task ran | | `steps..outputs.result` | Output result of any previous container or script step | | `steps..outputs.parameters` | When the previous step uses `withItems` or `withParams`, this contains a JSON array of the output parameter maps of each invocation | | `steps..outputs.parameters.` | Output parameter of any previous step. When the previous step uses `withItems` or `withParams`, this contains a JSON array of the output parameter values of each invocation | @@ -159,6 +160,7 @@ returns `0`. Please review the Sprig documentation to understand which functions | `tasks..exitCode` | Exit code of any previous script or container task | | `tasks..startedAt` | Time-stamp when the task started | | `tasks..finishedAt` | Time-stamp when the task finished | +| `tasks..hostNodeName` | Host node where task ran | | `tasks..outputs.result` | Output result of any previous container or script task | | `tasks..outputs.parameters` | When the previous task uses `withItems` or `withParams`, this contains a JSON array of the output parameter maps of each invocation | | `tasks..outputs.parameters.` | Output parameter of any previous task. When the previous task uses `withItems` or `withParams`, this contains a JSON array of the output parameter values of each invocation | diff --git a/workflow/controller/operator.go b/workflow/controller/operator.go index a58870bd18f9..70eb8586d41a 100644 --- a/workflow/controller/operator.go +++ b/workflow/controller/operator.go @@ -2861,6 +2861,10 @@ func (woc *wfOperationCtx) buildLocalScope(scope *wfScope, prefix string, node * key := fmt.Sprintf("%s.status", prefix) scope.addParamToScope(key, string(node.Phase)) } + if node.HostNodeName != "" { + key := fmt.Sprintf("%s.hostNodeName", prefix) + scope.addParamToScope(key, string(node.HostNodeName)) + } woc.addOutputsToLocalScope(prefix, node.Outputs, scope) } diff --git a/workflow/controller/operator_test.go b/workflow/controller/operator_test.go index de1d61ffd7c8..b2e3eb1bfe6b 100644 --- a/workflow/controller/operator_test.go +++ b/workflow/controller/operator_test.go @@ -4021,6 +4021,7 @@ status: cpu: 10 memory: 0 startedAt: "2020-04-02T16:29:18Z" + hostNodeName: ip-127-0-1-1 templateName: influxdb type: Pod daemon-step-dvbnn-3639466923: @@ -4065,6 +4066,7 @@ func TestRetryNodeOutputs(t *testing.T) { assert.Contains(t, scope.scope, "steps.influx.id") assert.Contains(t, scope.scope, "steps.influx.startedAt") assert.Contains(t, scope.scope, "steps.influx.finishedAt") + assert.Contains(t, scope.scope, "steps.influx.hostNodeName") } var workflowWithPVCAndFailingStep = ` diff --git a/workflow/validate/validate.go b/workflow/validate/validate.go index 19f6daeda5e1..a7e967443e83 100644 --- a/workflow/validate/validate.go +++ b/workflow/validate/validate.go @@ -963,6 +963,7 @@ func (ctx *templateValidationCtx) addOutputsToScope(tmpl *wfv1.Template, prefix scope[fmt.Sprintf("%s.id", prefix)] = true scope[fmt.Sprintf("%s.startedAt", prefix)] = true scope[fmt.Sprintf("%s.finishedAt", prefix)] = true + scope[fmt.Sprintf("%s.hostNodeName", prefix)] = true if tmpl.Daemon != nil && *tmpl.Daemon { scope[fmt.Sprintf("%s.ip", prefix)] = true } diff --git a/workflow/validate/validate_dag_test.go b/workflow/validate/validate_dag_test.go index 6d5b399aaed4..fcbb21968da9 100644 --- a/workflow/validate/validate_dag_test.go +++ b/workflow/validate/validate_dag_test.go @@ -143,6 +143,7 @@ spec: - name: startedat - name: finishedat - name: id + - name: hostnodename container: image: alpine:3.7 command: [echo, "{{inputs.parameters.message}}"] @@ -166,6 +167,8 @@ spec: value: "test" - name: id value: "1" + - name: hostnodename + value: "test" - name: B dependencies: [A] template: echo @@ -179,6 +182,8 @@ spec: value: "{{tasks.A.finishedAt}}" - name: id value: "{{tasks.A.id}}" + - name: hostnodename + value: "{{tasks.A.hostNodeName}}" - name: C dependencies: [B] template: echo @@ -192,6 +197,8 @@ spec: value: "{{tasks.A.finishedAt}}" - name: id value: "{{tasks.A.id}}" + - name: hostnodename + value: "{{tasks.A.hostNodeName}}" ` var dagResolvedVarNotAncestor = `