Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for keep alive timeouts #513

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/kubeclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Client

DEFAULT_HTTP_PROXY_URI = nil
DEFAULT_HTTP_MAX_REDIRECTS = 10
DEFAULT_KEEP_ALIVE_TIMEOUT = 60
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default of http gem seems to be 5 seconds: https://github.com/httprb/http/blob/v4.4.1/lib/http/options.rb#L63

I open to setting it higher by default if that's good for k8s watch connections.
This effectively controls how long we keep the watch open when server has no updates, right?
Do you know what's the default in Go or other k8s clients?

OTOH if we're not sure what's best value, we can set it 5 here to keep existing behavior, this PR will let users experiment...


SEARCH_ARGUMENTS = {
'labelSelector' => :label_selector,
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -283,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean :timeoutSeconds ?
This will override any passed-in timeout. I'm assuming you're just experimenting for now, but this can't be merged.


watch_entities(entity.resource_name, options, &block)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kubeclient/informer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/kubeclient/watch_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] ||= Kubeclient::Client::DEFAULT_KEEP_ALIVE_TIMEOUT
@formatter = formatter
end

Expand Down