Skip to content

Commit e6359eb

Browse files
authored
Merge pull request #624 from PerfectMemory/feat/watch-timeouts
feat: add timeout_seconds option to Kubeclient::Client#watch_entities
2 parents 054bff2 + a071202 commit e6359eb

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ client = Kubeclient::Client.new(
221221

222222
### Timeouts
223223

224-
Watching configures the socket to never time out (however, sooner or later all watches terminate).
224+
Watching configures the socket to never time out by default (however, sooner or later all watches terminate).
225225

226226
One-off actions like `.get_*`, `.delete_*` have a configurable timeout:
227227
```ruby
@@ -625,6 +625,13 @@ client.watch_pods allow_watch_bookmarks: true do |notice|
625625
end
626626
```
627627

628+
To limit the maximum duration of a watch on the server, pass the `timeout_seconds:` param.
629+
```ruby
630+
client.watch_pods(timeout_seconds: 120, namespace: ns) do |notice|
631+
...
632+
end
633+
```
634+
628635
#### All watches come to an end!
629636

630637
While nominally the watch block *looks* like an infinite loop, that's unrealistic. Network connections eventually get severed, and kubernetes apiserver is known to terminate watches.

lib/kubeclient.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ class Client
7777
}.freeze
7878

7979
WATCH_ARGUMENTS = {
80-
'labelSelector' => :label_selector,
81-
'fieldSelector' => :field_selector,
82-
'resourceVersion' => :resource_version,
83-
'allowWatchBookmarks' => :allow_watch_bookmarks
80+
'labelSelector' => :label_selector,
81+
'fieldSelector' => :field_selector,
82+
'resourceVersion' => :resource_version,
83+
'allowWatchBookmarks' => :allow_watch_bookmarks,
84+
'timeoutSeconds' => :timeout_seconds
8485
}.freeze
8586

8687
attr_reader :api_endpoint
@@ -408,6 +409,7 @@ def faraday_client
408409
# :label_selector (string) - a selector to restrict the list of returned objects by labels.
409410
# :field_selector (string) - a selector to restrict the list of returned objects by fields.
410411
# :resource_version (string) - shows changes that occur after passed version of a resource.
412+
# :timeout_seconds (integer) - limits the duration of the call
411413
# :as (:raw|:ros) - defaults to :ros
412414
# :raw - return the raw response body as a string
413415
# :ros - return a collection of RecursiveOpenStruct objects
@@ -493,7 +495,7 @@ def delete_entity(resource_name, name, namespace = nil, delete_options: {})
493495
# :resource_version (string) - sets a limit on the resource versions that can be served
494496
# :resource_version_match (string) - determines how the resource_version constraint
495497
# will be applied
496-
# :timeout_seconds (integer) - limits the duraiton of the call
498+
# :timeout_seconds (integer) - limits the duration of the call
497499
# :continue (string) - a token used to retrieve the next chunk of entities
498500
# :as (:raw|:ros) - defaults to :ros
499501
# :raw - return the raw response body as a string

0 commit comments

Comments
 (0)