kubeclient 0.6.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d79e1741f7bd3b7cfe819fdca581595fb2b94ba
4
- data.tar.gz: 4d24a9c760e92687ad894dee0bbf62380854d944
3
+ metadata.gz: d6cc6a52d6452f6d15c033635596aabc29af83ce
4
+ data.tar.gz: e56dff1999ee19dcbdfb9b29ca4155dde859b9b2
5
5
  SHA512:
6
- metadata.gz: b4bdc0b2562a03d4e0bf28987cfc4c5a5e273e2077fcb473e97b97fd47880698cfecce42fe1014db212b03922bf235d2c28469ac3f0a6a56ebf7685bbdb73226
7
- data.tar.gz: 5dd814c8b0b46163cff2362e199d33cb9bf97718852fbb346b06b4617ac1653c54ca3493c11c74b3ad72b75ce36361ad7fa5133dcbcb6bf28dd2fddd2c58517e
6
+ metadata.gz: cd96f2bd1b7dd6c2abd752194550d398541f90a14a903c033e36d03073e1a7839aeedc3f1ed87d8cf6f9f3acbbdd3fe455395e896314fc95a524e673115366d4
7
+ data.tar.gz: 33820065e18c7609bde8a4d7bc8c10f076110a07a62dbde40ea2a6b45ef3373ac9cf2adb564b16eff9800a0e457bb2cacc1f845fa3835b2800a1389247cbe70c
data/.travis.yml CHANGED
@@ -2,5 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - "2.0"
4
4
  - "2.1"
5
+ - "2.2"
5
6
  sudo: false
6
7
  cache: bundler
data/README.md CHANGED
@@ -175,12 +175,19 @@ The below example is for v1
175
175
 
176
176
  ```ruby
177
177
  service = Service.new
178
+ service.metadata = {}
178
179
  service.metadata.name = "redis-master"
179
- service.spec.port = 6379
180
- service.spec.containerPort = "redis-server"
180
+ service.metadata.namespace = 'staging'
181
+ service.spec = {}
182
+ service.spec.ports = [{ 'port' => 6379,
183
+ 'targetPort' => 'redis-server'
184
+ }]
181
185
  service.spec.selector = {}
182
186
  service.spec.selector.name = "redis"
183
187
  service.spec.selector.role = "master"
188
+ service.metadata.labels = {}
189
+ service.metadata.labels.app = 'redis'
190
+ service.metadata.labels.role = 'slave'
184
191
  client.create_service service`
