From 5ac0e314da80667e8b3b355c55cf9e1ab9b57b34 Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Fri, 1 Apr 2022 08:06:47 -0700 Subject: [PATCH] fix: `taskresults` owned by pod rather than workflow. (#8284) Signed-off-by: Alex Collins --- cmd/argoexec/commands/root.go | 2 +- workflow/common/common.go | 4 ++-- workflow/controller/workflowpod.go | 13 +++++++++---- workflow/executor/executor.go | 13 +++++++------ workflow/executor/executor_test.go | 4 ++-- workflow/executor/taskresult.go | 8 ++++---- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/cmd/argoexec/commands/root.go b/cmd/argoexec/commands/root.go index 022205a5322b..504766b24773 100644 --- a/cmd/argoexec/commands/root.go +++ b/cmd/argoexec/commands/root.go @@ -123,10 +123,10 @@ func initExecutor() *executor.WorkflowExecutor { versioned.NewForConfigOrDie(config).ArgoprojV1alpha1().WorkflowTaskResults(namespace), restClient, podName, + types.UID(os.Getenv(common.EnvVarPodUID)), os.Getenv(common.EnvVarWorkflowName), os.Getenv(common.EnvVarNodeID), namespace, - types.UID(os.Getenv(common.EnvVarWorkflowUID)), cre, *tmpl, includeScriptOutput, diff --git a/workflow/common/common.go b/workflow/common/common.go index 594720c584b2..d5c2b89d4c54 100644 --- a/workflow/common/common.go +++ b/workflow/common/common.go @@ -103,12 +103,12 @@ const ( // EnvVarPodName contains the name of the pod (currently unused) EnvVarPodName = "ARGO_POD_NAME" + // EnvVarPodUID is the workflow's UID + EnvVarPodUID = "ARGO_POD_UID" // EnvVarInstanceID is the instance ID 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's UID - 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/workflowpod.go b/workflow/controller/workflowpod.go index 696e1af5a515..3a588d6df5f3 100644 --- a/workflow/controller/workflowpod.go +++ b/workflow/controller/workflowpod.go @@ -572,6 +572,15 @@ func (woc *wfOperationCtx) createEnvVars() []apiv1.EnvVar { }, }, }, + { + Name: common.EnvVarPodUID, + ValueFrom: &apiv1.EnvVarSource{ + FieldRef: &apiv1.ObjectFieldSelector{ + APIVersion: "v1", + FieldPath: "metadata.uid", + }, + }, + }, { Name: common.EnvVarContainerRuntimeExecutor, Value: woc.getContainerRuntimeExecutor(), @@ -588,10 +597,6 @@ func (woc *wfOperationCtx) createEnvVars() []apiv1.EnvVar { Name: common.EnvVarWorkflowName, Value: woc.wf.Name, }, - { - Name: common.EnvVarWorkflowUID, - Value: string(woc.wf.UID), - }, } if v := woc.controller.Config.InstanceID; v != "" { execEnvVars = append(execEnvVars, diff --git a/workflow/executor/executor.go b/workflow/executor/executor.go index 5eeb465982b3..1bd7cd9a2ca4 100644 --- a/workflow/executor/executor.go +++ b/workflow/executor/executor.go @@ -55,8 +55,8 @@ const ( // WorkflowExecutor is program which runs as the init/wait container type WorkflowExecutor struct { PodName string + podUID types.UID workflow string - workflowUID types.UID nodeId string Template wfv1.Template IncludeScriptOutput bool @@ -113,10 +113,11 @@ type ContainerRuntimeExecutor interface { // NewExecutor instantiates a new workflow executor func NewExecutor( clientset kubernetes.Interface, - taskSetClient argoprojv1.WorkflowTaskResultInterface, + taskResultClient argoprojv1.WorkflowTaskResultInterface, restClient rest.Interface, - podName, workflow, nodeId, namespace string, - workflowUID types.UID, + podName string, + podUID types.UID, + workflow, nodeId, namespace string, cre ContainerRuntimeExecutor, template wfv1.Template, includeScriptOutput bool, @@ -126,11 +127,11 @@ func NewExecutor( log.WithFields(log.Fields{"Steps": executorretry.Steps, "Duration": executorretry.Duration, "Factor": executorretry.Factor, "Jitter": executorretry.Jitter}).Info("Using executor retry strategy") return WorkflowExecutor{ PodName: podName, + podUID: podUID, workflow: workflow, - workflowUID: workflowUID, nodeId: nodeId, ClientSet: clientset, - taskResultClient: taskSetClient, + taskResultClient: taskResultClient, RESTClient: restClient, Namespace: namespace, RuntimeExecutor: cre, diff --git a/workflow/executor/executor_test.go b/workflow/executor/executor_test.go index cd2b459089e0..2bd6c14370dd 100644 --- a/workflow/executor/executor_test.go +++ b/workflow/executor/executor_test.go @@ -22,7 +22,7 @@ import ( const ( fakePodName = "fake-test-pod-1234567890" fakeWorkflow = "my-wf" - fakeWorkflowUID = "my-wf-uid" + fakePodUID = "my-pod-uid" fakeNodeID = "my-node-id" fakeNamespace = "default" fakeContainerName = "main" @@ -399,10 +399,10 @@ func TestMonitorProgress(t *testing.T) { taskResults, nil, fakePodName, + fakePodUID, fakeWorkflow, fakeNodeID, fakeNamespace, - fakeWorkflowUID, &mocks.ContainerRuntimeExecutor{}, wfv1.Template{}, false, diff --git a/workflow/executor/taskresult.go b/workflow/executor/taskresult.go index 7ecedbcd7d7c..1d347437752f 100644 --- a/workflow/executor/taskresult.go +++ b/workflow/executor/taskresult.go @@ -51,10 +51,10 @@ func (we *WorkflowExecutor) createTaskResult(ctx context.Context, result wfv1.No taskResult.SetOwnerReferences( []metav1.OwnerReference{ { - APIVersion: workflow.APIVersion, - Kind: workflow.WorkflowKind, - Name: we.workflow, - UID: we.workflowUID, + APIVersion: "v1", + Kind: "pods", + Name: we.PodName, + UID: we.podUID, }, })