kubeclient 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kubeclient might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/.travis.yml +8 -0
- data/Gemfile-rest-client-1.8.rb +11 -0
- data/README.md +33 -1
- data/lib/kubeclient/common.rb +25 -1
- data/lib/kubeclient/version.rb +1 -1
- data/test/test_kubeclient.rb +72 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fce3b9093ea679f3884d8af4728dfc3005a0c36
|
4
|
+
data.tar.gz: 561a92297a3da43106d56ebf7bef5d0e572f0904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e250ffc5c7246e29340212a65132496e4aff7aacd88cac3906348bc1b62988104af59ac6c50adc83f036132cbd989d958cdf728afc4679f9aa1b60b4b1e4b5ff
|
7
|
+
data.tar.gz: 4d1f175cf90cbf673f16e55601bb7b86801f5a7fbd6e7ec1507517761e83733b0a45a8c43848caf608f7389e29350ad5b6f3389ec12957f1de613ed45d9d5601
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -4,9 +4,17 @@ rvm:
|
|
4
4
|
- "2.1"
|
5
5
|
- "2.2"
|
6
6
|
- "2.3.0"
|
7
|
+
gemfile:
|
8
|
+
- Gemfile
|
9
|
+
- Gemfile-rest-client-1.8.rb
|
7
10
|
sudo: false
|
8
11
|
cache: bundler
|
9
12
|
script: bundle exec rake $TASK
|
10
13
|
env:
|
11
14
|
- TASK=test
|
12
15
|
- TASK=rubocop
|
16
|
+
matrix:
|
17
|
+
exclude:
|
18
|
+
# No point running rubocop with old rest-client
|
19
|
+
- gemfile: Gemfile-rest-client-1.8.rb
|
20
|
+
env: TASK=rubocop
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# For travis to additionally test rest-client 1.x.
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in kubeclient.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
if dependencies.any? # needed for overriding with recent bundler (1.13 ?)
|
9
|
+
dependencies.delete('rest-client')
|
10
|
+
gem 'rest-client', '= 1.8.0'
|
11
|
+
end
|
data/README.md
CHANGED
@@ -51,6 +51,8 @@ uri = URI::HTTP.build(host: "somehostname", port: 8080)
|
|
51
51
|
client = Kubeclient::Client.new uri
|
52
52
|
```
|
53
53
|
|
54
|
+
### SSL
|
55
|
+
|
54
56
|
It is also possible to use https and configure ssl with:
|
55
57
|
|
56
58
|
```ruby
|
@@ -85,6 +87,8 @@ client = Kubeclient::Client.new 'https://localhost:8443/api/' , 'v1',
|
|
85
87
|
ssl_options: ssl_options
|
86
88
|
```
|
87
89
|
|
90
|
+
### Authentication
|
91
|
+
|
88
92
|
If you are using basic authentication or bearer tokens as described
|
89
93
|
[here](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/authentication.md) then you can specify one
|
90
94
|
of the following:
|
@@ -135,6 +139,8 @@ client = Kubeclient::Client.new 'https://localhost:8443/api/' , 'v1',
|
|
135
139
|
|
136
140
|
You can find information about token in [this guide](http://kubernetes.io/docs/user-guide/accessing-the-cluster/) and in [this reference](http://kubernetes.io/docs/admin/authentication/).
|
137
141
|
|
142
|
+
### Non-blocking IO
|
143
|
+
|
138
144
|
You can also use kubeclient with non-blocking sockets such as Celluloid::IO, see [here](https://github.com/httprb/http/wiki/Parallel-requests-with-Celluloid%3A%3AIO)
|
139
145
|
for details. For example:
|
140
146
|
|
@@ -148,7 +154,11 @@ client = Kubeclient::Client.new 'https://localhost:8443/api/' , 'v1',
|
|
148
154
|
socket_options: socket_options
|
149
155
|
```
|
150
156
|
|
151
|
-
|
157
|
+
This affects only `.watch_*` sockets, not one-off actions like `.get_*`, `.delete_*` etc.
|
158
|
+
|
159
|
+
### Proxies
|
160
|
+
|
161
|
+
You can also use kubeclient with an http proxy server such as tinyproxy. It can be entered as a string or a URI object.
|
152
162
|
For example:
|
153
163
|
```ruby
|
154
164
|
proxy_uri = URI::HTTP.build(host: "myproxyhost", port: 8443)
|
@@ -156,6 +166,28 @@ client = Kubeclient::Client.new('https://localhost:8443/api/',
|
|
156
166
|
:http_proxy_uri => proxy_uri)
|
157
167
|
```
|
158
168
|
|
169
|
+
|
170
|
+
### Timeouts
|
171
|
+
|
172
|
+
Watching never times out.
|
173
|
+
|
174
|
+
One-off actions like `.get_*`, `.delete_*` have a configurable timeout:
|
175
|
+
```ruby
|
176
|
+
timeouts = {
|
177
|
+
open: 10, # unit is seconds
|
178
|
+
read: nil # nil means never time out
|
179
|
+
}
|
180
|
+
client = Kubeclient::Client.new(
|
181
|
+
'https://localhost:8443/api/', timeouts: timeouts
|
182
|
+
)
|
183
|
+
```
|
184
|
+
|
185
|
+
Default timeouts match `Net::HTTP` and `RestClient`, which unfortunately depends on ruby version:
|
186
|
+
- open was infinite up to ruby 2.2, 60 seconds in 2.3+.
|
187
|
+
- read is 60 seconds.
|
188
|
+
|
189
|
+
If you want ruby-independent behavior, always specify `:open`.
|
190
|
+
|
159
191
|
### Discovery
|
160
192
|
|
161
193
|
Discovery from the kube-apiserver is done lazily on method calls so it would not change behavior.
|
data/lib/kubeclient/common.rb
CHANGED
@@ -26,6 +26,12 @@ module Kubeclient
|
|
26
26
|
ssl_socket_class: nil
|
27
27
|
}.freeze
|
28
28
|
|
29
|
+
DEFAULT_TIMEOUTS = {
|
30
|
+
# These do NOT affect watch, watching never times out.
|
31
|
+
open: Net::HTTP.new('127.0.0.1').open_timeout, # depends on ruby version
|
32
|
+
read: Net::HTTP.new('127.0.0.1').read_timeout
|
33
|
+
}.freeze
|
34
|
+
|
29
35
|
DEFAULT_HTTP_PROXY_URI = nil
|
30
36
|
|
31
37
|
SEARCH_ARGUMENTS = {
|
@@ -50,6 +56,7 @@ module Kubeclient
|
|
50
56
|
ssl_options: DEFAULT_SSL_OPTIONS,
|
51
57
|
auth_options: DEFAULT_AUTH_OPTIONS,
|
52
58
|
socket_options: DEFAULT_SOCKET_OPTIONS,
|
59
|
+
timeouts: DEFAULT_TIMEOUTS,
|
53
60
|
http_proxy_uri: DEFAULT_HTTP_PROXY_URI
|
54
61
|
)
|
55
62
|
validate_auth_options(auth_options)
|
@@ -63,6 +70,9 @@ module Kubeclient
|
|
63
70
|
@ssl_options = ssl_options
|
64
71
|
@auth_options = auth_options
|
65
72
|
@socket_options = socket_options
|
73
|
+
# Allow passing partial timeouts hash, without unspecified
|
74
|
+
# @timeouts[:foo] == nil resulting in infinite timeout.
|
75
|
+
@timeouts = DEFAULT_TIMEOUTS.merge(timeouts)
|
66
76
|
@http_proxy_uri = http_proxy_uri.to_s if http_proxy_uri
|
67
77
|
|
68
78
|
if auth_options[:bearer_token]
|
@@ -215,7 +225,9 @@ module Kubeclient
|
|
215
225
|
ssl_client_key: @ssl_options[:client_key],
|
216
226
|
proxy: @http_proxy_uri,
|
217
227
|
user: @auth_options[:username],
|
218
|
-
password: @auth_options[:password]
|
228
|
+
password: @auth_options[:password],
|
229
|
+
open_timeout: @timeouts[:open],
|
230
|
+
ClientMixin.restclient_read_timeout_option => @timeouts[:read]
|
219
231
|
}
|
220
232
|
RestClient::Resource.new(@api_endpoint.merge(path).to_s, options)
|
221
233
|
end
|
@@ -420,6 +432,18 @@ module Kubeclient
|
|
420
432
|
JSON.parse(response)
|
421
433
|
end
|
422
434
|
|
435
|
+
def self.restclient_read_timeout_option
|
436
|
+
@restclient_read_timeout_option ||=
|
437
|
+
# RestClient silently accepts unknown options, so check accessors instead.
|
438
|
+
if RestClient::Resource.instance_methods.include?(:read_timeout) # rest-client 2.0
|
439
|
+
:read_timeout
|
440
|
+
elsif RestClient::Resource.instance_methods.include?(:timeout) # rest-client 1.x
|
441
|
+
:timeout
|
442
|
+
else
|
443
|
+
fail ArgumentError("RestClient doesn't support neither :read_timeout nor :timeout")
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
423
447
|
private
|
424
448
|
|
425
449
|
def load_entities
|
data/lib/kubeclient/version.rb
CHANGED
data/test/test_kubeclient.rb
CHANGED
@@ -103,6 +103,15 @@ class KubeClientTest < MiniTest::Test
|
|
103
103
|
assert_equal(error_message, exception.message)
|
104
104
|
end
|
105
105
|
|
106
|
+
def test_api_timeout
|
107
|
+
stub_request(:get, 'http://localhost:8080/api').to_timeout
|
108
|
+
|
109
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/')
|
110
|
+
|
111
|
+
exception = assert_raises(KubeException) { client.api }
|
112
|
+
assert_match(/(timed out|timeout)/i, exception.message)
|
113
|
+
end
|
114
|
+
|
106
115
|
def test_api_valid
|
107
116
|
stub_request(:get, 'http://localhost:8080/api')
|
108
117
|
.to_return(status: 200, body: open_test_file('versions_list.json'))
|
@@ -627,6 +636,69 @@ class KubeClientTest < MiniTest::Test
|
|
627
636
|
client.get_persistent_volume_claims
|
628
637
|
end
|
629
638
|
|
639
|
+
# Timeouts
|
640
|
+
|
641
|
+
def test_timeouts_defaults
|
642
|
+
client = Kubeclient::Client.new(
|
643
|
+
'http://localhost:8080/api/'
|
644
|
+
)
|
645
|
+
rest_client = client.rest_client
|
646
|
+
assert_default_open_timeout(rest_client.open_timeout)
|
647
|
+
assert_equal(60, read_timeout(rest_client))
|
648
|
+
end
|
649
|
+
|
650
|
+
def test_timeouts_open
|
651
|
+
client = Kubeclient::Client.new(
|
652
|
+
'http://localhost:8080/api/',
|
653
|
+
timeouts: { open: 10 }
|
654
|
+
)
|
655
|
+
rest_client = client.rest_client
|
656
|
+
assert_equal(10, rest_client.open_timeout)
|
657
|
+
assert_equal(60, read_timeout(rest_client))
|
658
|
+
end
|
659
|
+
|
660
|
+
def test_timeouts_read
|
661
|
+
client = Kubeclient::Client.new(
|
662
|
+
'http://localhost:8080/api/',
|
663
|
+
timeouts: { read: 300 }
|
664
|
+
)
|
665
|
+
rest_client = client.rest_client
|
666
|
+
assert_default_open_timeout(rest_client.open_timeout)
|
667
|
+
assert_equal(300, read_timeout(rest_client))
|
668
|
+
end
|
669
|
+
|
670
|
+
def test_timeouts_both
|
671
|
+
client = Kubeclient::Client.new(
|
672
|
+
'http://localhost:8080/api/',
|
673
|
+
timeouts: { open: 10, read: 300 }
|
674
|
+
)
|
675
|
+
rest_client = client.rest_client
|
676
|
+
assert_equal(10, rest_client.open_timeout)
|
677
|
+
assert_equal(300, read_timeout(rest_client))
|
678
|
+
end
|
679
|
+
|
680
|
+
def test_timeouts_infinite
|
681
|
+
client = Kubeclient::Client.new(
|
682
|
+
'http://localhost:8080/api/',
|
683
|
+
timeouts: { open: nil, read: nil }
|
684
|
+
)
|
685
|
+
rest_client = client.rest_client
|
686
|
+
assert_nil(rest_client.open_timeout)
|
687
|
+
assert_nil(read_timeout(rest_client))
|
688
|
+
end
|
689
|
+
|
690
|
+
def read_timeout(rest_client)
|
691
|
+
rest_client.send(Kubeclient::ClientMixin.restclient_read_timeout_option)
|
692
|
+
end
|
693
|
+
|
694
|
+
def assert_default_open_timeout(actual)
|
695
|
+
if RUBY_VERSION >= '2.3'
|
696
|
+
assert_equal(60, actual)
|
697
|
+
else
|
698
|
+
assert_nil(actual)
|
699
|
+
end
|
700
|
+
end
|
701
|
+
|
630
702
|
private
|
631
703
|
|
632
704
|
# dup method creates a shallow copy which is not good in this case
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubeclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alissa Bonas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- ".rubocop.yml"
|
148
148
|
- ".travis.yml"
|
149
149
|
- Gemfile
|
150
|
+
- Gemfile-rest-client-1.8.rb
|
150
151
|
- LICENSE.txt
|
151
152
|
- README.md
|
152
153
|
- Rakefile
|
@@ -258,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
259
|
version: '0'
|
259
260
|
requirements: []
|
260
261
|
rubyforge_project:
|
261
|
-
rubygems_version: 2.
|
262
|
+
rubygems_version: 2.6.12
|
262
263
|
signing_key:
|
263
264
|
specification_version: 4
|
264
265
|
summary: A client for Kubernetes REST api
|