kubeclient 0.3.0 → 4.9.2

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.

Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/actions.yml +35 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +29 -0
  5. data/CHANGELOG.md +208 -0
  6. data/Gemfile +3 -0
  7. data/README.md +706 -57
  8. data/RELEASING.md +69 -0
  9. data/Rakefile +3 -5
  10. data/kubeclient.gemspec +19 -11
  11. data/lib/kubeclient/aws_eks_credentials.rb +46 -0
  12. data/lib/kubeclient/common.rb +597 -161
  13. data/lib/kubeclient/config.rb +195 -0
  14. data/lib/kubeclient/entity_list.rb +7 -2
  15. data/lib/kubeclient/exec_credentials.rb +89 -0
  16. data/lib/kubeclient/gcp_auth_provider.rb +19 -0
  17. data/lib/kubeclient/gcp_command_credentials.rb +31 -0
  18. data/lib/kubeclient/google_application_default_credentials.rb +31 -0
  19. data/lib/kubeclient/http_error.rb +25 -0
  20. data/lib/kubeclient/missing_kind_compatibility.rb +68 -0
  21. data/lib/kubeclient/oidc_auth_provider.rb +52 -0
  22. data/lib/kubeclient/resource.rb +11 -0
  23. data/lib/kubeclient/resource_not_found_error.rb +4 -0
  24. data/lib/kubeclient/version.rb +1 -1
  25. data/lib/kubeclient/watch_stream.rb +71 -28
  26. data/lib/kubeclient.rb +25 -82
  27. metadata +140 -114
  28. data/.travis.yml +0 -6
  29. data/lib/kubeclient/kube_exception.rb +0 -13
  30. data/lib/kubeclient/watch_notice.rb +0 -7
  31. data/test/json/created_namespace_b3.json +0 -20
  32. data/test/json/created_secret.json +0 -16
  33. data/test/json/created_service_b3.json +0 -31
  34. data/test/json/empty_pod_list_b3.json +0 -9
  35. data/test/json/endpoint_list_b3.json +0 -48
  36. data/test/json/entity_list_b3.json +0 -56
  37. data/test/json/event_list_b3.json +0 -35
  38. data/test/json/namespace_b3.json +0 -13
  39. data/test/json/namespace_exception_b3.json +0 -8
  40. data/test/json/namespace_list_b3.json +0 -32
  41. data/test/json/node_b3.json +0 -29
  42. data/test/json/node_list_b3.json +0 -37
  43. data/test/json/pod_b3.json +0 -92
  44. data/test/json/pod_list_b3.json +0 -75
  45. data/test/json/replication_controller_b3.json +0 -57
  46. data/test/json/replication_controller_list_b3.json +0 -64
  47. data/test/json/secret_list_b3.json +0 -44
  48. data/test/json/service_b3.json +0 -33
  49. data/test/json/service_illegal_json_404.json +0 -1
  50. data/test/json/service_list_b3.json +0 -97
  51. data/test/json/service_update_b3.json +0 -22
  52. data/test/json/versions_list.json +0 -6
  53. data/test/json/watch_stream_b3.json +0 -3
  54. data/test/test_helper.rb +0 -4
  55. data/test/test_kubeclient.rb +0 -407
  56. data/test/test_namespace.rb +0 -53
  57. data/test/test_node.rb +0 -25
  58. data/test/test_pod.rb +0 -21
  59. data/test/test_replication_controller.rb +0 -24
  60. data/test/test_secret.rb +0 -58
  61. data/test/test_service.rb +0 -136
  62. data/test/test_watch.rb +0 -37
  63. data/test/valid_token_file +0 -1
