@@ -223,6 +223,18 @@ type Options struct {
223223 // DefaultNamespaces.
224224 DefaultUnsafeDisableDeepCopy * bool
225225
226+ // DefaultEnableWatchBookmarks requests watch events with type "BOOKMARK".
227+ // Servers that do not implement bookmarks may ignore this flag and
228+ // bookmarks are sent at the server's discretion. Clients should not
229+ // assume bookmarks are returned at any specific interval, nor may they
230+ // assume the server will send any BOOKMARK event during a session.
231+ //
232+ // This will be used for all object types, unless it is set in ByObject or
233+ // DefaultNamespaces.
234+ //
235+ // Defaults to true.
236+ DefaultEnableWatchBookmarks * bool
237+
226238 // ByObject restricts the cache's ListWatch to the desired fields per GVK at the specified object.
227239 // If unset, this will fall through to the Default* settings.
228240 ByObject map [client.Object ]ByObject
@@ -273,6 +285,15 @@ type ByObject struct {
273285 // Be very careful with this, when enabled you must DeepCopy any object before mutating it,
274286 // otherwise you will mutate the object in the cache.
275287 UnsafeDisableDeepCopy * bool
288+
289+ // EnableWatchBookmarks requests watch events with type "BOOKMARK".
290+ // Servers that do not implement bookmarks may ignore this flag and
291+ // bookmarks are sent at the server's discretion. Clients should not
292+ // assume bookmarks are returned at any specific interval, nor may they
293+ // assume the server will send any BOOKMARK event during a session.
294+ //
295+ // Defaults to true.
296+ EnableWatchBookmarks * bool
276297}
277298
278299// Config describes all potential options for a given watch.
@@ -299,6 +320,15 @@ type Config struct {
299320 // UnsafeDisableDeepCopy specifies if List and Get requests against the
300321 // cache should not DeepCopy. A nil value allows to default this.
301322 UnsafeDisableDeepCopy * bool
323+
324+ // EnableWatchBookmarks requests watch events with type "BOOKMARK".
325+ // Servers that do not implement bookmarks may ignore this flag and
326+ // bookmarks are sent at the server's discretion. Clients should not
327+ // assume bookmarks are returned at any specific interval, nor may they
328+ // assume the server will send any BOOKMARK event during a session.
329+ //
330+ // Defaults to true.
331+ EnableWatchBookmarks * bool
302332}
303333
304334// NewCacheFunc - Function for creating a new cache from the options and a rest config.
@@ -368,6 +398,7 @@ func optionDefaultsToConfig(opts *Options) Config {
368398 FieldSelector : opts .DefaultFieldSelector ,
369399 Transform : opts .DefaultTransform ,
370400 UnsafeDisableDeepCopy : opts .DefaultUnsafeDisableDeepCopy ,
401+ EnableWatchBookmarks : opts .DefaultEnableWatchBookmarks ,
371402 }
372403}
373404
@@ -377,6 +408,7 @@ func byObjectToConfig(byObject ByObject) Config {
377408 FieldSelector : byObject .Field ,
378409 Transform : byObject .Transform ,
379410 UnsafeDisableDeepCopy : byObject .UnsafeDisableDeepCopy ,
411+ EnableWatchBookmarks : byObject .EnableWatchBookmarks ,
380412 }
381413}
382414
@@ -399,6 +431,7 @@ func newCache(restConfig *rest.Config, opts Options) newCacheFunc {
399431 Transform : config .Transform ,
400432 WatchErrorHandler : opts .DefaultWatchErrorHandler ,
401433 UnsafeDisableDeepCopy : ptr .Deref (config .UnsafeDisableDeepCopy , false ),
434+ EnableWatchBookmarks : ptr .Deref (config .EnableWatchBookmarks , true ),
402435 NewInformer : opts .newInformer ,
403436 }),
404437 readerFailOnMissingInformer : opts .ReaderFailOnMissingInformer ,
@@ -508,6 +541,11 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
508541 if opts .SyncPeriod == nil {
509542 opts .SyncPeriod = & defaultSyncPeriod
510543 }
544+
545+ // Default enable watch bookmarks, unless set.
546+ if opts .DefaultEnableWatchBookmarks == nil {
547+ opts .DefaultEnableWatchBookmarks = ptr .To (true )
548+ }
511549 return opts , nil
512550}
513551
@@ -524,7 +562,9 @@ func defaultConfig(toDefault, defaultFrom Config) Config {
524562 if toDefault .UnsafeDisableDeepCopy == nil {
525563 toDefault .UnsafeDisableDeepCopy = defaultFrom .UnsafeDisableDeepCopy
526564 }
527-
565+ if toDefault .EnableWatchBookmarks == nil {
566+ toDefault .EnableWatchBookmarks = defaultFrom .EnableWatchBookmarks
567+ }
528568 return toDefault
529569}
530570
0 commit comments