Commit df8c43a2 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'configure-timeout-for-Kubeclient' into 'master'

Set timeout for Kubeclient

See merge request gitlab-org/gitlab!23970
parents 25bfc88e 09a7a7aa
...@@ -90,12 +90,21 @@ module Gitlab ...@@ -90,12 +90,21 @@ module Gitlab
attr_reader :api_prefix, :kubeclient_options attr_reader :api_prefix, :kubeclient_options
DEFAULT_KUBECLIENT_OPTIONS = {
timeouts: {
open: 10,
read: 30
}
}.freeze
# We disable redirects through 'http_max_redirects: 0', # We disable redirects through 'http_max_redirects: 0',
# so that KubeClient does not follow redirects and # so that KubeClient does not follow redirects and
# expose internal services. # expose internal services.
def initialize(api_prefix, **kubeclient_options) def initialize(api_prefix, **kubeclient_options)
@api_prefix = api_prefix @api_prefix = api_prefix
@kubeclient_options = kubeclient_options.merge(http_max_redirects: 0) @kubeclient_options = DEFAULT_KUBECLIENT_OPTIONS
.deep_merge(kubeclient_options)
.merge(http_max_redirects: 0)
validate_url! validate_url!
end end
......
...@@ -92,6 +92,16 @@ describe Gitlab::Kubernetes::KubeClient do ...@@ -92,6 +92,16 @@ describe Gitlab::Kubernetes::KubeClient do
it_behaves_like 'local address' it_behaves_like 'local address'
end end
it 'falls back to default options, but allows overriding' do
client = Gitlab::Kubernetes::KubeClient.new(api_url, {})
defaults = Gitlab::Kubernetes::KubeClient::DEFAULT_KUBECLIENT_OPTIONS
expect(client.kubeclient_options[:timeouts]).to eq(defaults[:timeouts])
client = Gitlab::Kubernetes::KubeClient.new(api_url, timeouts: { read: 7 })
expect(client.kubeclient_options[:timeouts][:read]).to eq(7)
expect(client.kubeclient_options[:timeouts][:open]).to eq(defaults[:timeouts][:open])
end
end end
describe '#core_client' do describe '#core_client' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment