Skip to content

Commit

Permalink
Fix: 1008 argo wait and argo submit --wait should exit 1 if workf…
Browse files Browse the repository at this point in the history
…low fails (argoproj#1467)

Fix: 1008 `argo wait` and `argo submit --wait` should exit 1 if workflow fails  (argoproj#1467)
  • Loading branch information
sarabala1979 committed Jul 16, 2019
1 parent 3ab7bc9 commit 007d1f8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/argo/commands/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,25 @@ func NewWaitCommand() *cobra.Command {
// WaitWorkflows waits for the given workflowNames.
func WaitWorkflows(workflowNames []string, ignoreNotFound, quiet bool) {
var wg sync.WaitGroup
wfSuccessStatus := true
for _, workflowName := range workflowNames {
wg.Add(1)
go func(name string) {
waitOnOne(name, ignoreNotFound, quiet)
if !waitOnOne(name, ignoreNotFound, quiet) {
wfSuccessStatus = false
}
wg.Done()
}(workflowName)

}
wg.Wait()

if !wfSuccessStatus {
os.Exit(1)
}
}

func waitOnOne(workflowName string, ignoreNotFound, quiet bool) {
func waitOnOne(workflowName string, ignoreNotFound, quiet bool) bool {
fieldSelector := fields.ParseSelectorOrDie(fmt.Sprintf("metadata.name=%s", workflowName))
opts := metav1.ListOptions{
FieldSelector: fieldSelector.String(),
Expand All @@ -55,7 +63,7 @@ func waitOnOne(workflowName string, ignoreNotFound, quiet bool) {
_, err := wfClient.Get(workflowName, metav1.GetOptions{})
if err != nil {
if apierr.IsNotFound(err) && ignoreNotFound {
return
return true
}
errors.CheckError(err)
}
Expand All @@ -74,9 +82,12 @@ func waitOnOne(workflowName string, ignoreNotFound, quiet bool) {
}
if !wf.Status.FinishedAt.IsZero() {
if !quiet {
fmt.Printf("%s completed at %v\n", workflowName, wf.Status.FinishedAt)
fmt.Printf("%s %s at %v\n", workflowName, wf.Status.Phase, wf.Status.FinishedAt)
}
if wf.Status.Phase == wfv1.NodeFailed || wf.Status.Phase == wfv1.NodeError {
return false
}
return
return true
}
}
}

0 comments on commit 007d1f8

Please sign in to comment.