@@ -1,33 +0,0 @@
1
- {
2
- "kind": "Service",
3
- "apiVersion": "v1beta3",
4
- "metadata": {
5
- "name": "redis-slave",
6
- "namespace": "development",
7
- "selfLink": "/api/v1beta3/namespaces/development/services/redis-slave",
8
- "uid": "bdb80a8f-db93-11e4-b293-f8b156af4ae1",
9
- "resourceVersion": "2815",
10
- "creationTimestamp": "2015-04-05T13:00:31Z",
11
- "labels": {
12
- "name": "redis",
13
- "role": "slave"
14
- }
15
- },
16
- "spec": {
17
- "ports": [
18
- {
19
- "name": "",
20
- "protocol": "TCP",
21
- "port": 6379,
22
- "targetPort": "redis-server"
23
- }
24
- ],
25
- "selector": {
26
- "name": "redis",
27
- "role": "slave"
28
- },
29
- "portalIP": "10.0.0.140",
30
- "sessionAffinity": "None"
31
- },
32
- "status": {}
33
- }
@@ -1 +0,0 @@
1
- 404: Page Not Found
@@ -1,97 +0,0 @@
1
- {
2
- "kind": "ServiceList",
3
- "apiVersion": "v1beta3",
4
- "metadata": {
5
- "selfLink": "/api/v1beta3/services",
6
- "resourceVersion": "36727"
7
- },
8
- "items": [
9
- {
10
- "metadata": {
11
- "name": "kubernetes",
12
- "namespace": "default",
13
- "selfLink": "/api/v1beta3/namespaces/default/services/kubernetes",
14
- "uid": "b6606490-db86-11e4-b293-f8b156af4ae1",
15
- "resourceVersion": "6",
16
- "creationTimestamp": "2015-04-05T11:27:15Z",
17
- "labels": {
18
- "component": "apiserver",
19
- "provider": "kubernetes"
20
- }
21
- },
22
- "spec": {
23
- "ports": [
24
- {
25
- "name": "",
26
- "protocol": "TCP",
27
- "port": 443,
28
- "targetPort": 443
29
- }
30
- ],
31
- "selector": null,
32
- "portalIP": "10.0.0.2",
33
- "sessionAffinity": "None"
34
- },
35
- "status": {}
36
- },
37
- {
38
- "metadata": {
39
- "name": "kubernetes-ro",
40
- "namespace": "default",
41
- "selfLink": "/api/v1beta3/namespaces/default/services/kubernetes-ro",
42
- "uid": "b6606694-db86-11e4-b293-f8b156af4ae1",
43
- "resourceVersion": "5",
44
- "creationTimestamp": "2015-04-05T11:27:15Z",
45
- "labels": {
46
- "component": "apiserver",
47
- "provider": "kubernetes"
48
- }
49
- },
50
- "spec": {
51
- "ports": [
52
- {
53
- "name": "",
54
- "protocol": "TCP",
55
- "port": 80,
56
- "targetPort": 80
57
- }
58
- ],
59
- "selector": null,
60
- "portalIP": "10.0.0.1",
61
- "sessionAffinity": "None"
62
- },
63
- "status": {}
64
- },
65
- {
66
- "metadata": {
67
- "name": "redis-slave",
68
- "namespace": "development",
69
- "selfLink": "/api/v1beta3/namespaces/development/services/redis-slave",
70
- "uid": "bdb80a8f-db93-11e4-b293-f8b156af4ae1",
71
- "resourceVersion": "2815",
72
- "creationTimestamp": "2015-04-05T13:00:31Z",
73
- "labels": {
74
- "name": "redis",
75
- "role": "slave"
76
- }
77
- },
78
- "spec": {
79
- "ports": [
80
- {
81
- "name": "",
82
- "protocol": "TCP",
83
- "port": 6379,
84
- "targetPort": "redis-server"
85
- }
86
- ],
87
- "selector": {
88
- "name": "redis",
89
- "role": "slave"
90
- },
91
- "portalIP": "10.0.0.140",
92
- "sessionAffinity": "None"
93
- },
94
- "status": {}
95
- }
96
- ]
97
- }
@@ -1,22 +0,0 @@
1
- {
2
- "status" : {},
3
- "kind" : "Service",
4
- "apiVersion" : "v1beta3",
5
- "spec" : {
6
- "ports" : [
7
- {
8
- "targetPort" : 80,
9
- "nodePort" : 0,
10
- "port" : 80,
11
- "protocol" : "TCP"
12
- }
13
- ],
14
- "portalIP" : "1.2.3.4"
15
- },
16
- "metadata" : {
17
- "name" : "my_service",
18
- "creationTimestamp" : null,
19
- "namespace" : "default",
20
- "resourceVersion" : "2"
21
- }
22
- }
@@ -1,6 +0,0 @@
1
- {
2
- "versions": [
3
- "v1beta3",
4
- "v1"
5
- ]
6
- }
@@ -1,3 +0,0 @@
1
- {"type":"ADDED","object":{"kind":"Pod","apiVersion":"v1beta3","metadata":{"name":"php","namespace":"default","selfLink":"/api/v1beta3/pods/php","uid":"e75f2c07-b047-11e4-89e4-525400c903c1","resourceVersion":"1389","creationTimestamp":"2015-02-09T05:39:19-05:00","labels":{"name":"foo"}},"spec":{"volumes":null,"containers":[{"name":"nginx","image":"dockerfile/nginx","ports":[{"hostPort":9090,"containerPort":80,"protocol":"TCP"}],"resources":{},"livenessProbe":{"httpGet":{"path":"/index.html","port":"9090"},"initialDelaySeconds":30},"terminationMessagePath":"/dev/termination-log","imagePullPolicy":"IfNotPresent","capabilities":{}}],"restartPolicy":{"always":{}},"dnsPolicy":"ClusterFirst"},"status":{"phase":"Pending"}}}
2
- {"type":"MODIFIED","object":{"kind":"Pod","apiVersion":"v1beta3","metadata":{"name":"php","namespace":"default","selfLink":"/api/v1beta3/pods/php","uid":"e75f2c07-b047-11e4-89e4-525400c903c1","resourceVersion":"1390","creationTimestamp":"2015-02-09T05:39:19-05:00","labels":{"name":"foo"}},"spec":{"volumes":null,"containers":[{"name":"nginx","image":"dockerfile/nginx","ports":[{"hostPort":9090,"containerPort":80,"protocol":"TCP"}],"resources":{},"livenessProbe":{"httpGet":{"path":"/index.html","port":"9090"},"initialDelaySeconds":30},"terminationMessagePath":"/dev/termination-log","imagePullPolicy":"IfNotPresent","capabilities":{}}],"restartPolicy":{"always":{}},"dnsPolicy":"ClusterFirst"},"status":{"phase":"Pending","host":"127.0.0.1"}}}
3
- {"type":"DELETED","object":{"kind":"Pod","apiVersion":"v1beta3","metadata":{"name":"php","namespace":"default","selfLink":"/api/v1beta3/pods/php","uid":"e75f2c07-b047-11e4-89e4-525400c903c1","resourceVersion":"1398","creationTimestamp":"2015-02-09T05:39:19-05:00","labels":{"name":"foo"}},"spec":{"volumes":null,"containers":[{"name":"nginx","image":"dockerfile/nginx","ports":[{"hostPort":9090,"containerPort":80,"protocol":"TCP"}],"resources":{},"livenessProbe":{"httpGet":{"path":"/index.html","port":"9090"},"initialDelaySeconds":30},"terminationMessagePath":"/dev/termination-log","imagePullPolicy":"IfNotPresent","capabilities":{}}],"restartPolicy":{"always":{}},"dnsPolicy":"ClusterFirst"},"status":{"phase":"Pending","host":"127.0.0.1"}}}
data/test/test_helper.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'webmock/minitest'
3
- require 'json'
4
- require 'kubeclient'
@@ -1,407 +0,0 @@
1
- require 'test_helper'
2
-
3
- def open_test_json_file(name)
4
- File.new(File.join(File.dirname(__FILE__), 'json', name))
5
- end
6
-
7
- # Kubernetes client entity tests
8
- class KubeClientTest < MiniTest::Test
9
- def test_json
10
- our_object = Kubeclient::Service.new
11
- our_object.foo = 'bar'
12
- our_object.nested = {}
13
- our_object.nested.again = {}
14
- our_object.nested.again.again = {}
15
- our_object.nested.again.again.name = 'aaron'
16
-
17
- expected = { 'foo' => 'bar', 'nested' => { 'again' => { 'again' =>
18
- { 'name' => 'aaron' } } } }
19
-
20
- assert_equal(expected, JSON.parse(JSON.dump(our_object.to_h)))
21
- end
22
-
23
- def test_pass_uri
24
- # URI::Generic#hostname= was added in ruby 1.9.3 and will automatically
25
- # wrap an ipv6 address in []
26
- uri = URI::HTTP.build(port: 8080)
27
- uri.hostname = 'localhost'
28
- client = Kubeclient::Client.new uri
29
- rest_client = client.rest_client
30
- assert_equal 'http://localhost:8080/api/v1beta3', rest_client.url.to_s
31
- end
32
-
33
- def test_no_path_in_uri
34
- client = Kubeclient::Client.new 'http://localhost:8080', 'v1beta3'
35
- rest_client = client.rest_client
36
- assert_equal 'http://localhost:8080/api/v1beta3', rest_client.url.to_s
37
- end
38
-
39
- def test_no_version_passed
40
- client = Kubeclient::Client.new 'http://localhost:8080'
41
- rest_client = client.rest_client
42
- assert_equal 'http://localhost:8080/api/v1beta3', rest_client.url.to_s
43
- end
44
-
45
- def test_exception
46
- stub_request(:post, %r{/services})
47
- .to_return(body: open_test_json_file('namespace_exception_b3.json'),
48
- status: 409)
49
-
50
- service = Kubeclient::Service.new
51
- service.metadata = {}
52
- service.metadata.name = 'redisslave'
53
- service.metadata.namespace = 'default'
54
- # service.port = 80
55
- # service.container_port = 6379
56
- # service.protocol = 'TCP'
57
-
58
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
59
-
60
- exception = assert_raises(KubeException) do
61
- service = client.create_service service
62
- end
63
-
64
- assert_instance_of(KubeException, exception)
65
- assert_equal("converting to : type names don't match (Pod, Namespace)",
66
- exception.message)
67
- assert_equal(409, exception.error_code)
68
- end
69
-
70
- def test_api
71
- stub_request(:get, 'http://localhost:8080/api')
72
- .to_return(status: 200, body: open_test_json_file('versions_list.json'))
73
-
74
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
75
- response = client.api
76
- assert_includes(response, 'versions')
77
- end
78
-
79
- def test_api_ssl_failure
80
- error_message = 'certificate verify failed'
81
-
82
- stub_request(:get, 'http://localhost:8080/api')
83
- .to_raise(OpenSSL::SSL::SSLError.new(error_message))
84
-
85
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
86
-
87
- exception = assert_raises(KubeException) { client.api }
88
- assert_equal(error_message, exception.message)
89
- end
90
-
91
- def test_api_valid
92
- stub_request(:get, 'http://localhost:8080/api')
93
- .to_return(status: 200, body: open_test_json_file('versions_list.json'))
94
-
95
- args = ['http://localhost:8080/api/']
96
-
97
- [nil, 'v1beta3', 'v1'].each do |version|
98
- client = Kubeclient::Client.new(*(version ? args + [version] : args))
99
- assert client.api_valid?
100
- end
101
- end
102
-
103
- def test_api_valid_with_invalid_version
104
- stub_request(:get, 'http://localhost:8080/api')
105
- .to_return(status: 200, body: open_test_json_file('versions_list.json'))
106
-
107
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'foobar1'
108
- refute client.api_valid?
109
- end
110
-
111
- def test_api_valid_with_unreported_versions
112
- stub_request(:get, 'http://localhost:8080/api')
113
- .to_return(status: 200, body: '{}')
114
-
115
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
116
- refute client.api_valid?
117
- end
118
-
119
- def test_api_valid_with_invalid_json
120
- stub_request(:get, 'http://localhost:8080/api')
121
- .to_return(status: 200, body: '[]')
122
-
123
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
124
- refute client.api_valid?
125
- end
126
-
127
- def test_api_valid_with_bad_endpoint
128
- stub_request(:get, 'http://localhost:8080/api')
129
- .to_return(status: [404, 'Resource Not Found'])
130
-
131
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
132
- assert_raises(KubeException) { client.api_valid? }
133
- end
134
-
135
- def test_api_valid_with_non_json
136
- stub_request(:get, 'http://localhost:8080/api')
137
- .to_return(status: 200, body: '<html></html>')
138
-
139
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
140
- assert_raises(JSON::ParserError) { client.api_valid? }
141
- end
142
-
143
- def test_nonjson_exception
144
- stub_request(:get, %r{/servic})
145
- .to_return(body: open_test_json_file('service_illegal_json_404.json'),
146
- status: 404)
147
-
148
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
149
-
150
- exception = assert_raises(KubeException) do
151
- client.get_services
152
- end
153
-
154
- assert_instance_of(KubeException, exception)
155
- assert_equal('404 Resource Not Found', exception.message)
156
- assert_equal(404, exception.error_code)
157
- end
158
-
159
- def test_entity_list
160
- stub_request(:get, %r{/services})
161
- .to_return(body: open_test_json_file('entity_list_b3.json'),
162
- status: 200)
163
-
164
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
165
- services = client.get_services
166
-
167
- refute_empty(services)
168
- assert_instance_of(Kubeclient::Common::EntityList, services)
169
- assert_equal('Service', services.kind)
170
- assert_equal(2, services.size)
171
- assert_instance_of(Kubeclient::Service, services[0])
172
- assert_instance_of(Kubeclient::Service, services[1])
173
-
174
- assert_requested(:get,
175
- 'http://localhost:8080/api/v1beta3/services',
176
- times: 1)
177
- end
178
-
179
- def test_empty_list
180
- stub_request(:get, %r{/pods})
181
- .to_return(body: open_test_json_file('empty_pod_list_b3.json'),
182
- status: 200)
183
-
184
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
185
- pods = client.get_pods
186
- assert_instance_of(Kubeclient::Common::EntityList, pods)
187
- assert_equal(0, pods.size)
188
- end
189
-
190
- def test_get_all
191
- stub_request(:get, %r{/services})
192
- .to_return(body: open_test_json_file('service_list_b3.json'),
193
- status: 200)
194
-
195
- stub_request(:get, %r{/pods})
196
- .to_return(body: open_test_json_file('pod_list_b3.json'),
197
- status: 200)
198
-
199
- stub_request(:get, %r{/nodes})
200
- .to_return(body: open_test_json_file('node_list_b3.json'),
201
- status: 200)
202
-
203
- stub_request(:get, %r{/replicationcontrollers})
204
- .to_return(body: open_test_json_file('replication_controller_list_' \
205
- 'b3.json'), status: 200)
206
-
207
- stub_request(:get, %r{/events})
208
- .to_return(body: open_test_json_file('event_list_b3.json'), status: 200)
209
-
210
- stub_request(:get, %r{/endpoints})
211
- .to_return(body: open_test_json_file('endpoint_list_b3.json'),
212
- status: 200)
213
-
214
- stub_request(:get, %r{/namespaces})
215
- .to_return(body: open_test_json_file('namespace_list_b3.json'),
216
- status: 200)
217
-
218
- stub_request(:get, %r{/secrets})
219
- .to_return(body: open_test_json_file('secret_list_b3.json'),
220
- status: 200)
221
-
222
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
223
- result = client.all_entities
224
- assert_equal(8, result.keys.size)
225
- assert_instance_of(Kubeclient::Common::EntityList, result['node'])
226
- assert_instance_of(Kubeclient::Common::EntityList, result['service'])
227
- assert_instance_of(Kubeclient::Common::EntityList,
228
- result['replication_controller'])
229
- assert_instance_of(Kubeclient::Common::EntityList, result['pod'])
230
- assert_instance_of(Kubeclient::Common::EntityList, result['event'])
231
- assert_instance_of(Kubeclient::Common::EntityList, result['namespace'])
232
- assert_instance_of(Kubeclient::Common::EntityList, result['secret'])
233
- assert_instance_of(Kubeclient::Service, result['service'][0])
234
- assert_instance_of(Kubeclient::Node, result['node'][0])
235
- assert_instance_of(Kubeclient::Event, result['event'][0])
236
- assert_instance_of(Kubeclient::Endpoint, result['endpoint'][0])
237
- assert_instance_of(Kubeclient::Namespace, result['namespace'][0])
238
- assert_instance_of(Kubeclient::Secret, result['secret'][0])
239
- end
240
-
241
- def test_api_bearer_token_with_params_success
242
- stub_request(:get, 'http://localhost:8080/api/v1beta3/pods?labelSelector=name=redis-master')
243
- .with(headers: { Authorization: 'Bearer valid_token' })
244
- .to_return(body: open_test_json_file('pod_list_b3.json'),
245
- status: 200)
246
-
247
- client = Kubeclient::Client.new 'http://localhost:8080/api/',
248
- auth_options: {
249
- bearer_token: 'valid_token'
250
- }
251
-
252
- pods = client.get_pods(label_selector: 'name=redis-master')
253
-
254
- assert_equal('Pod', pods.kind)
255
- assert_equal(1, pods.size)
256
- end
257
-
258
- def test_api_bearer_token_success
259
- stub_request(:get, 'http://localhost:8080/api/v1beta3/pods')
260
- .with(headers: { Authorization: 'Bearer valid_token' })
261
- .to_return(body: open_test_json_file('pod_list_b3.json'),
262
- status: 200)
263
-
264
- client = Kubeclient::Client.new 'http://localhost:8080/api/',
265
- auth_options: {
266
- bearer_token: 'valid_token'
267
- }
268
-
269
- pods = client.get_pods
270
-
271
- assert_equal('Pod', pods.kind)
272
- assert_equal(1, pods.size)
273
- end
274
-
275
- def test_api_bearer_token_failure
276
- error_message = '"/api/v1beta3/pods" is forbidden because ' \
277
- 'system:anonymous cannot list on pods in'
278
-
279
- stub_request(:get, 'http://localhost:8080/api/v1beta3/pods')
280
- .with(headers: { Authorization: 'Bearer invalid_token' })
281
- .to_raise(KubeException.new(403, error_message))
282
-
283
- client = Kubeclient::Client.new 'http://localhost:8080/api/',
284
- auth_options: {
285
- bearer_token: 'invalid_token'
286
- }
287
-
288
- exception = assert_raises(KubeException) { client.get_pods }
289
- assert_equal(403, exception.error_code)
290
- assert_equal(error_message, exception.message)
291
- end
292
-
293
- def test_api_basic_auth_success
294
- stub_request(:get, 'http://username:password@localhost:8080/api/v1beta3/pods')
295
- .to_return(body: open_test_json_file('pod_list_b3.json'),
296
- status: 200)
297
-
298
- client = Kubeclient::Client.new 'http://localhost:8080/api/',
299
- auth_options: {
300
- user: 'username',
301
- password: 'password'
302
- }
303
-
304
- pods = client.get_pods
305
-
306
- assert_equal('Pod', pods.kind)
307
- assert_equal(1, pods.size)
308
- assert_requested(:get,
309
- 'http://username:password@localhost:8080/api/v1beta3/pods',
310
- times: 1)
311
- end
312
-
313
- def test_api_basic_auth_failure
314
- error_message = 'HTTP status code 401, 401 Unauthorized'
315
-
316
- stub_request(:get, 'http://username:password@localhost:8080/api/v1beta3/pods')
317
- .to_raise(KubeException.new(401, error_message))
318
-
319
- client = Kubeclient::Client.new 'http://localhost:8080/api/',
320
- auth_options: {
321
- user: 'username',
322
- password: 'password'
323
- }
324
-
325
- exception = assert_raises(KubeException) { client.get_pods }
326
- assert_equal(401, exception.error_code)
327
- assert_equal(error_message, exception.message)
328
- assert_requested(:get,
329
- 'http://username:password@localhost:8080/api/v1beta3/pods',
330
- times: 1)
331
- end
332
-
333
- def test_init_user_no_password
334
- expected_msg = 'Basic auth requires both user & password'
335
- exception = assert_raises(ArgumentError) do
336
- Kubeclient::Client.new 'http://localhost:8080',
337
- auth_options: {
338
- user: 'username'
339
- }
340
- end
341
- assert_equal expected_msg, exception.message
342
- end
343
-
344
- def test_init_user_and_bearer_token
345
- expected_msg = 'Invalid auth options: specify only one of user/password,' \
346
- ' bearer_token or bearer_token_file'
347
- exception = assert_raises(ArgumentError) do
348
- Kubeclient::Client.new 'http://localhost:8080',
349
- auth_options: {
350
- user: 'username',
351
- bearer_token: 'token'
352
- }
353
- end
354
- assert_equal expected_msg, exception.message
355
- end
356
-
357
- def test_bearer_token_and_bearer_token_file
358
- expected_msg = 'Invalid auth options: specify only one of user/password,' \
359
- ' bearer_token or bearer_token_file'
360
- exception = assert_raises(ArgumentError) do
361
- Kubeclient::Client.new 'http://localhost:8080',
362
- auth_options: {
363
- bearer_token: 'token',
364
- bearer_token_file: 'token-file'
365
- }
366
- end
367
- assert_equal expected_msg, exception.message
368
- end
369
-
370
- def test_bearer_token_file_not_exist
371
- expected_msg = 'Token file token-file does not exist'
372
- exception = assert_raises(ArgumentError) do
373
- Kubeclient::Client.new 'http://localhost:8080',
374
- auth_options: {
375
- bearer_token_file: 'token-file'
376
- }
377
- end
378
- assert_equal expected_msg, exception.message
379
- end
380
-
381
- def test_api_bearer_token_file_success
382
- stub_request(:get, 'http://localhost:8080/api/v1beta3/pods')
383
- .with(headers: { Authorization: 'Bearer valid_token' })
384
- .to_return(body: open_test_json_file('pod_list_b3.json'),
385
- status: 200)
386
-
387
- file = File.join(File.dirname(__FILE__), 'valid_token_file')
388
- client = Kubeclient::Client.new 'http://localhost:8080/api/',
389
- auth_options: {
390
- bearer_token_file: file
391
- }
392
-
393
- pods = client.get_pods
394
-
395
- assert_equal('Pod', pods.kind)
396
- assert_equal(1, pods.size)
397
- end
398
-
399
- private
400
-
401
- # dup method creates a shallow copy which is not good in this case
402
- # since rename_keys changes the input hash
403
- # hence need to create a deep_copy
404
- def deep_copy(hash)
405
- Marshal.load(Marshal.dump(hash))
406
- end
407
- end
@@ -1,53 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Namespace entity tests
4
- class TestNamespace < MiniTest::Test
5
- def test_get_namespace_v1beta3
6
- stub_request(:get, %r{/namespaces})
7
- .to_return(body: open_test_json_file('namespace_b3.json'),
8
- status: 200)
9
-
10
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
11
- namespace = client.get_namespace 'staging'
12
-
13
- assert_instance_of(Kubeclient::Namespace, namespace)
14
- assert_equal('e388bc10-c021-11e4-a514-3c970e4a436a', namespace.metadata.uid)
15
- assert_equal('staging', namespace.metadata.name)
16
- assert_equal('1168', namespace.metadata.resourceVersion)
17
- assert_equal('v1beta3', namespace.apiVersion)
18
-
19
- assert_requested(:get,
20
- 'http://localhost:8080/api/v1beta3/namespaces/staging',
21
- times: 1)
22
- end
23
-
24
- def test_delete_namespace_v1beta3
25
- our_namespace = Kubeclient::Namespace.new
26
- our_namespace.name = 'staging'
27
-
28
- stub_request(:delete, %r{/namespaces})
29
- .to_return(status: 200)
30
-
31
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
32
- client.delete_namespace our_namespace.name
33
-
34
- assert_requested(:delete,
35
- 'http://localhost:8080/api/v1beta3/namespaces/staging',
36
- times: 1)
37
- end
38
-
39
- def test_create_namespace
40
- stub_request(:post, %r{/namespaces})
41
- .to_return(body: open_test_json_file('created_namespace_b3.json'),
42
- status: 201)
43
-
44
- namespace = Kubeclient::Namespace.new
45
- namespace.metadata = {}
46
- namespace.metadata.name = 'development'
47
-
48
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
49
- created_namespace = client.create_namespace namespace
50
- assert_instance_of(Kubeclient::Namespace, created_namespace)
51
- assert_equal(namespace.metadata.name, created_namespace.metadata.name)
52
- end
53
- end
data/test/test_node.rb DELETED
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Node entity tests
4
- class TestNode < MiniTest::Test
5
- def test_get_from_json_v3
6
- stub_request(:get, %r{/nodes})
7
- .to_return(body: open_test_json_file('node_b3.json'),
8
- status: 200)
9
-
10
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
11
- node = client.get_node('127.0.0.1')
12
-
13
- assert_instance_of(Kubeclient::Node, node)
14
-
15
- assert_equal('041143c5-ce39-11e4-ac24-3c970e4a436a', node.metadata.uid)
16
- assert_equal('127.0.0.1', node.metadata.name)
17
- assert_equal('1724', node.metadata.resourceVersion)
18
- assert_equal('v1beta3', node.apiVersion)
19
- assert_equal('2015-03-19T15:08:20+02:00', node.metadata.creationTimestamp)
20
-
21
- assert_requested(:get,
22
- 'http://localhost:8080/api/v1beta3/nodes/127.0.0.1',
23
- times: 1)
24
- end
25
- end