kubeclient 1.1.0 → 1.1.1

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: 780e4ae994bf298d7316518d27110c3a336820c5
4
- data.tar.gz: fabcc8d9f9f7900495f9dd75d8e15b3d41b34db8
3
+ metadata.gz: c1a9d1c94899f80aff5f5785eba76960e53aadd9
4
+ data.tar.gz: b0b6a866ec05f67b6128adf1567f1439c574c6dd
5
5
  SHA512:
6
- metadata.gz: dc85e7d93e8a3a042830d67ceb852ba3c946fec3636d69151382f8d5abafac415567d36ca82453ec3aca6c12df5e25d32dcde82cd2bfd4e5d27a2752bde50503
7
- data.tar.gz: 9b029e85c7b33b2d606c39cf87204c0c418e2e79acc613e8262bed142e06297aa6945352667ea72f3a9ec0c75f03ba9750e221ec540fadea227f7c0913239712
6
+ metadata.gz: 4dec2bc2ebb2dbf0155b84ec0c58da5fe4a8b7c03b05b2f6831243c08cc7d313d265c63a39a377a25a2ea27d1237d2beb65a6727d9195aa4fe710c3760acfd0e
7
+ data.tar.gz: ec7a46482a877e8329a011a4cab8705f5e839dab07dc9fbbe8c579563bd84cda46e2410b69d61d0e9095d9885306f61c67b1baf665d9ca9ddeaf7b6c7b706c8e
@@ -207,17 +207,23 @@ module Kubeclient
207
207
  end
208
208
 
209
209
  def create_entity(entity_type, entity_config, klass)
210
- # to_hash should be called because of issue #9 in recursive open
211
- # struct
210
+ # Duplicate the entity_config to a hash so that when we assign
211
+ # kind and apiVersion, this does not mutate original entity_config obj.
212
212
  hash = entity_config.to_hash
213
213
 
214
- ns_prefix = build_namespace_prefix(entity_config.metadata['table'][:namespace])
214
+ ns_prefix = build_namespace_prefix(hash[:metadata][:namespace])
215
215
 
216
216
  # TODO: temporary solution to add "kind" and apiVersion to request
217
217
  # until this issue is solved
218
218
  # https://github.com/GoogleCloudPlatform/kubernetes/issues/6439
219
- hash['kind'] = entity_type
220
- hash['apiVersion'] = @api_version
219
+ # TODO: #2 solution for
220
+ # https://github.com/kubernetes/kubernetes/issues/8115
221
+ if entity_type.eql? 'Endpoint'
222
+ hash[:kind] = resource_name(entity_type).capitalize
223
+ else
224
+ hash[:kind] = entity_type
225
+ end
226
+ hash[:apiVersion] = @api_version
221
227
  response = handle_exception do
222
228
  rest_client[ns_prefix + resource_name(entity_type)]
223
229
  .post(hash.to_json, @headers)
@@ -227,14 +233,11 @@ module Kubeclient
227
233
  end
228
234
 
229
235
  def update_entity(entity_type, entity_config)
230
- name = entity_config.metadata.name
231
- # to_hash should be called because of issue #9 in recursive open
232
- # struct
233
- hash = entity_config.to_hash
234
- ns_prefix = build_namespace_prefix(entity_config.metadata['table'][:namespace])
236
+ name = entity_config[:metadata][:name]
237
+ ns_prefix = build_namespace_prefix(entity_config[:metadata][:namespace])
235
238
  handle_exception do
236
239
  rest_client[ns_prefix + resource_name(entity_type) + "/#{name}"]
237
- .put(hash.to_json, @headers)
240
+ .put(entity_config.to_h.to_json, @headers)
238
241
  end
239
242
  end
240
243
 
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.1'
4
4
  end
