Skip to content

Commit

Permalink
Merge pull request #624 from PerfectMemory/feat/watch-timeouts
Browse files Browse the repository at this point in the history
feat: add timeout_seconds option to Kubeclient::Client#watch_entities
  • Loading branch information
cben authored Dec 27, 2023
2 parents 054bff2 + a071202 commit e6359eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ client = Kubeclient::Client.new(

### Timeouts

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

One-off actions like `.get_*`, `.delete_*` have a configurable timeout:
```ruby
Expand Down Expand Up @@ -625,6 +625,13 @@ client.watch_pods allow_watch_bookmarks: true do |notice|
end
```

To limit the maximum duration of a watch on the server, pass the `timeout_seconds:` param.
```ruby
client.watch_pods(timeout_seconds: 120, namespace: ns) do |notice|
...
end
```

#### All watches come to an end!

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.
Expand Down
12 changes: 7 additions & 5 deletions lib/kubeclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ class Client
}.freeze

WATCH_ARGUMENTS = {
'labelSelector' => :label_selector,
'fieldSelector' => :field_selector,
'resourceVersion' => :resource_version,
'allowWatchBookmarks' => :allow_watch_bookmarks
'labelSelector' => :label_selector,
'fieldSelector' => :field_selector,
'resourceVersion' => :resource_version,
'allowWatchBookmarks' => :allow_watch_bookmarks,
'timeoutSeconds' => :timeout_seconds
}.freeze

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

0 comments on commit e6359eb

Please sign in to comment.