185
192
  ```
186
193
 
@@ -50,7 +50,7 @@ module Kubeclient
50
50
  json_error_msg = {}
51
51
  end
52
52
  err_message = json_error_msg['message'] || e.message
53
- raise KubeException.new(e.http_code, err_message)
53
+ raise KubeException.new(e.http_code, err_message, e.response)
54
54
  end
55
55
 
56
56
  def handle_uri(uri, path)
@@ -135,20 +135,7 @@ module Kubeclient
135
135
  uri.query = URI.encode_www_form('resourceVersion' => resource_version)
136
136
  end
137
137
 
138
- options = {
139
- use_ssl: uri.scheme == 'https',
140
- ca_file: @ssl_options[:ca_file],
141
- # ruby Net::HTTP uses verify_mode instead of verify_ssl
142
- # http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html
143
- verify_mode: @ssl_options[:verify_ssl],
144
- cert: @ssl_options[:client_cert],
145
- key: @ssl_options[:client_key],
146
- basic_auth_user: @auth_options[:username],
147
- basic_auth_password: @auth_options[:password],
148
- headers: @headers
149
- }
150
-
151
- Kubeclient::Common::WatchStream.new(uri, options)
138
+ Kubeclient::Common::WatchStream.new(uri, net_http_options(uri))
152
139
  end
153
140
 
154
141
  def get_entities(entity_type, klass, options = {})
@@ -295,5 +282,27 @@ module Kubeclient
295
282
  msg = "Cannot read token file #{@auth_options[:bearer_token_file]}"
296
283
  fail ArgumentError, msg unless File.readable?(@auth_options[:bearer_token_file])
297
284
  end
285
+
286
+ def net_http_options(uri)
287
+ options = {
288
+ basic_auth_user: @auth_options[:username],
289
+ basic_auth_password: @auth_options[:password],
290
+ headers: @headers
291
+ }
292
+
293
+ if uri.scheme == 'https'
294
+ options.merge!(
295
+ use_ssl: true,
296
+ ca_file: @ssl_options[:ca_file],
297
+ cert: @ssl_options[:client_cert],
298
+ key: @ssl_options[:client_key],
299
+ # ruby Net::HTTP uses verify_mode instead of verify_ssl
300
+ # http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html
301
+ verify_mode: @ssl_options[:verify_ssl]
302
+ )
303
+ end
304
+
305
+ options
306
+ end
298
307
  end
299
308
  end
@@ -1,10 +1,11 @@
1
1
  # Kubernetes HTTP Exceptions
2
2
  class KubeException < StandardError
3
- attr_reader :error_code, :message
3
+ attr_reader :error_code, :message, :response
4
4
 
5
- def initialize(error_code, message)
5
+ def initialize(error_code, message, response)
6
6
  @error_code = error_code
7
7
  @message = message
8
+ @response = response
8
9
  end
9
10
 
10
11
  def to_s
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '0.6.0'
3
+ VERSION = '0.7.0'
4
4
  end
@@ -4,27 +4,28 @@ module Kubeclient
4
4
  module Common
5
5
  # HTTP Stream used to watch changes on entities
6
6
  class WatchStream
7
- def initialize(uri, options)
7
+ def initialize(uri, http_options, format: :json)
8
8
  @uri = uri
9
9
  @http = nil
10
- @options = options.merge(read_timeout: nil)
10
+ @http_options = http_options.merge(read_timeout: nil)
11
+ @format = format
11
12
  end
12
13
 
13
14
  def each
14
15
  @finished = false
15
- @http = Net::HTTP.start(@uri.host, @uri.port, @options)
16
+ @http = Net::HTTP.start(@uri.host, @uri.port, @http_options)
16
17
 
17
18
  buffer = ''
18
19
  request = generate_request
19
20
 
20
21
  @http.request(request) do |response|
21
22
  unless response.is_a? Net::HTTPSuccess
22
- fail KubeException.new(response.code, response.message)
23
+ fail KubeException.new(response.code, response.message, response)
23
24
  end
24
25
  response.read_body do |chunk|
25
26
  buffer << chunk
26
27
  while (line = buffer.slice!(/.+\n/))
27
- yield WatchNotice.new(JSON.parse(line))
28
+ yield @format == :json ? WatchNotice.new(JSON.parse(line)) : line.chomp
28
29
  end
29
30
  end
30
31
  end
@@ -34,12 +35,12 @@ module Kubeclient
34
35
 
35
36
  def generate_request
36
37
  request = Net::HTTP::Get.new(@uri)
37
- if @options[:basic_auth_user] && @options[:basic_auth_password]
38
- request.basic_auth @options[:basic_auth_user],
39
- @options[:basic_auth_password]
38
+ if @http_options[:basic_auth_user] && @http_options[:basic_auth_password]
39
+ request.basic_auth @http_options[:basic_auth_user],
40
+ @http_options[:basic_auth_password]
40
41
  end
41
42
 
42
- @options[:headers].each do |header, value|
43
+ @http_options.fetch(:headers, {}).each do |header, value|
43
44
  request[header.to_s] = value
44
45
  end
45
46
  request
data/test/test_helper.rb CHANGED
@@ -2,3 +2,9 @@ require 'minitest/autorun'
2
2
  require 'webmock/minitest'
3
3
  require 'json'
4
4
  require 'kubeclient'
5
+
6
+ # Assumes test files will be in a subdirectory with the same name as the
7
+ # file suffix. e.g. a file named foo.json would be a "json" subdirectory.
8
+ def open_test_file(name)
9
+ File.new(File.join(File.dirname(__FILE__), name.split('.').last, name))
10
+ end
@@ -1,9 +1,5 @@
1
1
  require 'test_helper'
2
2
 
3
- def open_test_json_file(name)
4
- File.new(File.join(File.dirname(__FILE__), 'json', name))
5
- end
6
-
7
3
  # Kubernetes client entity tests
8
4
  class KubeClientTest < MiniTest::Test
9
5
  def test_json
@@ -44,7 +40,7 @@ class KubeClientTest < MiniTest::Test
44
40
 
45
41
  def test_exception
46
42
  stub_request(:post, %r{/services})
47
- .to_return(body: open_test_json_file('namespace_exception.json'),
43
+ .to_return(body: open_test_file('namespace_exception.json'),
48
44
  status: 409)
49
45
 
50
46
  service = Kubeclient::Service.new
@@ -69,7 +65,7 @@ class KubeClientTest < MiniTest::Test
69
65
 
70
66
  def test_api
71
67
  stub_request(:get, 'http://localhost:8080/api')
72
- .to_return(status: 200, body: open_test_json_file('versions_list.json'))
68
+ .to_return(status: 200, body: open_test_file('versions_list.json'))
73
69
 
74
70
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
75
71
  response = client.api
@@ -90,7 +86,7 @@ class KubeClientTest < MiniTest::Test
90
86
 
91
87
  def test_api_valid
92
88
  stub_request(:get, 'http://localhost:8080/api')
93
- .to_return(status: 200, body: open_test_json_file('versions_list.json'))
89
+ .to_return(status: 200, body: open_test_file('versions_list.json'))
94
90
 
95
91
  args = ['http://localhost:8080/api/']
96
92
 
@@ -102,7 +98,7 @@ class KubeClientTest < MiniTest::Test
102
98
 
103
99
  def test_api_valid_with_invalid_version
104
100
  stub_request(:get, 'http://localhost:8080/api')
105
- .to_return(status: 200, body: open_test_json_file('versions_list.json'))
101
+ .to_return(status: 200, body: open_test_file('versions_list.json'))
106
102
 
107
103
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'foobar1'
108
104
  refute client.api_valid?
@@ -142,7 +138,7 @@ class KubeClientTest < MiniTest::Test
142
138
 
143
139
  def test_nonjson_exception
144
140
  stub_request(:get, %r{/servic})
145
- .to_return(body: open_test_json_file('service_illegal_json_404.json'),
141
+ .to_return(body: open_test_file('service_illegal_json_404.json'),
146
142
  status: 404)
147
143
 
148
144
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -152,13 +148,13 @@ class KubeClientTest < MiniTest::Test
152
148
  end
153
149
 
154
150
  assert_instance_of(KubeException, exception)
155
- assert_equal('404 Resource Not Found', exception.message)
151
+ assert(exception.message.include?('Not Found'))
156
152
  assert_equal(404, exception.error_code)
157
153
  end
158
154
 
159
155
  def test_entity_list
160
156
  stub_request(:get, %r{/services})
161
- .to_return(body: open_test_json_file('entity_list.json'),
157
+ .to_return(body: open_test_file('entity_list.json'),
162
158
  status: 200)
163
159
 
164
160
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -178,7 +174,7 @@ class KubeClientTest < MiniTest::Test
178
174
 
179
175
  def test_empty_list
180
176
  stub_request(:get, %r{/pods})
181
- .to_return(body: open_test_json_file('empty_pod_list.json'),
177
+ .to_return(body: open_test_file('empty_pod_list.json'),
182
178
  status: 200)
183
179
 
184
180
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -189,49 +185,49 @@ class KubeClientTest < MiniTest::Test
189
185
 
190
186
  def test_get_all
191
187
  stub_request(:get, %r{/services})
192
- .to_return(body: open_test_json_file('service_list.json'),
188
+ .to_return(body: open_test_file('service_list.json'),
193
189
  status: 200)
194
190
 
195
191
  stub_request(:get, %r{/pods})
196
- .to_return(body: open_test_json_file('pod_list.json'),
192
+ .to_return(body: open_test_file('pod_list.json'),
197
193
  status: 200)
198
194
 
199
195
  stub_request(:get, %r{/nodes})
200
- .to_return(body: open_test_json_file('node_list.json'),
196
+ .to_return(body: open_test_file('node_list.json'),
201
197
  status: 200)
202
198
 
203
199
  stub_request(:get, %r{/replicationcontrollers})
204
- .to_return(body: open_test_json_file('replication_controller_list.json'), status: 200)
200
+ .to_return(body: open_test_file('replication_controller_list.json'), status: 200)
205
201
 
206
202
  stub_request(:get, %r{/events})
207
- .to_return(body: open_test_json_file('event_list.json'), status: 200)
203
+ .to_return(body: open_test_file('event_list.json'), status: 200)
208
204
 
209
205
  stub_request(:get, %r{/endpoints})
210
- .to_return(body: open_test_json_file('endpoint_list.json'),
206
+ .to_return(body: open_test_file('endpoint_list.json'),
211
207
  status: 200)
212
208
 
213
209
  stub_request(:get, %r{/namespaces})
214
- .to_return(body: open_test_json_file('namespace_list.json'),
210
+ .to_return(body: open_test_file('namespace_list.json'),
215
211
  status: 200)
216
212
 
217
213
  stub_request(:get, %r{/secrets})
218
- .to_return(body: open_test_json_file('secret_list.json'),
214
+ .to_return(body: open_test_file('secret_list.json'),
219
215
  status: 200)
220
216
 
221
217
  stub_request(:get, %r{/resourcequotas})
222
- .to_return(body: open_test_json_file('resource_quota_list.json'),
218
+ .to_return(body: open_test_file('resource_quota_list.json'),
223
219
  status: 200)
224
220
 
225
221
  stub_request(:get, %r{/limitranges})
226
- .to_return(body: open_test_json_file('limit_range_list.json'),
222
+ .to_return(body: open_test_file('limit_range_list.json'),
227
223
  status: 200)
228
224
 
229
225
  stub_request(:get, %r{/persistentvolumes})
230
- .to_return(body: open_test_json_file('persistent_volume_list.json'),
226
+ .to_return(body: open_test_file('persistent_volume_list.json'),
231
227
  status: 200)
232
228
 
233
229
  stub_request(:get, %r{/persistentvolumeclaims})
234
- .to_return(body: open_test_json_file('persistent_volume_claim_list.json'),
230
+ .to_return(body: open_test_file('persistent_volume_claim_list.json'),
235
231
  status: 200)
236
232
 
237
233
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -260,7 +256,7 @@ class KubeClientTest < MiniTest::Test
260
256
  def test_api_bearer_token_with_params_success
261
257
  stub_request(:get, 'http://localhost:8080/api/v1/pods?labelSelector=name=redis-master')
262
258
  .with(headers: { Authorization: 'Bearer valid_token' })
263
- .to_return(body: open_test_json_file('pod_list.json'),
259
+ .to_return(body: open_test_file('pod_list.json'),
264
260
  status: 200)
265
261
 
266
262
  client = Kubeclient::Client.new 'http://localhost:8080/api/',
@@ -277,7 +273,7 @@ class KubeClientTest < MiniTest::Test
277
273
  def test_api_bearer_token_success
278
274
  stub_request(:get, 'http://localhost:8080/api/v1/pods')
279
275
  .with(headers: { Authorization: 'Bearer valid_token' })
280
- .to_return(body: open_test_json_file('pod_list.json'),
276
+ .to_return(body: open_test_file('pod_list.json'),
281
277
  status: 200)
282
278
 
283
279
  client = Kubeclient::Client.new 'http://localhost:8080/api/',
@@ -294,10 +290,11 @@ class KubeClientTest < MiniTest::Test
294
290
  def test_api_bearer_token_failure
295
291
  error_message = '"/api/v1/pods" is forbidden because ' \
296
292
  'system:anonymous cannot list on pods in'
293
+ response = OpenStruct.new(code: 401, message: error_message)
297
294
 
298
295
  stub_request(:get, 'http://localhost:8080/api/v1/pods')
299
296
  .with(headers: { Authorization: 'Bearer invalid_token' })
300
- .to_raise(KubeException.new(403, error_message))
297
+ .to_raise(KubeException.new(403, error_message, response))
301
298
 
302
299
  client = Kubeclient::Client.new 'http://localhost:8080/api/',
303
300
  auth_options: {
@@ -307,11 +304,12 @@ class KubeClientTest < MiniTest::Test
307
304
  exception = assert_raises(KubeException) { client.get_pods }
308
305
  assert_equal(403, exception.error_code)
309
306
  assert_equal(error_message, exception.message)
307
+ assert_equal(response, exception.response)
310
308
  end
311
309
 
312
310
  def test_api_basic_auth_success
313
311
  stub_request(:get, 'http://username:password@localhost:8080/api/v1/pods')
314
- .to_return(body: open_test_json_file('pod_list.json'),
312
+ .to_return(body: open_test_file('pod_list.json'),
315
313
  status: 200)
316
314
 
317
315
  client = Kubeclient::Client.new 'http://localhost:8080/api/',
@@ -331,7 +329,7 @@ class KubeClientTest < MiniTest::Test
331
329
 
332
330
  def test_api_basic_auth_back_comp_success
333
331
  stub_request(:get, 'http://username:password@localhost:8080/api/v1/pods')
334
- .to_return(body: open_test_json_file('pod_list.json'),
332
+ .to_return(body: open_test_file('pod_list.json'),
335
333
  status: 200)
336
334
 
337
335
  client = Kubeclient::Client.new 'http://localhost:8080/api/',
@@ -351,9 +349,10 @@ class KubeClientTest < MiniTest::Test
351
349
 
352
350
  def test_api_basic_auth_failure
353
351
  error_message = 'HTTP status code 401, 401 Unauthorized'
352
+ response = OpenStruct.new(code: 401, message: '401 Unauthorized')
354
353
 
355
354
  stub_request(:get, 'http://username:password@localhost:8080/api/v1/pods')
356
- .to_raise(KubeException.new(401, error_message))
355
+ .to_raise(KubeException.new(401, error_message, response))
357
356
 
358
357
  client = Kubeclient::Client.new 'http://localhost:8080/api/',
359
358
  auth_options: {
@@ -364,6 +363,7 @@ class KubeClientTest < MiniTest::Test
364
363
  exception = assert_raises(KubeException) { client.get_pods }
365
364
  assert_equal(401, exception.error_code)
366
365
  assert_equal(error_message, exception.message)
366
+ assert_equal(response, exception.response)
367
367
  assert_requested(:get,
368
368
  'http://username:password@localhost:8080/api/v1/pods',
369
369
  times: 1)
@@ -444,7 +444,7 @@ class KubeClientTest < MiniTest::Test
444
444
  def test_api_bearer_token_file_success
445
445
  stub_request(:get, 'http://localhost:8080/api/v1/pods')
446
446
  .with(headers: { Authorization: 'Bearer valid_token' })
447
- .to_return(body: open_test_json_file('pod_list.json'),
447
+ .to_return(body: open_test_file('pod_list.json'),
448
448
  status: 200)
449
449
 
450
450
  file = File.join(File.dirname(__FILE__), 'valid_token_file')
@@ -493,7 +493,7 @@ class KubeClientTest < MiniTest::Test
493
493
  def test_nil_items
494
494
  # handle https://github.com/kubernetes/kubernetes/issues/13096
495
495
  stub_request(:get, %r{/persistentvolumeclaims})
496
- .to_return(body: open_test_json_file('persistent_volume_claims_nil_items.json'),
496
+ .to_return(body: open_test_file('persistent_volume_claims_nil_items.json'),
497
497
  status: 200)
498
498
 
499
499
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class TestLimitRange < MiniTest::Test
5
5
  def test_get_from_json_v1
6
6
  stub_request(:get, %r{/limitranges})
7
- .to_return(body: open_test_json_file('limit_range.json'),
7
+ .to_return(body: open_test_file('limit_range.json'),
8
8
  status: 200)
9
9
 
10
10
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class TestNamespace < MiniTest::Test
5
5
  def test_get_namespace_v1
6
6
  stub_request(:get, %r{/namespaces})
7
- .to_return(body: open_test_json_file('namespace.json'),
7
+ .to_return(body: open_test_file('namespace.json'),
8
8
  status: 200)
9
9
 
10
10
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -38,7 +38,7 @@ class TestNamespace < MiniTest::Test
38
38
 
39
39
  def test_create_namespace
40
40
  stub_request(:post, %r{/namespaces})
41
- .to_return(body: open_test_json_file('created_namespace.json'),
41
+ .to_return(body: open_test_file('created_namespace.json'),
42
42
  status: 201)
43
43
 
44
44
  namespace = Kubeclient::Namespace.new
data/test/test_node.rb CHANGED
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class TestNode < MiniTest::Test
5
5
  def test_get_from_json_v1
6
6
  stub_request(:get, %r{/nodes})
7
- .to_return(body: open_test_json_file('node.json'),
7
+ .to_return(body: open_test_file('node.json'),
8
8
  status: 200)
9
9
 
10
10
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class TestPersistentVolume < MiniTest::Test
5
5
  def test_get_from_json_v1
6
6
  stub_request(:get, %r{/persistentvolumes})
7
- .to_return(body: open_test_json_file('persistent_volume.json'),
7
+ .to_return(body: open_test_file('persistent_volume.json'),
8
8
  status: 200)
9
9
 
10
10
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class TestPersistentVolumeClaim < MiniTest::Test
5
5
  def test_get_from_json_v1
6
6
  stub_request(:get, %r{/persistentvolumeclaims})
7
- .to_return(body: open_test_json_file('persistent_volume_claim.json'),
7
+ .to_return(body: open_test_file('persistent_volume_claim.json'),
8
8
  status: 200)
9
9
 
10
10
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
data/test/test_pod.rb CHANGED
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class TestPod < MiniTest::Test
5
5
  def test_get_from_json_v1
6
6
  stub_request(:get, %r{/pods})
7
- .to_return(body: open_test_json_file('pod.json'),
7
+ .to_return(body: open_test_file('pod.json'),
8
8
  status: 200)
9
9
 
10
10
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class TestReplicationController < MiniTest::Test
5
5
  def test_get_from_json_v1
6
6
  stub_request(:get, %r{/replicationcontrollers})
7
- .to_return(body: open_test_json_file('replication_controller.json'),
7
+ .to_return(body: open_test_file('replication_controller.json'),
8
8
  status: 200)
9
9
 
10
10
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class TestResourceQuota < MiniTest::Test
5
5
  def test_get_from_json_v1
6
6
  stub_request(:get, %r{/resourcequotas})
7
- .to_return(body: open_test_json_file('resource_quota.json'),
7
+ .to_return(body: open_test_file('resource_quota.json'),
8
8
  status: 200)
9
9
 
10
10
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
data/test/test_secret.rb CHANGED
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class TestSecret < MiniTest::Test
5
5
  def test_get_secret_v1
6
6
  stub_request(:get, %r{/secrets})
7
- .to_return(body: open_test_json_file('created_secret.json'),
7
+ .to_return(body: open_test_file('created_secret.json'),
8
8
  status: 200)
9
9
 
10
10
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -35,7 +35,7 @@ class TestSecret < MiniTest::Test
35
35
 
36
36
  def test_create_secret_v1
37
37
  stub_request(:post, %r{/secrets})
38
- .to_return(body: open_test_json_file('created_secret.json'),
38
+ .to_return(body: open_test_file('created_secret.json'),
39
39
  status: 201)
40
40
 
41
41
  secret = Kubeclient::Secret.new
data/test/test_service.rb CHANGED
@@ -24,7 +24,7 @@ class TestService < MiniTest::Test
24
24
  hash[:metadata][:labels][:name]
25
25
 
26
26
  stub_request(:post, %r{namespaces/staging/services})
27
- .to_return(body: open_test_json_file('created_service.json'),
27
+ .to_return(body: open_test_file('created_service.json'),
28
28
  status: 201)
29
29
 
30
30
  client = Kubeclient::Client.new 'http://localhost:8080/api/'
@@ -37,7 +37,7 @@ class TestService < MiniTest::Test
37
37
 
38
38
  def test_conversion_from_json_v1
39
39
  stub_request(:get, %r{/services})
40
- .to_return(body: open_test_json_file('service.json'),
40
+ .to_return(body: open_test_file('service.json'),
41
41
  status: 200)
42
42
 
43
43
  client = Kubeclient::Client.new 'http://localhost:8080/api/'
@@ -98,7 +98,7 @@ class TestService < MiniTest::Test
98
98
 
99
99
  def test_get_service
100
100
  stub_request(:get, %r{/namespaces/development/services/redis-slave})
101
- .to_return(body: open_test_json_file('service.json'),
101
+ .to_return(body: open_test_file('service.json'),
102
102
  status: 200)
103
103
 
104
104
  client = Kubeclient::Client.new 'http://localhost:8080/api/'
@@ -120,7 +120,7 @@ class TestService < MiniTest::Test
120
120
 
121
121
  stub_request(:put, %r{/services/#{name}})\
122
122
  .to_return(
123
- body: open_test_json_file('service_update.json'),
123
+ body: open_test_file('service_update.json'),
124
124
  status: 200
125
125
  )
126
126
 
data/test/test_watch.rb CHANGED
@@ -10,7 +10,7 @@ class TestWatch < MiniTest::Test
10
10
  ]
11
11
 
12
12
  stub_request(:get, %r{.*\/watch/pods})
13
- .to_return(body: open_test_json_file('watch_stream.json'),
13
+ .to_return(body: open_test_file('watch_stream.json'),
14
14
  status: 200)
15
15
 
16
16
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
@@ -34,4 +34,20 @@ class TestWatch < MiniTest::Test
34
34
  end
35
35
  end
36
36
  end
37
+
38
+ # Ensure that WatchStream respects a format that's not JSON
39
+ def test_watch_stream_text
40
+ url = 'http://www.example.com/foobar'
41
+ expected_lines = open_test_file('pod_log.txt').read.split("\n")
42
+
43
+ stub_request(:get, url)
44
+ .to_return(body: open_test_file('pod_log.txt'),
45
+ status: 200)
46
+
47
+ stream = Kubeclient::Common::WatchStream.new(URI.parse(url), {}, format: :txt)
48
+ stream.to_enum.with_index do |line, index|
49
+ assert_instance_of(String, line)
50
+ assert_equal(expected_lines[index], line)
51
+ end
52
+ end
37
53
  end
@@ -0,0 +1,6 @@
1
+ Initializing server...
2
+ ...loaded configuration
3
+ ...updated settings
4
+ ...discovered local servers
5
+ ...frobinated disks
6
+ Complete!
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubeclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.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: 2015-09-21 00:00:00.000000000 Z
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: vcr
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
@@ -98,42 +98,42 @@ dependencies:
98
98
  name: rest-client
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: activesupport
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: json
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
@@ -157,9 +157,9 @@ executables: []
157
157
  extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
- - .gitignore
161
- - .rubocop.yml
162
- - .travis.yml
160
+ - ".gitignore"
161
+ - ".rubocop.yml"
162
+ - ".travis.yml"
163
163
  - Gemfile
164
164
  - LICENSE.txt
165
165
  - README.md
@@ -219,6 +219,7 @@ files:
219
219
  - test/test_secret.rb
220
220
  - test/test_service.rb
221
221
  - test/test_watch.rb
222
+ - test/txt/pod_log.txt
222
223
  - test/valid_token_file
223
224
  homepage: https://github.com/abonas/kubeclient
224
225
  licenses:
@@ -230,17 +231,17 @@ require_paths:
230
231
  - lib
231
232
  required_ruby_version: !ruby/object:Gem::Requirement
232
233
  requirements:
233
- - - '>='
234
+ - - ">="
234
235
  - !ruby/object:Gem::Version
235
236
  version: 2.0.0
236
237
  required_rubygems_version: !ruby/object:Gem::Requirement
237
238
  requirements:
238
- - - '>='
239
+ - - ">="
239
240
  - !ruby/object:Gem::Version
240
241
  version: '0'
241
242
  requirements: []
242
243
  rubyforge_project:
243
- rubygems_version: 2.4.5
244
+ rubygems_version: 2.4.8
244
245
  signing_key:
245
246
  specification_version: 4
246
247
  summary: A client for Kubernetes REST api
@@ -292,4 +293,5 @@ test_files:
292
293
  - test/test_secret.rb
293
294
  - test/test_service.rb
294
295
  - test/test_watch.rb
296
+ - test/txt/pod_log.txt
295
297
  - test/valid_token_file