@@ -0,0 +1,28 @@
1
+ {
2
+ "kind": "Endpoints",
3
+ "apiVersion": "v1",
4
+ "metadata": {
5
+ "name": "myendpoint",
6
+ "namespace": "default",
7
+ "selfLink": "/api/v1/namespaces/default/endpoints/myendpoint",
8
+ "uid": "59d05b48-dadb-11e5-937e-18037327aaeb",
9
+ "resourceVersion": "393",
10
+ "creationTimestamp": "2016-02-24T09:45:34Z"
11
+ },
12
+ "subsets": [
13
+ {
14
+ "addresses": [
15
+ {
16
+ "ip": "172.17.0.25"
17
+ }
18
+ ],
19
+ "ports": [
20
+ {
21
+ "name": "https",
22
+ "port": 6443,
23
+ "protocol": "TCP"
24
+ }
25
+ ]
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ # Endpoint entity tests
4
+ class TestEndpoint < MiniTest::Test
5
+ def test_create_endpoint
6
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
7
+ testing_ep = Kubeclient::Endpoint.new
8
+ testing_ep.metadata = {}
9
+ testing_ep.metadata.name = 'myendpoint'
10
+ testing_ep.metadata.namespace = 'default'
11
+ testing_ep.subsets = [{ 'addresses' => [{ 'ip' => '172.17.0.25' }], 'ports' =>
12
+ [{ 'name' => 'https',
13
+ 'port' => 6443,
14
+ 'protocol' => 'TCP' }] }]
15
+
16
+ req_body = "{\"metadata\":{\"name\":\"myendpoint\",\"namespace\":\"default\"}," \
17
+ "\"subsets\":[{\"addresses\":[{\"ip\":\"172.17.0.25\"}],\"ports\":[{\"name\":\"https\"," \
18
+ "\"port\":6443,\"protocol\":\"TCP\"}]}],\"kind\":\"Endpoints\",\"apiVersion\":\"v1\"}"
19
+
20
+ stub_request(:post, 'http://localhost:8080/api/v1/namespaces/default/endpoints')
21
+ .with(body: req_body)
22
+ .to_return(body: open_test_file('created_endpoint.json'), status: 201)
23
+
24
+ created_ep = client.create_endpoint testing_ep
25
+ assert_equal('Endpoints', created_ep.kind)
26
+ end
27
+ end
data/test/test_service.rb CHANGED
@@ -23,9 +23,9 @@ class TestService < MiniTest::Test
23
23
  assert_equal our_service.metadata.labels.name,
24
24
  hash[:metadata][:labels][:name]
25
25
 
26
- stub_request(:post, %r{namespaces/staging/services})
27
- .to_return(body: open_test_file('created_service.json'),
28
- status: 201)
26
+ expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
27
+ stub_request(:post, expected_url)
28
+ .to_return(body: open_test_file('created_service.json'), status: 201)
29
29
 
30
30
  client = Kubeclient::Client.new 'http://localhost:8080/api/'
31
31
  created = client.create_service our_service
@@ -33,6 +33,81 @@ class TestService < MiniTest::Test
33
33
  assert_instance_of(Kubeclient::Service, created)
34
34
  assert_equal(created.metadata.name, our_service.metadata.name)
35
35
  assert_equal(created.spec.ports.size, our_service.spec.ports.size)
36
+
37
+ # Check that original entity_config is not modified by kind/apiVersion patches:
38
+ assert_equal(our_service.kind, nil)
39
+
40
+ assert_requested(:post, expected_url, times: 1) do |req|
41
+ data = JSON.parse(req.body)
42
+ data['kind'] == 'Service' &&
43
+ data['apiVersion'] == 'v1' &&
44
+ data['metadata']['name'] == 'guestbook' &&
45
+ data['metadata']['namespace'] == 'staging'
46
+ end
47
+ end
48
+
49
+ def test_construct_service_from_symbol_keys
50
+ service = Kubeclient::Service.new
51
+ service.metadata = {
52
+ labels: { tier: 'frontend' },
53
+ name: 'test-service',
54
+ namespace: 'staging'
55
+ }
56
+ service.spec = {
57
+ ports: [{
58
+ port: 3000,
59
+ targetPort: 'http-server',
60
+ protocol: 'TCP'
61
+ }]
62
+ }
63
+
64
+ expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
65
+ stub_request(:post, expected_url)
66
+ .to_return(body: open_test_file('created_service.json'), status: 201)
67
+
68
+ client = Kubeclient::Client.new 'http://localhost:8080/api/'
69
+ client.create_service service
70
+
71
+ assert_requested(:post, expected_url, times: 1) do |req|
72
+ data = JSON.parse(req.body)
73
+ data['kind'] == 'Service' &&
74
+ data['apiVersion'] == 'v1' &&
75
+ data['metadata']['name'] == 'test-service' &&
76
+ data['metadata']['labels']['tier'] == 'frontend' &&
77
+ data['metadata']['namespace'] == 'staging'
78
+ end
79
+ end
80
+
81
+ def test_construct_service_from_string_keys
82
+ service = Kubeclient::Service.new
83
+ service.metadata = {
84
+ 'labels' => { 'tier' => 'frontend' },
85
+ 'name' => 'test-service',
86
+ 'namespace' => 'staging'
87
+ }
88
+ service.spec = {
89
+ 'ports' => [{
90
+ 'port' => 3000,
91
+ 'targetPort' => 'http-server',
92
+ 'protocol' => 'TCP'
93
+ }]
94
+ }
95
+
96
+ expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
97
+ stub_request(:post, %r{namespaces/staging/services})
98
+ .to_return(body: open_test_file('created_service.json'), status: 201)
99
+
100
+ client = Kubeclient::Client.new 'http://localhost:8080/api/'
101
+ client.create_service service
102
+
103
+ assert_requested(:post, expected_url, times: 1) do |req|
104
+ data = JSON.parse(req.body)
105
+ data['kind'] == 'Service' &&
106
+ data['apiVersion'] == 'v1' &&
107
+ data['metadata']['name'] == 'test-service' &&
108
+ data['metadata']['labels']['tier'] == 'frontend' &&
109
+ data['metadata']['namespace'] == 'staging'
110
+ end
36
111
  end
37
112
 
38
113
  def test_conversion_from_json_v1
@@ -111,26 +186,47 @@ class TestService < MiniTest::Test
111
186
  end
112
187
 
113
188
  def test_update_service
114
- entity = 'service'
115
- object = Kubeclient::Service.new
189
+ service = Kubeclient::Service.new
190
+ name = 'my_service'
191
+
192
+ service.metadata = {}
193
+ service.metadata.name = name
194
+ service.metadata.namespace = 'development'
195
+
196
+ expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
197
+ stub_request(:put, expected_url)
198
+ .to_return(body: open_test_file('service_update.json'), status: 201)
199
+
200
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
201
+ client.update_service service
202
+
203
+ assert_requested(:put, expected_url, times: 1) do |req|
204
+ data = JSON.parse(req.body)
205
+ data['metadata']['name'] == name &&
206
+ data['metadata']['namespace'] == 'development'
207
+ end
208
+ end
209
+
210
+ def test_update_service_with_string_keys
211
+ service = Kubeclient::Service.new
116
212
  name = 'my_service'
117
- object.metadata = {
118
- 'name' => name
213
+
214
+ service.metadata = {
215
+ 'name' => name,
216
+ 'namespace' => 'development'
119
217
  }
120
218
 
121
- stub_request(:put, %r{/services/#{name}})\
122
- .to_return(
123
- body: open_test_file('service_update.json'),
124
- status: 200
125
- )
219
+ expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
220
+ stub_request(:put, expected_url)
221
+ .to_return(body: open_test_file('service_update.json'), status: 201)
126
222
 
127
223
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
128
- client.update_entity entity, object
224
+ client.update_service service
129
225
 
130
- assert_requested(
131
- :put,
132
- "http://localhost:8080/api/v1/services/#{name}",
133
- times: 1
134
- )
226
+ assert_requested(:put, expected_url, times: 1) do |req|
227
+ data = JSON.parse(req.body)
228
+ data['metadata']['name'] == name &&
229
+ data['metadata']['namespace'] == 'development'
230
+ end
135
231
  end
136
232
  end
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: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alissa Bonas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-17 00:00:00.000000000 Z
11
+ date: 2016-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -189,6 +189,7 @@ files:
189
189
  - test/cassettes/kubernetes_guestbook.yml
190
190
  - test/json/component_status.json
191
191
  - test/json/component_status_list.json
192
+ - test/json/created_endpoint.json
192
193
  - test/json/created_namespace.json
193
194
  - test/json/created_secret.json
194
195
  - test/json/created_service.json
@@ -224,6 +225,7 @@ files:
224
225
  - test/json/versions_list.json
225
226
  - test/json/watch_stream.json
226
227
  - test/test_component_status.rb
228
+ - test/test_endpoint.rb
227
229
  - test/test_guestbook_go.rb
228
230
  - test/test_helper.rb
229
231
  - test/test_kubeclient.rb
@@ -270,6 +272,7 @@ test_files:
270
272
  - test/cassettes/kubernetes_guestbook.yml
271
273
  - test/json/component_status.json
272
274
  - test/json/component_status_list.json
275
+ - test/json/created_endpoint.json
273
276
  - test/json/created_namespace.json
274
277
  - test/json/created_secret.json
275
278
  - test/json/created_service.json
@@ -305,6 +308,7 @@ test_files:
305
308
  - test/json/versions_list.json
306
309
  - test/json/watch_stream.json
307
310
  - test/test_component_status.rb
311
+ - test/test_endpoint.rb
308
312
  - test/test_guestbook_go.rb
309
313
  - test/test_helper.rb
310
314
  - test/test_kubeclient.rb