Skip to content

Commit c5c6df5

Browse files
authored
Merge pull request #168 from justinsb/allow_watch_bookmarks
Allow watch bookmark events
2 parents 9279395 + 826892e commit c5c6df5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/patterns/declarative/pkg/watch/dynamic.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/runtime"
2727
"k8s.io/apimachinery/pkg/runtime/schema"
28+
"k8s.io/apimachinery/pkg/watch"
2829
"k8s.io/client-go/dynamic"
2930
"k8s.io/client-go/rest"
3031
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -105,8 +106,10 @@ type clientObject struct {
105106
func (dw *dynamicWatch) watchUntilClosed(client dynamic.ResourceInterface, trigger schema.GroupVersionKind, options metav1.ListOptions, target metav1.ObjectMeta) {
106107
log := log.Log
107108

108-
events, err := client.Watch(context.TODO(), options)
109+
// Though we don't use the resource version, we allow bookmarks to help keep TCP connections healthy.
110+
options.AllowWatchBookmarks = true
109111

112+
events, err := client.Watch(context.TODO(), options)
110113
if err != nil {
111114
log.WithValues("kind", trigger.String()).WithValues("namespace", target.Namespace).WithValues("labels", options.LabelSelector).Error(err, "adding watch to dynamic client")
112115
return
@@ -118,6 +121,10 @@ func (dw *dynamicWatch) watchUntilClosed(client dynamic.ResourceInterface, trigg
118121
defer events.Stop()
119122

120123
for clientEvent := range events.ResultChan() {
124+
if clientEvent.Type == watch.Bookmark {
125+
// not an invalidation, we ignore it
126+
continue
127+
}
121128
log.WithValues("type", clientEvent.Type).WithValues("kind", trigger.String()).Info("broadcasting event")
122129
dw.events <- event.GenericEvent{Object: clientObject{Object: clientEvent.Object, ObjectMeta: &target}}
123130
}

0 commit comments

Comments
 (0)