Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 1008 argo wait and argo submit --wait should exit 1 if workflow fails #1467

Merged
merged 4 commits into from
Jul 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}