Skip to content

Commit

Permalink
fix: Add instance ID to workflowtaskresults (#8150)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec authored Mar 17, 2022
1 parent 74237a5 commit 9101c49
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
2 changes: 2 additions & 0 deletions workflow/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ const (

// EnvVarPodName contains the name of the pod (currently unused)
EnvVarPodName = "ARGO_POD_NAME"
// 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
Expand Down
5 changes: 5 additions & 0 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,11 @@ func (woc *wfOperationCtx) createEnvVars() []apiv1.EnvVar {
Value: string(woc.wf.UID),
},
}
if v := woc.controller.Config.InstanceID; v != "" {
execEnvVars = append(execEnvVars,
apiv1.EnvVar{Name: common.EnvVarInstanceID, Value: v},
)
}
if woc.controller.Config.Executor != nil {
execEnvVars = append(execEnvVars, woc.controller.Config.Executor.Env...)
}
Expand Down
44 changes: 25 additions & 19 deletions workflow/executor/taskresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package executor
import (
"context"
"encoding/json"
"os"

apierr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -36,27 +37,32 @@ func (we *WorkflowExecutor) patchTaskResult(ctx context.Context, result wfv1.Nod
}

func (we *WorkflowExecutor) createTaskResult(ctx context.Context, result wfv1.NodeResult) error {
_, err := we.taskResultClient.Create(ctx,
&wfv1.WorkflowTaskResult{
TypeMeta: metav1.TypeMeta{
taskResult := &wfv1.WorkflowTaskResult{
TypeMeta: metav1.TypeMeta{
APIVersion: workflow.APIVersion,
Kind: workflow.WorkflowTaskResultKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: we.nodeId,
Labels: map[string]string{common.LabelKeyWorkflow: we.workflow},
},
NodeResult: result,
}
taskResult.SetOwnerReferences(
[]metav1.OwnerReference{
{
APIVersion: workflow.APIVersion,
Kind: workflow.WorkflowTaskResultKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: we.nodeId,
Labels: map[string]string{common.LabelKeyWorkflow: we.workflow},
// make sure deleting the workflow, delete this result
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: workflow.APIVersion,
Kind: workflow.WorkflowKind,
Name: we.workflow,
UID: we.workflowUID,
},
},
Kind: workflow.WorkflowKind,
Name: we.workflow,
UID: we.workflowUID,
},
NodeResult: result,
},
})

if v := os.Getenv(common.EnvVarInstanceID); v != "" {
taskResult.Labels[common.LabelKeyControllerInstanceID] = v
}
_, err := we.taskResultClient.Create(ctx,
taskResult,
metav1.CreateOptions{},
)
return err
Expand Down

0 comments on commit 9101c49

Please sign in to comment.