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: Maybe fix watch. Fixes #2678 #2719

Merged
merged 5 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
reconn
  • Loading branch information
alexec committed Apr 16, 2020
commit ec3655c58777ec5f6b32b5675da3bccea6a09be3
14 changes: 11 additions & 3 deletions cmd/argo/commands/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"

"github.com/argoproj/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
apierr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -58,15 +59,16 @@ func WaitWorkflows(workflowNames []string, ignoreNotFound, quiet bool) {
}
}

func waitOnOne(client workflowpkg.WorkflowServiceClient, ctx context.Context, wfName, namespace string, ignoreNotFound, quiet bool) bool {
func waitOnOne(serviceClient workflowpkg.WorkflowServiceClient, ctx context.Context, wfName, namespace string, ignoreNotFound, quiet bool) bool {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
stream, err := client.WatchWorkflows(ctx, &workflowpkg.WatchWorkflowsRequest{
req := &workflowpkg.WatchWorkflowsRequest{
Namespace: namespace,
ListOptions: &metav1.ListOptions{
FieldSelector: fields.ParseSelectorOrDie(fmt.Sprintf("metadata.name=%s", wfName)).String(),
},
})
}
stream, err := serviceClient.WatchWorkflows(ctx, req)
if err != nil {
if apierr.IsNotFound(err) && ignoreNotFound {
return true
Expand All @@ -82,6 +84,12 @@ func waitOnOne(client workflowpkg.WorkflowServiceClient, ctx context.Context, wf
}
wf := event.Object
if wf == nil {
log.Debug("Re-establishing workflow watch")
stream, err = serviceClient.WatchWorkflows(ctx, req)
if err != nil {
errors.CheckError(err)
return false
}
continue
}
if !wf.Status.FinishedAt.IsZero() {
Expand Down
15 changes: 12 additions & 3 deletions cmd/argo/commands/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/argoproj/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
Expand Down Expand Up @@ -40,19 +41,27 @@ func watchWorkflow(wfName string) {
namespace := client.Namespace()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
stream, err := serviceClient.WatchWorkflows(ctx, &workflowpkg.WatchWorkflowsRequest{
req := &workflowpkg.WatchWorkflowsRequest{
Namespace: namespace,
ListOptions: &metav1.ListOptions{
FieldSelector: fields.ParseSelectorOrDie(fmt.Sprintf("metadata.name=%s", wfName)).String(),
},
})
}
stream, err := serviceClient.WatchWorkflows(ctx, req)
errors.CheckError(err)
for {
event, err := stream.Recv()
errors.CheckError(err)
wf := event.Object
if wf == nil {
break
log.Debug("Re-establishing workflow watch")
stream, err = serviceClient.WatchWorkflows(ctx, req)
if err != nil {
errors.CheckError(err)
return
}
continue

}
printWorkflowStatus(wf)
if !wf.Status.FinishedAt.IsZero() {
Expand Down