@@ -5,20 +5,52 @@ import (
55
66 "google.golang.org/grpc/metadata"
77
8+ v1 "k8s.io/api/core/v1"
9+
810 workflowpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflow"
911)
1012
11- type watchIntermediary struct {
13+ type workflowWatchIntermediary struct {
1214 abstractIntermediary
1315 events chan * workflowpkg.WorkflowWatchEvent
1416}
1517
16- func (w watchIntermediary ) Send (e * workflowpkg.WorkflowWatchEvent ) error {
18+ func (w workflowWatchIntermediary ) Send (e * workflowpkg.WorkflowWatchEvent ) error {
19+ w .events <- e
20+ return nil
21+ }
22+
23+ func (w workflowWatchIntermediary ) Recv () (* workflowpkg.WorkflowWatchEvent , error ) {
24+ select {
25+ case e := <- w .error :
26+ return nil , e
27+ case event := <- w .events :
28+ return event , nil
29+ }
30+ }
31+
32+ func (w * workflowWatchIntermediary ) SendHeader (metadata.MD ) error {
33+ // We invoke `SendHeader` in order to eagerly flush headers to allow us to send period
34+ // keepalives when using HTTP/1 and Server Sent Events, so we need to implement this here,
35+ // though we don't use the meta for anything.
36+ return nil
37+ }
38+
39+ func newWorkflowWatchIntermediary (ctx context.Context ) * workflowWatchIntermediary {
40+ return & workflowWatchIntermediary {newAbstractIntermediary (ctx ), make (chan * workflowpkg.WorkflowWatchEvent )}
41+ }
42+
43+ type eventWatchIntermediary struct {
44+ abstractIntermediary
45+ events chan * v1.Event
46+ }
47+
48+ func (w eventWatchIntermediary ) Send (e * v1.Event ) error {
1749 w .events <- e
1850 return nil
1951}
2052
21- func (w watchIntermediary ) Recv () (* workflowpkg. WorkflowWatchEvent , error ) {
53+ func (w eventWatchIntermediary ) Recv () (* v1. Event , error ) {
2254 select {
2355 case e := <- w .error :
2456 return nil , e
@@ -27,13 +59,13 @@ func (w watchIntermediary) Recv() (*workflowpkg.WorkflowWatchEvent, error) {
2759 }
2860}
2961
30- func (w * watchIntermediary ) SendHeader (metadata.MD ) error {
62+ func (w * eventWatchIntermediary ) SendHeader (metadata.MD ) error {
3163 // We invoke `SendHeader` in order to eagerly flush headers to allow us to send period
3264 // keepalives when using HTTP/1 and Server Sent Events, so we need to implement this here,
3365 // though we don't use the meta for anything.
3466 return nil
3567}
3668
37- func newWatchIntermediary (ctx context.Context ) * watchIntermediary {
38- return & watchIntermediary {newAbstractIntermediary (ctx ), make (chan * workflowpkg. WorkflowWatchEvent )}
69+ func newEventWatchIntermediary (ctx context.Context ) * eventWatchIntermediary {
70+ return & eventWatchIntermediary {newAbstractIntermediary (ctx ), make (chan * v1. Event )}
3971}
0 commit comments