From cd43bba6c87d185bd1530c03c99b874eeceba966 Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Mon, 10 Oct 2022 14:04:45 -0700 Subject: [PATCH] fix: Send workflow UID to plugins. Fixes #8573 (#9784) Signed-off-by: Alex Collins --- cmd/argoexec/commands/agent.go | 6 +++++- docs/executor_swagger.md | 2 ++ pkg/plugins/executor/objectmeta.go | 4 +++- pkg/plugins/executor/swagger.yml | 4 ++++ workflow/common/common.go | 2 ++ workflow/controller/agent.go | 1 + workflow/executor/agent.go | 10 ++++++++-- 7 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cmd/argoexec/commands/agent.go b/cmd/argoexec/commands/agent.go index b8983cd1ae3c..4b796e91dbf1 100644 --- a/cmd/argoexec/commands/agent.go +++ b/cmd/argoexec/commands/agent.go @@ -103,6 +103,10 @@ func initAgentExecutor() *executor.AgentExecutor { if !ok { log.Fatalf("Unable to determine workflow name from environment variable %s", common.EnvVarWorkflowName) } + workflowUID, ok := os.LookupEnv(common.EnvVarWorkflowUID) + if !ok { + log.Fatalf("Unable to determine workflow Uid from environment variable %s", common.EnvVarWorkflowUID) + } addresses := getPluginAddresses() names := getPluginNames() @@ -120,5 +124,5 @@ func initAgentExecutor() *executor.AgentExecutor { plugins = append(plugins, rpc.New(address, string(data))) } - return executor.NewAgentExecutor(clientSet, restClient, config, namespace, workflowName, plugins) + return executor.NewAgentExecutor(clientSet, restClient, config, namespace, workflowName, workflowUID, plugins) } diff --git a/docs/executor_swagger.md b/docs/executor_swagger.md index a2a956793656..4b27225d3aed 100644 --- a/docs/executor_swagger.md +++ b/docs/executor_swagger.md @@ -2755,6 +2755,8 @@ save/load the directory appropriately. | Name | Type | Go type | Required | Default | Description | Example | |------|------|---------|:--------:| ------- |-------------|---------| | name | string| `string` | | | | | +| namespace | string| `string` | | | | | +| uid | string| `string` | | | | | diff --git a/pkg/plugins/executor/objectmeta.go b/pkg/plugins/executor/objectmeta.go index 68fdaecea9c5..7e710bf5f211 100644 --- a/pkg/plugins/executor/objectmeta.go +++ b/pkg/plugins/executor/objectmeta.go @@ -1,5 +1,7 @@ package executor type ObjectMeta struct { - Name string `json:"name"` + Name string `json:"name"` + Namespace string `json:"namespace"` + Uid string `json:"uid"` } diff --git a/pkg/plugins/executor/swagger.yml b/pkg/plugins/executor/swagger.yml index 8f2c2fc133a0..b6146e756bf6 100644 --- a/pkg/plugins/executor/swagger.yml +++ b/pkg/plugins/executor/swagger.yml @@ -2349,6 +2349,10 @@ definitions: properties: name: type: string + namespace: + type: string + uid: + type: string type: object Outputs: description: Outputs hold parameters, artifacts, and results from a step diff --git a/workflow/common/common.go b/workflow/common/common.go index 9647e162e2a2..61d4e60fcaa6 100644 --- a/workflow/common/common.go +++ b/workflow/common/common.go @@ -119,6 +119,8 @@ const ( EnvVarInstanceID = "ARGO_INSTANCE_ID" // EnvVarWorkflowName is the name of the workflow for which the an agent is responsible for EnvVarWorkflowName = "ARGO_WORKFLOW_NAME" + // EnvVarWorkflowUID is the workflow UUID + EnvVarWorkflowUID = "ARGO_WORKFLOW_UID" // EnvVarNodeID is the node ID of the node. EnvVarNodeID = "ARGO_NODE_ID" // EnvVarPluginAddresses is a list of plugin addresses diff --git a/workflow/controller/agent.go b/workflow/controller/agent.go index 6e0a8f569b8f..6cc90c4f9d48 100644 --- a/workflow/controller/agent.go +++ b/workflow/controller/agent.go @@ -135,6 +135,7 @@ func (woc *wfOperationCtx) createAgentPod(ctx context.Context) (*apiv1.Pod, erro envVars := []apiv1.EnvVar{ {Name: common.EnvVarWorkflowName, Value: woc.wf.Name}, + {Name: common.EnvVarWorkflowUID, Value: string(woc.wf.UID)}, {Name: common.EnvAgentPatchRate, Value: env.LookupEnvStringOr(common.EnvAgentPatchRate, GetRequeueTime().String())}, {Name: common.EnvVarPluginAddresses, Value: wfv1.MustMarshallJSON(addresses(pluginSidecars))}, {Name: common.EnvVarPluginNames, Value: wfv1.MustMarshallJSON(names(pluginSidecars))}, diff --git a/workflow/executor/agent.go b/workflow/executor/agent.go index 0234268cd1d0..66fc94edb5f9 100644 --- a/workflow/executor/agent.go +++ b/workflow/executor/agent.go @@ -37,6 +37,7 @@ import ( type AgentExecutor struct { log *log.Entry WorkflowName string + workflowUID string ClientSet kubernetes.Interface WorkflowInterface workflow.Interface RESTClient rest.Interface @@ -47,13 +48,14 @@ type AgentExecutor struct { type templateExecutor = func(ctx context.Context, tmpl wfv1.Template, result *wfv1.NodeResult) (time.Duration, error) -func NewAgentExecutor(clientSet kubernetes.Interface, restClient rest.Interface, config *rest.Config, namespace, workflowName string, plugins []executorplugins.TemplateExecutor) *AgentExecutor { +func NewAgentExecutor(clientSet kubernetes.Interface, restClient rest.Interface, config *rest.Config, namespace, workflowName, workflowUID string, plugins []executorplugins.TemplateExecutor) *AgentExecutor { return &AgentExecutor{ log: log.WithField("workflow", workflowName), ClientSet: clientSet, RESTClient: restClient, Namespace: namespace, WorkflowName: workflowName, + workflowUID: workflowUID, WorkflowInterface: workflow.NewForConfigOrDie(config), consideredTasks: &sync.Map{}, plugins: plugins, @@ -352,7 +354,11 @@ func (ae *AgentExecutor) executeHTTPTemplateRequest(ctx context.Context, httpTem func (ae *AgentExecutor) executePluginTemplate(ctx context.Context, tmpl wfv1.Template, result *wfv1.NodeResult) (time.Duration, error) { args := executorplugins.ExecuteTemplateArgs{ Workflow: &executorplugins.Workflow{ - ObjectMeta: executorplugins.ObjectMeta{Name: ae.WorkflowName}, + ObjectMeta: executorplugins.ObjectMeta{ + Name: ae.WorkflowName, + Namespace: ae.Namespace, + Uid: ae.workflowUID, + }, }, Template: &tmpl, }