Skip to content

Commit

Permalink
fix: Send workflow UID to plugins. Fixes #8573 (#9784)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <[email protected]>
  • Loading branch information
alexec committed Oct 10, 2022
1 parent 514aa05 commit cd43bba
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cmd/argoexec/commands/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
2 changes: 2 additions & 0 deletions docs/executor_swagger.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | | | | |



Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/executor/objectmeta.go
Original file line number Diff line number Diff line change
@@ -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"`
}
4 changes: 4 additions & 0 deletions pkg/plugins/executor/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions workflow/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions workflow/controller/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))},
Expand Down
10 changes: 8 additions & 2 deletions workflow/executor/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
type AgentExecutor struct {
log *log.Entry
WorkflowName string
workflowUID string
ClientSet kubernetes.Interface
WorkflowInterface workflow.Interface
RESTClient rest.Interface
Expand All @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit cd43bba

Please sign in to comment.