ruboty-k8s 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruboty/k8s/version.rb +1 -1
  3. data/ruboty-k8s.gemspec +1 -9
  4. metadata +4 -183
  5. data/lib/kubeclient/.gitignore +0 -15
  6. data/lib/kubeclient/.rubocop.yml +0 -16
  7. data/lib/kubeclient/.travis.yml +0 -12
  8. data/lib/kubeclient/Gemfile +0 -4
  9. data/lib/kubeclient/LICENSE.txt +0 -22
  10. data/lib/kubeclient/README.md +0 -428
  11. data/lib/kubeclient/Rakefile +0 -12
  12. data/lib/kubeclient/kubeclient.gemspec +0 -31
  13. data/lib/kubeclient/lib/kubeclient.rb +0 -32
  14. data/lib/kubeclient/lib/kubeclient/common.rb +0 -512
  15. data/lib/kubeclient/lib/kubeclient/config.rb +0 -126
  16. data/lib/kubeclient/lib/kubeclient/entity_list.rb +0 -16
  17. data/lib/kubeclient/lib/kubeclient/kube_exception.rb +0 -14
  18. data/lib/kubeclient/lib/kubeclient/missing_kind_compatibility.rb +0 -68
  19. data/lib/kubeclient/lib/kubeclient/version.rb +0 -4
  20. data/lib/kubeclient/lib/kubeclient/watch_notice.rb +0 -7
  21. data/lib/kubeclient/lib/kubeclient/watch_stream.rb +0 -80
  22. data/lib/kubeclient/test/cassettes/kubernetes_guestbook.yml +0 -879
  23. data/lib/kubeclient/test/config/allinone.kubeconfig +0 -20
  24. data/lib/kubeclient/test/config/external-ca.pem +0 -18
  25. data/lib/kubeclient/test/config/external-cert.pem +0 -19
  26. data/lib/kubeclient/test/config/external-key.rsa +0 -27
  27. data/lib/kubeclient/test/config/external.kubeconfig +0 -20
  28. data/lib/kubeclient/test/config/nouser.kubeconfig +0 -16
  29. data/lib/kubeclient/test/config/userauth.kubeconfig +0 -28
  30. data/lib/kubeclient/test/json/bindings_list.json +0 -10
  31. data/lib/kubeclient/test/json/component_status.json +0 -17
  32. data/lib/kubeclient/test/json/component_status_list.json +0 -52
  33. data/lib/kubeclient/test/json/config_map_list.json +0 -9
  34. data/lib/kubeclient/test/json/core_api_resource_list.json +0 -181
  35. data/lib/kubeclient/test/json/core_api_resource_list_without_kind.json +0 -129
  36. data/lib/kubeclient/test/json/core_oapi_resource_list_without_kind.json +0 -197
  37. data/lib/kubeclient/test/json/created_endpoint.json +0 -28
  38. data/lib/kubeclient/test/json/created_namespace.json +0 -20
  39. data/lib/kubeclient/test/json/created_secret.json +0 -16
  40. data/lib/kubeclient/test/json/created_service.json +0 -31
  41. data/lib/kubeclient/test/json/empty_pod_list.json +0 -9
  42. data/lib/kubeclient/test/json/endpoint_list.json +0 -48
  43. data/lib/kubeclient/test/json/entity_list.json +0 -56
  44. data/lib/kubeclient/test/json/event_list.json +0 -35
  45. data/lib/kubeclient/test/json/limit_range.json +0 -23
  46. data/lib/kubeclient/test/json/limit_range_list.json +0 -31
  47. data/lib/kubeclient/test/json/namespace.json +0 -13
  48. data/lib/kubeclient/test/json/namespace_exception.json +0 -8
  49. data/lib/kubeclient/test/json/namespace_list.json +0 -32
  50. data/lib/kubeclient/test/json/node.json +0 -29
  51. data/lib/kubeclient/test/json/node_list.json +0 -37
  52. data/lib/kubeclient/test/json/persistent_volume.json +0 -37
  53. data/lib/kubeclient/test/json/persistent_volume_claim.json +0 -32
  54. data/lib/kubeclient/test/json/persistent_volume_claim_list.json +0 -40
  55. data/lib/kubeclient/test/json/persistent_volume_claims_nil_items.json +0 -8
  56. data/lib/kubeclient/test/json/persistent_volume_list.json +0 -45
  57. data/lib/kubeclient/test/json/pod.json +0 -92
  58. data/lib/kubeclient/test/json/pod_list.json +0 -79
  59. data/lib/kubeclient/test/json/pod_template_list.json +0 -9
  60. data/lib/kubeclient/test/json/processed_template.json +0 -27
  61. data/lib/kubeclient/test/json/replication_controller.json +0 -57
  62. data/lib/kubeclient/test/json/replication_controller_list.json +0 -66
  63. data/lib/kubeclient/test/json/resource_quota.json +0 -46
  64. data/lib/kubeclient/test/json/resource_quota_list.json +0 -54
  65. data/lib/kubeclient/test/json/secret_list.json +0 -44
  66. data/lib/kubeclient/test/json/service.json +0 -33
  67. data/lib/kubeclient/test/json/service_account.json +0 -25
  68. data/lib/kubeclient/test/json/service_account_list.json +0 -82
  69. data/lib/kubeclient/test/json/service_illegal_json_404.json +0 -1
  70. data/lib/kubeclient/test/json/service_list.json +0 -97
  71. data/lib/kubeclient/test/json/service_patch.json +0 -25
  72. data/lib/kubeclient/test/json/service_update.json +0 -22
  73. data/lib/kubeclient/test/json/versions_list.json +0 -6
  74. data/lib/kubeclient/test/json/watch_stream.json +0 -3
  75. data/lib/kubeclient/test/test_common.rb +0 -32
  76. data/lib/kubeclient/test/test_component_status.rb +0 -30
  77. data/lib/kubeclient/test/test_config.rb +0 -72
  78. data/lib/kubeclient/test/test_endpoint.rb +0 -35
  79. data/lib/kubeclient/test/test_guestbook_go.rb +0 -238
  80. data/lib/kubeclient/test/test_helper.rb +0 -10
  81. data/lib/kubeclient/test/test_kubeclient.rb +0 -611
  82. data/lib/kubeclient/test/test_limit_range.rb +0 -27
  83. data/lib/kubeclient/test/test_missing_methods.rb +0 -42
  84. data/lib/kubeclient/test/test_namespace.rb +0 -61
  85. data/lib/kubeclient/test/test_node.rb +0 -33
  86. data/lib/kubeclient/test/test_persistent_volume.rb +0 -30
  87. data/lib/kubeclient/test/test_persistent_volume_claim.rb +0 -30
  88. data/lib/kubeclient/test/test_pod.rb +0 -29
  89. data/lib/kubeclient/test/test_pod_log.rb +0 -50
  90. data/lib/kubeclient/test/test_process_template.rb +0 -44
  91. data/lib/kubeclient/test/test_replication_controller.rb +0 -27
  92. data/lib/kubeclient/test/test_resource_list_without_kind.rb +0 -78
  93. data/lib/kubeclient/test/test_resource_quota.rb +0 -25
  94. data/lib/kubeclient/test/test_secret.rb +0 -70
  95. data/lib/kubeclient/test/test_service.rb +0 -293
  96. data/lib/kubeclient/test/test_service_account.rb +0 -28
  97. data/lib/kubeclient/test/test_watch.rb +0 -119
  98. data/lib/kubeclient/test/txt/pod_log.txt +0 -6
  99. data/lib/kubeclient/test/valid_token_file +0 -1
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- # ResourceQuota tests
4
- class TestResourceQuota < MiniTest::Test
5
- def test_get_from_json_v1
6
- stub_request(:get, %r{/api/v1$})
7
- .to_return(body: open_test_file('core_api_resource_list.json'),
8
- status: 200)
9
- stub_request(:get, %r{/resourcequotas})
10
- .to_return(body: open_test_file('resource_quota.json'),
11
- status: 200)
12
-
13
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
14
- quota = client.get_resource_quota 'quota', 'quota-example'
15
-
16
- assert_instance_of(Kubeclient::ResourceQuota, quota)
17
- assert_equal('quota', quota.metadata.name)
18
- assert_equal('20', quota.spec.hard.cpu)
19
- assert_equal('10', quota.spec.hard.secrets)
20
-
21
- assert_requested(:get,
22
- 'http://localhost:8080/api/v1/namespaces/quota-example/resourcequotas/quota',
23
- times: 1)
24
- end
25
- end
@@ -1,70 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Namespace entity tests
4
- class TestSecret < MiniTest::Test
5
- def test_get_secret_v1
6
- stub_request(:get, %r{/api/v1$})
7
- .to_return(body: open_test_file('core_api_resource_list.json'),
8
- status: 200)
9
-
10
- stub_request(:get, %r{/secrets})
11
- .to_return(body: open_test_file('created_secret.json'),
12
- status: 200)
13
-
14
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
15
- secret = client.get_secret 'test-secret', 'dev'
16
-
17
- assert_instance_of(Kubeclient::Secret, secret)
18
- assert_equal('4e38a198-2bcb-11e5-a483-0e840567604d', secret.metadata.uid)
19
- assert_equal('test-secret', secret.metadata.name)
20
- assert_equal('v1', secret.apiVersion)
21
- assert_equal('Y2F0J3MgYXJlIGF3ZXNvbWUK', secret.data['super-secret'])
22
-
23
- assert_requested(:get,
24
- 'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
25
- times: 1)
26
- end
27
-
28
- def test_delete_secret_v1
29
- stub_request(:get, %r{/api/v1$})
30
- .to_return(body: open_test_file('core_api_resource_list.json'),
31
- status: 200)
32
-
33
- stub_request(:delete, %r{/secrets})
34
- .to_return(status: 200)
35
-
36
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
37
- client.delete_secret 'test-secret', 'dev'
38
-
39
- assert_requested(:delete,
40
- 'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
41
- times: 1)
42
- end
43
-
44
- def test_create_secret_v1
45
- stub_request(:get, %r{/api/v1$})
46
- .to_return(body: open_test_file('core_api_resource_list.json'),
47
- status: 200)
48
-
49
- stub_request(:post, %r{/secrets})
50
- .to_return(body: open_test_file('created_secret.json'),
51
- status: 201)
52
-
53
- secret = Kubeclient::Resource.new
54
- secret.metadata = {}
55
- secret.metadata.name = 'test-secret'
56
- secret.metadata.namespace = 'dev'
57
- secret.data = {}
58
- secret.data['super-secret'] = 'Y2F0J3MgYXJlIGF3ZXNvbWUK'
59
-
60
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
61
- created_secret = client.create_secret secret
62
- assert_instance_of(Kubeclient::Secret, created_secret)
63
- assert_equal(secret.metadata.name, created_secret.metadata.name)
64
- assert_equal(secret.metadata.namespace, created_secret.metadata.namespace)
65
- assert_equal(
66
- secret.data['super-secret'],
67
- created_secret.data['super-secret']
68
- )
69
- end
70
- end
@@ -1,293 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Service entity tests
4
- class TestService < MiniTest::Test
5
- def test_construct_our_own_service
6
- our_service = Kubeclient::Resource.new
7
- our_service.metadata = {}
8
- our_service.metadata.name = 'guestbook'
9
- our_service.metadata.namespace = 'staging'
10
- our_service.metadata.labels = {}
11
- our_service.metadata.labels.name = 'guestbook'
12
-
13
- our_service.spec = {}
14
- our_service.spec.ports = [{
15
- 'port' => 3000,
16
- 'targetPort' => 'http-server',
17
- 'protocol' => 'TCP'
18
- }]
19
-
20
- assert_equal('guestbook', our_service.metadata.labels.name)
21
-
22
- hash = our_service.to_h
23
-
24
- assert_equal our_service.metadata.labels.name,
25
- hash[:metadata][:labels][:name]
26
-
27
- expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
28
- stub_request(:get, %r{/api/v1$})
29
- .to_return(body: open_test_file('core_api_resource_list.json'),
30
- status: 200)
31
-
32
- stub_request(:post, expected_url)
33
- .to_return(body: open_test_file('created_service.json'), status: 201)
34
-
35
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
36
- created = client.create_service our_service
37
-
38
- assert_instance_of(Kubeclient::Service, created)
39
- assert_equal(created.metadata.name, our_service.metadata.name)
40
- assert_equal(created.spec.ports.size, our_service.spec.ports.size)
41
-
42
- # Check that original entity_config is not modified by kind/apiVersion patches:
43
- assert_equal(our_service.kind, nil)
44
-
45
- assert_requested(:post, expected_url, times: 1) do |req|
46
- data = JSON.parse(req.body)
47
- data['kind'] == 'Service' &&
48
- data['apiVersion'] == 'v1' &&
49
- data['metadata']['name'] == 'guestbook' &&
50
- data['metadata']['namespace'] == 'staging'
51
- end
52
- end
53
-
54
- def test_construct_service_from_symbol_keys
55
- service = Kubeclient::Resource.new
56
- service.metadata = {
57
- labels: { tier: 'frontend' },
58
- name: 'test-service',
59
- namespace: 'staging'
60
- }
61
- service.spec = {
62
- ports: [{
63
- port: 3000,
64
- targetPort: 'http-server',
65
- protocol: 'TCP'
66
- }]
67
- }
68
-
69
- expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
70
- stub_request(:get, %r{/api/v1$})
71
- .to_return(body: open_test_file('core_api_resource_list.json'),
72
- status: 200)
73
- stub_request(:post, expected_url)
74
- .to_return(body: open_test_file('created_service.json'), status: 201)
75
-
76
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
77
- client.create_service service
78
-
79
- assert_requested(:post, expected_url, times: 1) do |req|
80
- data = JSON.parse(req.body)
81
- data['kind'] == 'Service' &&
82
- data['apiVersion'] == 'v1' &&
83
- data['metadata']['name'] == 'test-service' &&
84
- data['metadata']['labels']['tier'] == 'frontend' &&
85
- data['metadata']['namespace'] == 'staging'
86
- end
87
- end
88
-
89
- def test_construct_service_from_string_keys
90
- service = Kubeclient::Resource.new
91
- service.metadata = {
92
- 'labels' => { 'tier' => 'frontend' },
93
- 'name' => 'test-service',
94
- 'namespace' => 'staging'
95
- }
96
- service.spec = {
97
- 'ports' => [{
98
- 'port' => 3000,
99
- 'targetPort' => 'http-server',
100
- 'protocol' => 'TCP'
101
- }]
102
- }
103
-
104
- stub_request(:get, %r{/api/v1$})
105
- .to_return(body: open_test_file('core_api_resource_list.json'),
106
- status: 200)
107
- expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
108
- stub_request(:post, %r{namespaces/staging/services})
109
- .to_return(body: open_test_file('created_service.json'), status: 201)
110
-
111
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
112
- client.create_service service
113
-
114
- assert_requested(:post, expected_url, times: 1) do |req|
115
- data = JSON.parse(req.body)
116
- data['kind'] == 'Service' &&
117
- data['apiVersion'] == 'v1' &&
118
- data['metadata']['name'] == 'test-service' &&
119
- data['metadata']['labels']['tier'] == 'frontend' &&
120
- data['metadata']['namespace'] == 'staging'
121
- end
122
- end
123
-
124
- def test_conversion_from_json_v1
125
- stub_request(:get, %r{/api/v1$})
126
- .to_return(body: open_test_file('core_api_resource_list.json'),
127
- status: 200)
128
- stub_request(:get, %r{/services})
129
- .to_return(body: open_test_file('service.json'),
130
- status: 200)
131
-
132
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
133
- service = client.get_service 'redis-slave', 'development'
134
-
135
- assert_instance_of(Kubeclient::Service, service)
136
- assert_equal('2015-04-05T13:00:31Z',
137
- service.metadata.creationTimestamp)
138
- assert_equal('bdb80a8f-db93-11e4-b293-f8b156af4ae1', service.metadata.uid)
139
- assert_equal('redis-slave', service.metadata.name)
140
- assert_equal('2815', service.metadata.resourceVersion)
141
- assert_equal('v1', service.apiVersion)
142
- assert_equal('10.0.0.140', service.spec.clusterIP)
143
- assert_equal('development', service.metadata.namespace)
144
-
145
- assert_equal('TCP', service.spec.ports[0].protocol)
146
- assert_equal(6379, service.spec.ports[0].port)
147
- assert_equal('', service.spec.ports[0].name)
148
- assert_equal('redis-server', service.spec.ports[0].targetPort)
149
-
150
- assert_requested(:get,
151
- 'http://localhost:8080/api/v1/namespaces/development/services/redis-slave',
152
- times: 1)
153
- end
154
-
155
- def test_delete_service
156
- our_service = Kubeclient::Resource.new
157
- our_service.name = 'redis-service'
158
- # TODO, new ports assignment to be added
159
- our_service.labels = {}
160
- our_service.labels.component = 'apiserver'
161
- our_service.labels.provider = 'kubernetes'
162
-
163
- stub_request(:get, %r{/api/v1$})
164
- .to_return(body: open_test_file('core_api_resource_list.json'),
165
- status: 200)
166
- stub_request(:delete, %r{/namespaces/default/services})
167
- .to_return(status: 200)
168
-
169
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
170
- client.delete_service our_service.name, 'default'
171
-
172
- assert_requested(:delete,
173
- 'http://localhost:8080/api/v1/namespaces/default/services/redis-service',
174
- times: 1)
175
- end
176
-
177
- def test_get_service_no_ns
178
- stub_request(:get, %r{/api/v1$})
179
- .to_return(body: open_test_file('core_api_resource_list.json'),
180
- status: 200)
181
- # when not specifying namespace for entities which
182
- # are not node or namespace, the request will fail
183
- stub_request(:get, %r{/services/redis-slave})
184
- .to_return(status: 404)
185
-
186
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
187
-
188
- exception = assert_raises(KubeException) do
189
- client.get_service 'redis-slave'
190
- end
191
- assert_equal(404, exception.error_code)
192
- end
193
-
194
- def test_get_service
195
- stub_request(:get, %r{/api/v1$})
196
- .to_return(body: open_test_file('core_api_resource_list.json'),
197
- status: 200)
198
- stub_request(:get, %r{/namespaces/development/services/redis-slave})
199
- .to_return(body: open_test_file('service.json'),
200
- status: 200)
201
-
202
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
203
- service = client.get_service 'redis-slave', 'development'
204
- assert_equal('redis-slave', service.metadata.name)
205
-
206
- assert_requested(:get,
207
- 'http://localhost:8080/api/v1/namespaces/development/services/redis-slave',
208
- times: 1)
209
- end
210
-
211
- def test_update_service
212
- service = Kubeclient::Resource.new
213
- name = 'my_service'
214
-
215
- service.metadata = {}
216
- service.metadata.name = name
217
- service.metadata.namespace = 'development'
218
-
219
- stub_request(:get, %r{/api/v1$})
220
- .to_return(body: open_test_file('core_api_resource_list.json'),
221
- status: 200)
222
- expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
223
- stub_request(:put, expected_url)
224
- .to_return(body: open_test_file('service_update.json'), status: 201)
225
-
226
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
227
- client.update_service service
228
-
229
- assert_requested(:put, expected_url, times: 1) do |req|
230
- data = JSON.parse(req.body)
231
- data['metadata']['name'] == name &&
232
- data['metadata']['namespace'] == 'development'
233
- end
234
- end
235
-
236
- def test_update_service_with_string_keys
237
- service = Kubeclient::Resource.new
238
- name = 'my_service'
239
-
240
- service.metadata = {
241
- 'name' => name,
242
- 'namespace' => 'development'
243
- }
244
-
245
- stub_request(:get, %r{/api/v1$})
246
- .to_return(body: open_test_file('core_api_resource_list.json'),
247
- status: 200)
248
- expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
249
- stub_request(:put, expected_url)
250
- .to_return(body: open_test_file('service_update.json'), status: 201)
251
-
252
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
253
- client.update_service service
254
-
255
- assert_requested(:put, expected_url, times: 1) do |req|
256
- data = JSON.parse(req.body)
257
- data['metadata']['name'] == name &&
258
- data['metadata']['namespace'] == 'development'
259
- end
260
- end
261
-
262
- def test_patch_service
263
- service = Kubeclient::Resource.new
264
- name = 'my_service'
265
-
266
- service.metadata = {}
267
- service.metadata.name = name
268
- service.metadata.namespace = 'development'
269
-
270
- stub_request(:get, %r{/api/v1$})
271
- .to_return(body: open_test_file('core_api_resource_list.json'),
272
- status: 200)
273
- expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
274
- stub_request(:patch, expected_url)
275
- .to_return(body: open_test_file('service_patch.json'), status: 200)
276
-
277
- patch = {
278
- metadata: {
279
- annotations: {
280
- key: 'value'
281
- }
282
- }
283
- }
284
-
285
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
286
- client.patch_service name, patch, 'development'
287
-
288
- assert_requested(:patch, expected_url, times: 1) do |req|
289
- data = JSON.parse(req.body)
290
- data['metadata']['annotations']['key'] == 'value'
291
- end
292
- end
293
- end
@@ -1,28 +0,0 @@
1
- require 'test_helper'
2
-
3
- # ServiceAccount tests
4
- class TestServiceAccount < MiniTest::Test
5
- def test_get_from_json_v1
6
- stub_request(:get, %r{/serviceaccounts})
7
- .to_return(body: open_test_file('service_account.json'),
8
- status: 200)
9
- stub_request(:get, %r{/api/v1$})
10
- .to_return(body: open_test_file('core_api_resource_list.json'),
11
- status: 200)
12
-
13
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
14
- account = client.get_service_account 'default'
15
-
16
- assert_instance_of(Kubeclient::ServiceAccount, account)
17
- assert_equal('default', account.metadata.name)
18
- assert_equal('default-token-6s23q', account.secrets[0].name)
19
- assert_equal('default-dockercfg-62tf3', account.secrets[1].name)
20
-
21
- assert_requested(:get,
22
- 'http://localhost:8080/api/v1/serviceaccounts/default',
23
- times: 1)
24
- assert_requested(:get,
25
- 'http://localhost:8080/api/v1',
26
- times: 1)
27
- end
28
- end
@@ -1,119 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Watch entity tests
4
- class TestWatch < MiniTest::Test
5
- def test_watch_pod_success
6
- expected = [
7
- { 'type' => 'ADDED', 'resourceVersion' => '1389' },
8
- { 'type' => 'MODIFIED', 'resourceVersion' => '1390' },
9
- { 'type' => 'DELETED', 'resourceVersion' => '1398' }
10
- ]
11
-
12
- stub_request(:get, %r{/api/v1$})
13
- .to_return(body: open_test_file('core_api_resource_list.json'),
14
- status: 200)
15
-
16
- stub_request(:get, %r{.*\/watch/pods})
17
- .to_return(body: open_test_file('watch_stream.json'),
18
- status: 200)
19
-
20
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
21
-
22
- client.watch_pods.to_enum.with_index do |notice, index|
23
- assert_instance_of(Kubeclient::Common::WatchNotice, notice)
24
- assert_equal(expected[index]['type'], notice.type)
25
- assert_equal('Pod', notice.object.kind)
26
- assert_equal('php', notice.object.metadata.name)
27
- assert_equal(expected[index]['resourceVersion'],
28
- notice.object.metadata.resourceVersion)
29
- end
30
- end
31
-
32
- def test_watch_pod_failure
33
- stub_request(:get, %r{/api/v1$})
34
- .to_return(body: open_test_file('core_api_resource_list.json'),
35
- status: 200)
36
- stub_request(:get, %r{.*\/watch/pods}).to_return(status: 404)
37
-
38
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
39
- assert_raises KubeException do
40
- client.watch_pods.each do
41
- end
42
- end
43
- end
44
-
45
- # Ensure that WatchStream respects a format that's not JSON
46
- def test_watch_stream_text
47
- url = 'http://www.example.com/foobar'
48
- expected_lines = open_test_file('pod_log.txt').read.split("\n")
49
-
50
- stub_request(:get, url)
51
- .to_return(body: open_test_file('pod_log.txt'),
52
- status: 200)
53
-
54
- stream = Kubeclient::Common::WatchStream.new(URI.parse(url), {}, format: :txt)
55
- stream.to_enum.with_index do |line, index|
56
- assert_instance_of(String, line)
57
- assert_equal(expected_lines[index], line)
58
- end
59
- end
60
-
61
- def test_watch_with_resource_version
62
- api_host = 'http://localhost:8080/api'
63
- version = '1995'
64
- stub_request(:get, %r{/api/v1$})
65
- .to_return(body: open_test_file('core_api_resource_list.json'),
66
- status: 200)
67
- stub_request(:get, %r{.*\/watch/events})
68
- .to_return(body: open_test_file('watch_stream.json'),
69
- status: 200)
70
-
71
- client = Kubeclient::Client.new api_host, 'v1'
72
- results = client.watch_events(version).to_enum
73
-
74
- assert_equal(3, results.count)
75
- assert_requested(:get,
76
- "#{api_host}/v1/watch/events?resourceVersion=#{version}",
77
- times: 1)
78
- end
79
-
80
- def test_watch_with_label_selector
81
- api_host = 'http://localhost:8080/api'
82
- selector = 'name=redis-master'
83
-
84
- stub_request(:get, %r{/api/v1$})
85
- .to_return(body: open_test_file('core_api_resource_list.json'),
86
- status: 200)
87
- stub_request(:get, %r{.*\/watch/events})
88
- .to_return(body: open_test_file('watch_stream.json'),
89
- status: 200)
90
-
91
- client = Kubeclient::Client.new api_host, 'v1'
92
- results = client.watch_events(label_selector: selector).to_enum
93
-
94
- assert_equal(3, results.count)
95
- assert_requested(:get,
96
- "#{api_host}/v1/watch/events?labelSelector=#{selector}",
97
- times: 1)
98
- end
99
-
100
- def test_watch_with_field_selector
101
- api_host = 'http://localhost:8080/api'
102
- selector = 'involvedObject.kind=Pod'
103
-
104
- stub_request(:get, %r{/api/v1$})
105
- .to_return(body: open_test_file('core_api_resource_list.json'),
106
- status: 200)
107
- stub_request(:get, %r{.*\/watch/events})
108
- .to_return(body: open_test_file('watch_stream.json'),
109
- status: 200)
110
-
111
- client = Kubeclient::Client.new api_host, 'v1'
112
- results = client.watch_events(field_selector: selector).to_enum
113
-
114
- assert_equal(3, results.count)
115
- assert_requested(:get,
116
- "#{api_host}/v1/watch/events?fieldSelector=#{selector}",
117
- times: 1)
118
- end
119
- end