From a071202b4cec7784202822a14c28453aa8209cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Pervill=C3=A9?= Date: Tue, 21 Nov 2023 13:15:29 +0100 Subject: [PATCH] feat: add timeout_seconds option to Kubeclient::Client#watch_entities --- README.md | 9 ++++++++- lib/kubeclient.rb | 12 +++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 50f52e03..3440e173 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/lib/kubeclient.rb b/lib/kubeclient.rb index c855b6b2..a7cde0ac 100644 --- a/lib/kubeclient.rb +++ b/lib/kubeclient.rb @@ -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 @@ -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 @@ -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