From 45f52e0902208dd18428b8042e858aefd7e5e1f2 Mon Sep 17 00:00:00 2001 From: Khushi Chaudhari Date: Wed, 11 Aug 2021 17:26:14 -0700 Subject: [PATCH 1/4] added support for keep alive timeouts --- lib/kubeclient.rb | 5 +++++ lib/kubeclient/watch_stream.rb | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/kubeclient.rb b/lib/kubeclient.rb index a9edb2fc..7aeef37a 100644 --- a/lib/kubeclient.rb +++ b/lib/kubeclient.rb @@ -53,6 +53,7 @@ class Client DEFAULT_HTTP_PROXY_URI = nil DEFAULT_HTTP_MAX_REDIRECTS = 10 + DEFAULT_KEEP_ALIVE_TIMEOUT = 60 SEARCH_ARGUMENTS = { 'labelSelector' => :label_selector, @@ -73,6 +74,7 @@ class Client attr_reader :auth_options attr_reader :http_proxy_uri attr_reader :http_max_redirects + attr_reader :keep_alive_timeout attr_reader :headers attr_reader :discovered @@ -102,6 +104,7 @@ def initialize_client( timeouts: DEFAULT_TIMEOUTS, http_proxy_uri: DEFAULT_HTTP_PROXY_URI, http_max_redirects: DEFAULT_HTTP_MAX_REDIRECTS, + keep_alive_timeout: DEFAULT_KEEP_ALIVE_TIMEOUT, as: :ros ) validate_auth_options(auth_options) @@ -119,6 +122,7 @@ def initialize_client( @timeouts = DEFAULT_TIMEOUTS.merge(timeouts) @http_proxy_uri = http_proxy_uri ? http_proxy_uri.to_s : nil @http_max_redirects = http_max_redirects + @keep_alive_timeout = keep_alive_timeout @as = as if auth_options[:bearer_token] @@ -718,6 +722,7 @@ def http_options(uri) headers: @headers, http_proxy_uri: @http_proxy_uri, http_max_redirects: http_max_redirects + keep_alive_timeout: keep_alive_timeout } if uri.scheme == 'https' diff --git a/lib/kubeclient/watch_stream.rb b/lib/kubeclient/watch_stream.rb index aa43b5c9..00444b1b 100644 --- a/lib/kubeclient/watch_stream.rb +++ b/lib/kubeclient/watch_stream.rb @@ -11,6 +11,7 @@ def initialize(uri, http_options, formatter:) @http_client = nil @http_options = http_options @http_options[:http_max_redirects] ||= Kubeclient::Client::DEFAULT_HTTP_MAX_REDIRECTS + @http_options[:keep_alive_timeout] = 60 @formatter = formatter end From b2c39fd4d7a314373be23d3d75bda7386b74ad8e Mon Sep 17 00:00:00 2001 From: Khushi Chaudhari Date: Mon, 16 Aug 2021 08:50:54 -0700 Subject: [PATCH 2/4] keep alive timeout bug fixes --- lib/kubeclient.rb | 1 - lib/kubeclient/watch_stream.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/kubeclient.rb b/lib/kubeclient.rb index 7aeef37a..61df05cf 100644 --- a/lib/kubeclient.rb +++ b/lib/kubeclient.rb @@ -722,7 +722,6 @@ def http_options(uri) headers: @headers, http_proxy_uri: @http_proxy_uri, http_max_redirects: http_max_redirects - keep_alive_timeout: keep_alive_timeout } if uri.scheme == 'https' diff --git a/lib/kubeclient/watch_stream.rb b/lib/kubeclient/watch_stream.rb index 00444b1b..1ffab824 100644 --- a/lib/kubeclient/watch_stream.rb +++ b/lib/kubeclient/watch_stream.rb @@ -11,7 +11,7 @@ def initialize(uri, http_options, formatter:) @http_client = nil @http_options = http_options @http_options[:http_max_redirects] ||= Kubeclient::Client::DEFAULT_HTTP_MAX_REDIRECTS - @http_options[:keep_alive_timeout] = 60 + @http_options[:keep_alive_timeout] ||= Kubeclient::Client::DEFAULT_KEEP_ALIVE_TIMEOUT @formatter = formatter end From 02c41b927c88e0988d197f4ed0ea5abc14e3f975 Mon Sep 17 00:00:00 2001 From: Khushi Chaudhari Date: Fri, 20 Aug 2021 14:09:19 -0700 Subject: [PATCH 3/4] adding timeout seconds to options in watch entities --- lib/kubeclient/informer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kubeclient/informer.rb b/lib/kubeclient/informer.rb index b94c0b9c..6dbe2173 100644 --- a/lib/kubeclient/informer.rb +++ b/lib/kubeclient/informer.rb @@ -65,7 +65,7 @@ def fill_cache end def watch_to_update_cache - watcher = @client.watch_entities(@resource_name, watch: true, resource_version: @started) + watcher = @client.watch_entities(@resource_name, watch: true, resource_version: @started, timeoutSeconds: 380) stop_reason = 'disconnect' # stop watcher without using timeout From b85ec712edfa7788a0473df21bc466c1f1493e9c Mon Sep 17 00:00:00 2001 From: Khushi Chaudhari Date: Fri, 20 Aug 2021 14:10:23 -0700 Subject: [PATCH 4/4] adding timeout seconds to options in watch entities --- lib/kubeclient.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/kubeclient.rb b/lib/kubeclient.rb index 61df05cf..0fe4149c 100644 --- a/lib/kubeclient.rb +++ b/lib/kubeclient.rb @@ -287,6 +287,7 @@ def define_entity_methods # This method used to take resource_version as a param, so # this conversion is to keep backwards compatibility options = { resource_version: options } unless options.is_a?(Hash) + options[timeoutSeconds] = 380 # 6 mins 20 seconds watch_entities(entity.resource_name, options, &block) end