diff --git a/cmd/argoexec/commands/wait.go b/cmd/argoexec/commands/wait.go index 08b93e774126..9504b3df4067 100644 --- a/cmd/argoexec/commands/wait.go +++ b/cmd/argoexec/commands/wait.go @@ -39,46 +39,35 @@ func waitContainer(ctx context.Context) error { }() // Wait for main container to complete - waitErr := wfExecutor.Wait(ctx) - if waitErr != nil { - wfExecutor.AddError(waitErr) - // do not return here so we can still try to kill sidecars & save outputs + err := wfExecutor.Wait(ctx) + if err != nil { + wfExecutor.AddError(err) } - // Capture output script result - err := wfExecutor.CaptureScriptResult(ctx) + err = wfExecutor.CaptureScriptResult(ctx) if err != nil { wfExecutor.AddError(err) - return err } // Saving logs logArt, err := wfExecutor.SaveLogs(ctx) if err != nil { wfExecutor.AddError(err) - return err } // Saving output parameters err = wfExecutor.SaveParameters(ctx) if err != nil { wfExecutor.AddError(err) - return err } // Saving output artifacts err = wfExecutor.SaveArtifacts(ctx) if err != nil { wfExecutor.AddError(err) - return err } + // Annotating pod with output err = wfExecutor.AnnotateOutputs(ctx, logArt) if err != nil { wfExecutor.AddError(err) - return err - } - - // To prevent the workflow step from completing successfully, return the error occurred during wait. - if waitErr != nil { - return waitErr } - return nil + return wfExecutor.HasError() } diff --git a/workflow/executor/executor.go b/workflow/executor/executor.go index 6f58f8ec3de3..e95a225988bb 100644 --- a/workflow/executor/executor.go +++ b/workflow/executor/executor.go @@ -728,12 +728,20 @@ func (we *WorkflowExecutor) AnnotateOutputs(ctx context.Context, logArt *wfv1.Ar return we.AddAnnotation(ctx, common.AnnotationKeyOutputs, string(outputBytes)) } -// AddError adds an error to the list of encountered errors durign execution +// AddError adds an error to the list of encountered errors during execution func (we *WorkflowExecutor) AddError(err error) { log.Errorf("executor error: %+v", err) we.errors = append(we.errors, err) } +// HasError return the first error if exist +func (we *WorkflowExecutor) HasError() error { + if len(we.errors) > 0 { + return we.errors[0] + } + return nil +} + // AddAnnotation adds an annotation to the workflow pod func (we *WorkflowExecutor) AddAnnotation(ctx context.Context, key, value string) error { return common.AddPodAnnotation(ctx, we.ClientSet, we.PodName, we.Namespace, key, value, ExecutorRetry)