Skip to content

Commit

Permalink
feat: add a configurable keep_alive_timeout for watches
Browse files Browse the repository at this point in the history
  • Loading branch information
jperville committed Nov 21, 2023
1 parent ca8fec9 commit 1b94a89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/kubeclient/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ module ClientMixin
DEFAULT_HTTP_PROXY_URI = nil
DEFAULT_HTTP_MAX_REDIRECTS = 10

DEFAULT_KEEP_ALIVE_TIMEOUT = 60

SEARCH_ARGUMENTS = {
'labelSelector' => :label_selector,
'fieldSelector' => :field_selector,
Expand All @@ -55,6 +57,7 @@ module ClientMixin
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

Expand All @@ -68,6 +71,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)
Expand All @@ -85,6 +89,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_file]
Expand Down Expand Up @@ -645,7 +650,8 @@ def http_options(uri)
basic_auth_password: @auth_options[:password],
headers: get_headers,
http_proxy_uri: @http_proxy_uri,
http_max_redirects: http_max_redirects
http_max_redirects: http_max_redirects,
keep_alive_timeout: keep_alive_timeout
}
options[:bearer_token_file] = @auth_options[:bearer_token_file] if @auth_options[:bearer_token_file]
if uri.scheme == 'https'
Expand Down
5 changes: 5 additions & 0 deletions lib/kubeclient/watch_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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] ||= Kubeclient::Client::DEFAULT_KEEP_ALIVE_TIMEOUT
@formatter = formatter
end

Expand Down Expand Up @@ -63,6 +64,10 @@ def build_client
)
end

if @http_options[:keep_alive_timeout].positive?
client = client.persistent(@uri.origin, timeout: @http_options[:keep_alive_timeout])
end

client
end

Expand Down

0 comments on commit 1b94a89

Please sign in to comment.