diff --git a/cmd/argoexec/commands/data.go b/cmd/argoexec/commands/data.go index c25daf08645d..a01bb70cd173 100644 --- a/cmd/argoexec/commands/data.go +++ b/cmd/argoexec/commands/data.go @@ -3,6 +3,7 @@ package commands import ( "context" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -10,11 +11,31 @@ func NewDataCommand() *cobra.Command { command := cobra.Command{ Use: "data", Short: "Process data", - RunE: func(cmd *cobra.Command, args []string) error { - ctx := context.Background() - wfExecutor := initExecutor() - return wfExecutor.Data(ctx) + Run: func(cmd *cobra.Command, args []string) { + ctx := cmd.Context() + err := execData(ctx) + if err != nil { + log.Fatalf("%+v", err) + } }, } return &command } + +func execData(ctx context.Context) error { + wfExecutor := initExecutor() + + // Don't allow cancellation to impact capture of results, parameters, artifacts, or defers. + bgCtx := context.Background() + // Create a new empty (placeholder) task result with LabelKeyReportOutputsCompleted set to false. + wfExecutor.InitializeOutput(bgCtx) + defer wfExecutor.HandleError(bgCtx) + defer wfExecutor.FinalizeOutput(bgCtx) //Ensures the LabelKeyReportOutputsCompleted is set to true. + + err := wfExecutor.Data(ctx) + if err != nil { + wfExecutor.AddError(err) + return err + } + return nil +} diff --git a/cmd/argoexec/commands/resource.go b/cmd/argoexec/commands/resource.go index e5d8fcf32328..68b0583b6378 100644 --- a/cmd/argoexec/commands/resource.go +++ b/cmd/argoexec/commands/resource.go @@ -33,12 +33,19 @@ func NewResourceCommand() *cobra.Command { func execResource(ctx context.Context, action string) error { wfExecutor := initExecutor() - defer wfExecutor.HandleError(ctx) + + // Don't allow cancellation to impact capture of results, parameters, artifacts, or defers. + bgCtx := context.Background() + + wfExecutor.InitializeOutput(bgCtx) + defer wfExecutor.HandleError(bgCtx) + defer wfExecutor.FinalizeOutput(bgCtx) //Ensures the LabelKeyReportOutputsCompleted is set to true. err := wfExecutor.StageFiles() if err != nil { wfExecutor.AddError(err) return err } + isDelete := action == "delete" if isDelete && (wfExecutor.Template.Resource.SuccessCondition != "" || wfExecutor.Template.Resource.FailureCondition != "" || len(wfExecutor.Template.Outputs.Parameters) > 0) { err = fmt.Errorf("successCondition, failureCondition and outputs are not supported for delete action") diff --git a/test/e2e/functional_test.go b/test/e2e/functional_test.go index 30a522287876..76b270394fb1 100644 --- a/test/e2e/functional_test.go +++ b/test/e2e/functional_test.go @@ -908,6 +908,9 @@ func (s *FunctionalSuite) TestDataTransformation() { } assert.NotNil(t, status.Nodes.FindByDisplayName("process-artifact(0:foo/script.py)")) assert.NotNil(t, status.Nodes.FindByDisplayName("process-artifact(1:script.py)")) + for _, value := range status.TaskResultsCompletionStatus { + assert.True(t, value) + } }) } diff --git a/test/e2e/resource_template_test.go b/test/e2e/resource_template_test.go index 2a4916f85b2d..e8f2bbb49e9d 100644 --- a/test/e2e/resource_template_test.go +++ b/test/e2e/resource_template_test.go @@ -159,6 +159,9 @@ func (s *ResourceTemplateSuite) TestResourceTemplateWithOutputs() { assert.Equal(t, "my-pod", parameters[1].Value.String(), "metadata.name is capture for jq") } } + for _, value := range status.TaskResultsCompletionStatus { + assert.True(t, value) + } }) }