kubeclient 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kubeclient might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +73 -0
- data/kubeclient.gemspec +0 -1
- data/lib/kubeclient.rb +3 -24
- data/lib/kubeclient/common.rb +153 -63
- data/lib/kubeclient/config.rb +2 -1
- data/lib/kubeclient/version.rb +1 -1
- data/test/cassettes/kubernetes_guestbook.yml +34 -1
- data/test/json/bindings_list.json +10 -0
- data/test/json/config_map_list.json +9 -0
- data/test/json/core_api_resource_list.json +181 -0
- data/test/json/pod_template_list.json +9 -0
- data/test/json/processed_template.json +27 -0
- data/test/test_common.rb +32 -0
- data/test/test_component_status.rb +6 -0
- data/test/test_endpoint.rb +5 -1
- data/test/test_guestbook_go.rb +1 -1
- data/test/test_kubeclient.rb +80 -7
- data/test/test_limit_range.rb +4 -0
- data/test/test_missing_methods.rb +42 -0
- data/test/test_namespace.rb +11 -2
- data/test/test_node.rb +6 -0
- data/test/test_persistent_volume.rb +6 -0
- data/test/test_persistent_volume_claim.rb +6 -0
- data/test/test_pod.rb +6 -0
- data/test/test_process_template.rb +44 -0
- data/test/test_replication_controller.rb +3 -0
- data/test/test_resource_quota.rb +3 -0
- data/test/test_secret.rb +13 -1
- data/test/test_service.rb +38 -7
- data/test/test_service_account.rb +6 -0
- data/test/test_watch.rb +16 -1
- metadata +18 -16
data/lib/kubeclient/config.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'base64'
|
3
|
+
require 'pathname'
|
3
4
|
|
4
5
|
module Kubeclient
|
5
6
|
# Kubernetes client configuration class
|
@@ -63,7 +64,7 @@ module Kubeclient
|
|
63
64
|
private
|
64
65
|
|
65
66
|
def ext_file_path(path)
|
66
|
-
File.join(@kcfg_path, path)
|
67
|
+
Pathname(path).absolute? ? path : File.join(@kcfg_path, path)
|
67
68
|
end
|
68
69
|
|
69
70
|
def fetch_context(context_name)
|
data/lib/kubeclient/version.rb
CHANGED
@@ -843,4 +843,37 @@ http_interactions:
|
|
843
843
|
string: '{"kind":"Namespace","apiVersion":"v1","metadata":{"name":"kubeclient-ns","selfLink":"/api/v1/namespaces/kubeclient-ns","uid":"f41e6b27-3e7d-11e5-a75a-18037327aaeb","resourceVersion":"584","creationTimestamp":"2015-08-09T10:03:59Z","deletionTimestamp":"2015-08-09T10:03:59Z"},"spec":{"finalizers":["kubernetes"]},"status":{"phase":"Terminating"}}'
|
844
844
|
http_version:
|
845
845
|
recorded_at: Sun, 09 Aug 2015 10:00:02 GMT
|
846
|
-
|
846
|
+
- request:
|
847
|
+
method: get
|
848
|
+
uri: http://10.35.0.23:8080/api/v1
|
849
|
+
body:
|
850
|
+
encoding: US-ASCII
|
851
|
+
string: ''
|
852
|
+
headers:
|
853
|
+
Accept:
|
854
|
+
- "*/*"
|
855
|
+
Accept-Encoding:
|
856
|
+
- gzip, deflate
|
857
|
+
User-Agent:
|
858
|
+
- rest-client/2.0.0 (linux-gnu x86_64) ruby/2.3.0p0
|
859
|
+
Host:
|
860
|
+
- localhost:8080
|
861
|
+
response:
|
862
|
+
status:
|
863
|
+
code: 200
|
864
|
+
message: OK
|
865
|
+
headers:
|
866
|
+
Content-Type:
|
867
|
+
- application/json
|
868
|
+
Date:
|
869
|
+
- Mon, 29 Aug 2016 15:51:30 GMT
|
870
|
+
Transfer-Encoding:
|
871
|
+
- chunked
|
872
|
+
body:
|
873
|
+
encoding: UTF-8
|
874
|
+
string: '{"kind":"APIResourceList","groupVersion":"v1","resources":[{"name":"bindings","namespaced":true,"kind":"Binding"},{"name":"componentstatuses","namespaced":false,"kind":"ComponentStatus"},{"name":"configmaps","namespaced":true,"kind":"ConfigMap"},{"name":"endpoints","namespaced":true,"kind":"Endpoints"},{"name":"events","namespaced":true,"kind":"Event"},{"name":"limitranges","namespaced":true,"kind":"LimitRange"},{"name":"namespaces","namespaced":false,"kind":"Namespace"},{"name":"namespaces/finalize","namespaced":false,"kind":"Namespace"},{"name":"namespaces/status","namespaced":false,"kind":"Namespace"},{"name":"nodes","namespaced":false,"kind":"Node"},{"name":"nodes/proxy","namespaced":false,"kind":"Node"},{"name":"nodes/status","namespaced":false,"kind":"Node"},{"name":"persistentvolumeclaims","namespaced":true,"kind":"PersistentVolumeClaim"},{"name":"persistentvolumeclaims/status","namespaced":true,"kind":"PersistentVolumeClaim"},{"name":"persistentvolumes","namespaced":false,"kind":"PersistentVolume"},{"name":"persistentvolumes/status","namespaced":false,"kind":"PersistentVolume"},{"name":"pods","namespaced":true,"kind":"Pod"},{"name":"pods/attach","namespaced":true,"kind":"Pod"},{"name":"pods/binding","namespaced":true,"kind":"Binding"},{"name":"pods/exec","namespaced":true,"kind":"Pod"},{"name":"pods/log","namespaced":true,"kind":"Pod"},{"name":"pods/portforward","namespaced":true,"kind":"Pod"},{"name":"pods/proxy","namespaced":true,"kind":"Pod"},{"name":"pods/status","namespaced":true,"kind":"Pod"},{"name":"podtemplates","namespaced":true,"kind":"PodTemplate"},{"name":"replicationcontrollers","namespaced":true,"kind":"ReplicationController"},{"name":"replicationcontrollers/scale","namespaced":true,"kind":"Scale"},{"name":"replicationcontrollers/status","namespaced":true,"kind":"ReplicationController"},{"name":"resourcequotas","namespaced":true,"kind":"ResourceQuota"},{"name":"resourcequotas/status","namespaced":true,"kind":"ResourceQuota"},{"name":"secrets","namespaced":true,"kind":"Secret"},{"name":"serviceaccounts","namespaced":true,"kind":"ServiceAccount"},{"name":"services","namespaced":true,"kind":"Service"},{"name":"services/proxy","namespaced":true,"kind":"Service"},{"name":"services/status","namespaced":true,"kind":"Service"}]}
|
875
|
+
|
876
|
+
'
|
877
|
+
http_version:
|
878
|
+
recorded_at: Mon, 29 Aug 2016 15:51:30 GMT
|
879
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,181 @@
|
|
1
|
+
{
|
2
|
+
"kind": "APIResourceList",
|
3
|
+
"groupVersion": "v1",
|
4
|
+
"resources": [
|
5
|
+
{
|
6
|
+
"name": "bindings",
|
7
|
+
"namespaced": true,
|
8
|
+
"kind": "Binding"
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"name": "componentstatuses",
|
12
|
+
"namespaced": false,
|
13
|
+
"kind": "ComponentStatus"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"name": "configmaps",
|
17
|
+
"namespaced": true,
|
18
|
+
"kind": "ConfigMap"
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"name": "endpoints",
|
22
|
+
"namespaced": true,
|
23
|
+
"kind": "Endpoints"
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"name": "events",
|
27
|
+
"namespaced": true,
|
28
|
+
"kind": "Event"
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"name": "limitranges",
|
32
|
+
"namespaced": true,
|
33
|
+
"kind": "LimitRange"
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"name": "namespaces",
|
37
|
+
"namespaced": false,
|
38
|
+
"kind": "Namespace"
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"name": "namespaces/finalize",
|
42
|
+
"namespaced": false,
|
43
|
+
"kind": "Namespace"
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"name": "namespaces/status",
|
47
|
+
"namespaced": false,
|
48
|
+
"kind": "Namespace"
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"name": "nodes",
|
52
|
+
"namespaced": false,
|
53
|
+
"kind": "Node"
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"name": "nodes/proxy",
|
57
|
+
"namespaced": false,
|
58
|
+
"kind": "Node"
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"name": "nodes/status",
|
62
|
+
"namespaced": false,
|
63
|
+
"kind": "Node"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"name": "persistentvolumeclaims",
|
67
|
+
"namespaced": true,
|
68
|
+
"kind": "PersistentVolumeClaim"
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"name": "persistentvolumeclaims/status",
|
72
|
+
"namespaced": true,
|
73
|
+
"kind": "PersistentVolumeClaim"
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"name": "persistentvolumes",
|
77
|
+
"namespaced": false,
|
78
|
+
"kind": "PersistentVolume"
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"name": "persistentvolumes/status",
|
82
|
+
"namespaced": false,
|
83
|
+
"kind": "PersistentVolume"
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"name": "pods",
|
87
|
+
"namespaced": true,
|
88
|
+
"kind": "Pod"
|
89
|
+
},
|
90
|
+
{
|
91
|
+
"name": "pods/attach",
|
92
|
+
"namespaced": true,
|
93
|
+
"kind": "Pod"
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"name": "pods/binding",
|
97
|
+
"namespaced": true,
|
98
|
+
"kind": "Binding"
|
99
|
+
},
|
100
|
+
{
|
101
|
+
"name": "pods/exec",
|
102
|
+
"namespaced": true,
|
103
|
+
"kind": "Pod"
|
104
|
+
},
|
105
|
+
{
|
106
|
+
"name": "pods/log",
|
107
|
+
"namespaced": true,
|
108
|
+
"kind": "Pod"
|
109
|
+
},
|
110
|
+
{
|
111
|
+
"name": "pods/portforward",
|
112
|
+
"namespaced": true,
|
113
|
+
"kind": "Pod"
|
114
|
+
},
|
115
|
+
{
|
116
|
+
"name": "pods/proxy",
|
117
|
+
"namespaced": true,
|
118
|
+
"kind": "Pod"
|
119
|
+
},
|
120
|
+
{
|
121
|
+
"name": "pods/status",
|
122
|
+
"namespaced": true,
|
123
|
+
"kind": "Pod"
|
124
|
+
},
|
125
|
+
{
|
126
|
+
"name": "podtemplates",
|
127
|
+
"namespaced": true,
|
128
|
+
"kind": "PodTemplate"
|
129
|
+
},
|
130
|
+
{
|
131
|
+
"name": "replicationcontrollers",
|
132
|
+
"namespaced": true,
|
133
|
+
"kind": "ReplicationController"
|
134
|
+
},
|
135
|
+
{
|
136
|
+
"name": "replicationcontrollers/scale",
|
137
|
+
"namespaced": true,
|
138
|
+
"kind": "Scale"
|
139
|
+
},
|
140
|
+
{
|
141
|
+
"name": "replicationcontrollers/status",
|
142
|
+
"namespaced": true,
|
143
|
+
"kind": "ReplicationController"
|
144
|
+
},
|
145
|
+
{
|
146
|
+
"name": "resourcequotas",
|
147
|
+
"namespaced": true,
|
148
|
+
"kind": "ResourceQuota"
|
149
|
+
},
|
150
|
+
{
|
151
|
+
"name": "resourcequotas/status",
|
152
|
+
"namespaced": true,
|
153
|
+
"kind": "ResourceQuota"
|
154
|
+
},
|
155
|
+
{
|
156
|
+
"name": "secrets",
|
157
|
+
"namespaced": true,
|
158
|
+
"kind": "Secret"
|
159
|
+
},
|
160
|
+
{
|
161
|
+
"name": "serviceaccounts",
|
162
|
+
"namespaced": true,
|
163
|
+
"kind": "ServiceAccount"
|
164
|
+
},
|
165
|
+
{
|
166
|
+
"name": "services",
|
167
|
+
"namespaced": true,
|
168
|
+
"kind": "Service"
|
169
|
+
},
|
170
|
+
{
|
171
|
+
"name": "services/proxy",
|
172
|
+
"namespaced": true,
|
173
|
+
"kind": "Service"
|
174
|
+
},
|
175
|
+
{
|
176
|
+
"name": "services/status",
|
177
|
+
"namespaced": true,
|
178
|
+
"kind": "Service"
|
179
|
+
}
|
180
|
+
]
|
181
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"kind": "Template",
|
3
|
+
"apiVersion": "v1",
|
4
|
+
"metadata": {
|
5
|
+
"name": "my-templtae",
|
6
|
+
"namespace": "default",
|
7
|
+
"selfLink": "/oapi/v1/namespaces/default/processedtemplates/my-templtae",
|
8
|
+
"uid": "2240c61c-8f70-11e5-a806-001a4a231290",
|
9
|
+
"resourceVersion": "1399",
|
10
|
+
"creationTimestamp": "2015-11-20T10:19:07Z"
|
11
|
+
},
|
12
|
+
"objects": [
|
13
|
+
{
|
14
|
+
"apiVersion": "v1",
|
15
|
+
"kind": "Service",
|
16
|
+
"metadata": {
|
17
|
+
"name": "test/my-service"
|
18
|
+
}
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"parameters": [
|
22
|
+
{
|
23
|
+
"name": "NAME_PREFIX",
|
24
|
+
"value": "test/"
|
25
|
+
}
|
26
|
+
]
|
27
|
+
}
|
data/test/test_common.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# Unit tests for the common module
|
4
|
+
class CommonTest < MiniTest::Test
|
5
|
+
def test_underscore_entity
|
6
|
+
%w(
|
7
|
+
Pod pod
|
8
|
+
Service service
|
9
|
+
ReplicationController replication_controller
|
10
|
+
Node node
|
11
|
+
Event event
|
12
|
+
Endpoint endpoint
|
13
|
+
Namespace namespace
|
14
|
+
Secret secret
|
15
|
+
ResourceQuota resource_quota
|
16
|
+
LimitRange limit_range
|
17
|
+
PersistentVolume persistent_volume
|
18
|
+
PersistentVolumeClaim persistent_volume_claim
|
19
|
+
ComponentStatus component_status
|
20
|
+
ServiceAccount service_account
|
21
|
+
Project project
|
22
|
+
Route route
|
23
|
+
ClusterRoleBinding cluster_role_binding
|
24
|
+
Build build
|
25
|
+
BuildConfig build_config
|
26
|
+
Image image
|
27
|
+
ImageStream image_stream
|
28
|
+
).each_slice(2) do |singular, plural|
|
29
|
+
assert_equal(Kubeclient::ClientMixin.underscore_entity(singular), plural)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -6,6 +6,9 @@ class TestComponentStatus < MiniTest::Test
|
|
6
6
|
stub_request(:get, %r{/componentstatuses})
|
7
7
|
.to_return(body: open_test_file('component_status.json'),
|
8
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)
|
9
12
|
|
10
13
|
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
11
14
|
component_status = client.get_component_status 'etcd-0', 'default'
|
@@ -15,6 +18,9 @@ class TestComponentStatus < MiniTest::Test
|
|
15
18
|
assert_equal('Healthy', component_status.conditions[0].type)
|
16
19
|
assert_equal('True', component_status.conditions[0].status)
|
17
20
|
|
21
|
+
assert_requested(:get,
|
22
|
+
'http://localhost:8080/api/v1',
|
23
|
+
times: 1)
|
18
24
|
assert_requested(:get,
|
19
25
|
'http://localhost:8080/api/v1/namespaces/default/componentstatuses/etcd-0',
|
20
26
|
times: 1)
|
data/test/test_endpoint.rb
CHANGED
@@ -3,8 +3,12 @@ require 'test_helper'
|
|
3
3
|
# Endpoint entity tests
|
4
4
|
class TestEndpoint < MiniTest::Test
|
5
5
|
def test_create_endpoint
|
6
|
+
stub_request(:get, %r{/api/v1$})
|
7
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
8
|
+
status: 200)
|
9
|
+
|
6
10
|
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
7
|
-
testing_ep = Kubeclient::
|
11
|
+
testing_ep = Kubeclient::Resource.new
|
8
12
|
testing_ep.metadata = {}
|
9
13
|
testing_ep.metadata.name = 'myendpoint'
|
10
14
|
testing_ep.metadata.namespace = 'default'
|
data/test/test_guestbook_go.rb
CHANGED
@@ -13,7 +13,7 @@ class CreateGuestbookGo < MiniTest::Test
|
|
13
13
|
VCR.use_cassette('kubernetes_guestbook') do # , record: :new_episodes) do
|
14
14
|
client = Kubeclient::Client.new 'http://10.35.0.23:8080/api/', 'v1'
|
15
15
|
|
16
|
-
testing_ns = Kubeclient::
|
16
|
+
testing_ns = Kubeclient::Resource.new
|
17
17
|
testing_ns.metadata = {}
|
18
18
|
testing_ns.metadata.name = 'kubeclient-ns'
|
19
19
|
|
data/test/test_kubeclient.rb
CHANGED
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
# Kubernetes client entity tests
|
4
4
|
class KubeClientTest < MiniTest::Test
|
5
5
|
def test_json
|
6
|
-
our_object = Kubeclient::
|
6
|
+
our_object = Kubeclient::Resource.new
|
7
7
|
our_object.foo = 'bar'
|
8
8
|
our_object.nested = {}
|
9
9
|
our_object.nested.again = {}
|
@@ -41,6 +41,10 @@ class KubeClientTest < MiniTest::Test
|
|
41
41
|
def test_pass_proxy
|
42
42
|
uri = URI::HTTP.build(host: 'localhost', port: 8080)
|
43
43
|
proxy_uri = URI::HTTP.build(host: 'myproxyhost', port: 8888)
|
44
|
+
stub_request(:get, %r{/api/v1$})
|
45
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
46
|
+
status: 200)
|
47
|
+
|
44
48
|
client = Kubeclient::Client.new(uri, http_proxy_uri: proxy_uri)
|
45
49
|
rest_client = client.rest_client
|
46
50
|
assert_equal proxy_uri.to_s, rest_client.options[:proxy]
|
@@ -51,11 +55,14 @@ class KubeClientTest < MiniTest::Test
|
|
51
55
|
end
|
52
56
|
|
53
57
|
def test_exception
|
58
|
+
stub_request(:get, %r{/api/v1$})
|
59
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
60
|
+
status: 200)
|
54
61
|
stub_request(:post, %r{/services})
|
55
62
|
.to_return(body: open_test_file('namespace_exception.json'),
|
56
63
|
status: 409)
|
57
64
|
|
58
|
-
service = Kubeclient::
|
65
|
+
service = Kubeclient::Resource.new
|
59
66
|
service.metadata = {}
|
60
67
|
service.metadata.name = 'redisslave'
|
61
68
|
service.metadata.namespace = 'default'
|
@@ -149,6 +156,9 @@ class KubeClientTest < MiniTest::Test
|
|
149
156
|
end
|
150
157
|
|
151
158
|
def test_nonjson_exception
|
159
|
+
stub_request(:get, %r{/api/v1$})
|
160
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
161
|
+
status: 200)
|
152
162
|
stub_request(:get, %r{/servic})
|
153
163
|
.to_return(body: open_test_file('service_illegal_json_404.json'),
|
154
164
|
status: 404)
|
@@ -165,6 +175,9 @@ class KubeClientTest < MiniTest::Test
|
|
165
175
|
end
|
166
176
|
|
167
177
|
def test_entity_list
|
178
|
+
stub_request(:get, %r{/api/v1$})
|
179
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
180
|
+
status: 200)
|
168
181
|
stub_request(:get, %r{/services})
|
169
182
|
.to_return(body: open_test_file('entity_list.json'),
|
170
183
|
status: 200)
|
@@ -187,6 +200,9 @@ class KubeClientTest < MiniTest::Test
|
|
187
200
|
def test_entities_with_label_selector
|
188
201
|
selector = 'component=apiserver'
|
189
202
|
|
203
|
+
stub_request(:get, %r{/api/v1$})
|
204
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
205
|
+
status: 200)
|
190
206
|
stub_request(:get, %r{/services})
|
191
207
|
.to_return(body: open_test_file('entity_list.json'),
|
192
208
|
status: 200)
|
@@ -203,6 +219,9 @@ class KubeClientTest < MiniTest::Test
|
|
203
219
|
def test_entities_with_field_selector
|
204
220
|
selector = 'involvedObject.name=redis-master'
|
205
221
|
|
222
|
+
stub_request(:get, %r{/api/v1$})
|
223
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
224
|
+
status: 200)
|
206
225
|
stub_request(:get, %r{/services})
|
207
226
|
.to_return(body: open_test_file('entity_list.json'),
|
208
227
|
status: 200)
|
@@ -217,6 +236,9 @@ class KubeClientTest < MiniTest::Test
|
|
217
236
|
end
|
218
237
|
|
219
238
|
def test_empty_list
|
239
|
+
stub_request(:get, %r{/api/v1$})
|
240
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
241
|
+
status: 200)
|
220
242
|
stub_request(:get, %r{/pods})
|
221
243
|
.to_return(body: open_test_file('empty_pod_list.json'),
|
222
244
|
status: 200)
|
@@ -228,6 +250,22 @@ class KubeClientTest < MiniTest::Test
|
|
228
250
|
end
|
229
251
|
|
230
252
|
def test_get_all
|
253
|
+
stub_request(:get, %r{/api/v1$})
|
254
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
255
|
+
status: 200)
|
256
|
+
|
257
|
+
stub_request(:get, %r{/bindings})
|
258
|
+
.to_return(body: open_test_file('bindings_list.json'),
|
259
|
+
status: 404)
|
260
|
+
|
261
|
+
stub_request(:get, %r{/configmaps})
|
262
|
+
.to_return(body: open_test_file('config_map_list.json'),
|
263
|
+
status: 200)
|
264
|
+
|
265
|
+
stub_request(:get, %r{/podtemplates})
|
266
|
+
.to_return(body: open_test_file('pod_template_list.json'),
|
267
|
+
status: 200)
|
268
|
+
|
231
269
|
stub_request(:get, %r{/services})
|
232
270
|
.to_return(body: open_test_file('service_list.json'),
|
233
271
|
status: 200)
|
@@ -284,7 +322,7 @@ class KubeClientTest < MiniTest::Test
|
|
284
322
|
|
285
323
|
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
286
324
|
result = client.all_entities
|
287
|
-
assert_equal(
|
325
|
+
assert_equal(16, result.keys.size)
|
288
326
|
assert_instance_of(Kubeclient::Common::EntityList, result['node'])
|
289
327
|
assert_instance_of(Kubeclient::Common::EntityList, result['service'])
|
290
328
|
assert_instance_of(Kubeclient::Common::EntityList,
|
@@ -312,6 +350,10 @@ class KubeClientTest < MiniTest::Test
|
|
312
350
|
.with(headers: { Authorization: 'Bearer valid_token' })
|
313
351
|
.to_return(body: open_test_file('pod_list.json'),
|
314
352
|
status: 200)
|
353
|
+
stub_request(:get, %r{/api/v1$})
|
354
|
+
.with(headers: { Authorization: 'Bearer valid_token' })
|
355
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
356
|
+
status: 200)
|
315
357
|
|
316
358
|
client = Kubeclient::Client.new 'http://localhost:8080/api/',
|
317
359
|
auth_options: {
|
@@ -325,6 +367,9 @@ class KubeClientTest < MiniTest::Test
|
|
325
367
|
end
|
326
368
|
|
327
369
|
def test_api_bearer_token_success
|
370
|
+
stub_request(:get, %r{/api/v1$})
|
371
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
372
|
+
status: 200)
|
328
373
|
stub_request(:get, 'http://localhost:8080/api/v1/pods')
|
329
374
|
.with(headers: { Authorization: 'Bearer valid_token' })
|
330
375
|
.to_return(body: open_test_file('pod_list.json'),
|
@@ -342,11 +387,11 @@ class KubeClientTest < MiniTest::Test
|
|
342
387
|
end
|
343
388
|
|
344
389
|
def test_api_bearer_token_failure
|
345
|
-
error_message = '"/api/v1
|
390
|
+
error_message = '"/api/v1" is forbidden because ' \
|
346
391
|
'system:anonymous cannot list on pods in'
|
347
392
|
response = OpenStruct.new(code: 401, message: error_message)
|
348
393
|
|
349
|
-
stub_request(:get, 'http://localhost:8080/api/v1
|
394
|
+
stub_request(:get, 'http://localhost:8080/api/v1')
|
350
395
|
.with(headers: { Authorization: 'Bearer invalid_token' })
|
351
396
|
.to_raise(KubeException.new(403, error_message, response))
|
352
397
|
|
@@ -362,6 +407,9 @@ class KubeClientTest < MiniTest::Test
|
|
362
407
|
end
|
363
408
|
|
364
409
|
def test_api_basic_auth_success
|
410
|
+
stub_request(:get, 'http://username:password@localhost:8080/api/v1')
|
411
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
412
|
+
status: 200)
|
365
413
|
stub_request(:get, 'http://username:password@localhost:8080/api/v1/pods')
|
366
414
|
.to_return(body: open_test_file('pod_list.json'),
|
367
415
|
status: 200)
|
@@ -382,6 +430,9 @@ class KubeClientTest < MiniTest::Test
|
|
382
430
|
end
|
383
431
|
|
384
432
|
def test_api_basic_auth_back_comp_success
|
433
|
+
stub_request(:get, 'http://username:password@localhost:8080/api/v1')
|
434
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
435
|
+
status: 200)
|
385
436
|
stub_request(:get, 'http://username:password@localhost:8080/api/v1/pods')
|
386
437
|
.to_return(body: open_test_file('pod_list.json'),
|
387
438
|
status: 200)
|
@@ -405,7 +456,7 @@ class KubeClientTest < MiniTest::Test
|
|
405
456
|
error_message = 'HTTP status code 401, 401 Unauthorized'
|
406
457
|
response = OpenStruct.new(code: 401, message: '401 Unauthorized')
|
407
458
|
|
408
|
-
stub_request(:get, 'http://username:password@localhost:8080/api/v1
|
459
|
+
stub_request(:get, 'http://username:password@localhost:8080/api/v1')
|
409
460
|
.to_raise(KubeException.new(401, error_message, response))
|
410
461
|
|
411
462
|
client = Kubeclient::Client.new 'http://localhost:8080/api/',
|
@@ -419,7 +470,7 @@ class KubeClientTest < MiniTest::Test
|
|
419
470
|
assert_equal(error_message, exception.message)
|
420
471
|
assert_equal(response, exception.response)
|
421
472
|
assert_requested(:get,
|
422
|
-
'http://username:password@localhost:8080/api/v1
|
473
|
+
'http://username:password@localhost:8080/api/v1',
|
423
474
|
times: 1)
|
424
475
|
end
|
425
476
|
|
@@ -496,6 +547,9 @@ class KubeClientTest < MiniTest::Test
|
|
496
547
|
end
|
497
548
|
|
498
549
|
def test_api_bearer_token_file_success
|
550
|
+
stub_request(:get, %r{/api/v1$})
|
551
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
552
|
+
status: 200)
|
499
553
|
stub_request(:get, 'http://localhost:8080/api/v1/pods')
|
500
554
|
.with(headers: { Authorization: 'Bearer valid_token' })
|
501
555
|
.to_return(body: open_test_file('pod_list.json'),
|
@@ -514,10 +568,20 @@ class KubeClientTest < MiniTest::Test
|
|
514
568
|
end
|
515
569
|
|
516
570
|
def test_proxy_url
|
571
|
+
stub_request(:get, %r{/api/v1$})
|
572
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
573
|
+
status: 200)
|
574
|
+
|
517
575
|
client = Kubeclient::Client.new 'http://host:8080', 'v1'
|
518
576
|
assert_equal('http://host:8080/api/v1/proxy/namespaces/ns/services/srvname:srvportname',
|
519
577
|
client.proxy_url('service', 'srvname', 'srvportname', 'ns'))
|
520
578
|
|
579
|
+
assert_equal('http://host:8080/api/v1/proxy/namespaces/ns/services/srvname:srvportname',
|
580
|
+
client.proxy_url('services', 'srvname', 'srvportname', 'ns'))
|
581
|
+
|
582
|
+
assert_equal('http://host:8080/api/v1/namespaces/ns/pods/srvname:srvportname/proxy',
|
583
|
+
client.proxy_url('pod', 'srvname', 'srvportname', 'ns'))
|
584
|
+
|
521
585
|
assert_equal('http://host:8080/api/v1/namespaces/ns/pods/srvname:srvportname/proxy',
|
522
586
|
client.proxy_url('pods', 'srvname', 'srvportname', 'ns'))
|
523
587
|
|
@@ -525,9 +589,15 @@ class KubeClientTest < MiniTest::Test
|
|
525
589
|
assert_equal('http://host:8080/api/v1/proxy/nodes/srvname:srvportname',
|
526
590
|
client.proxy_url('nodes', 'srvname', 'srvportname'))
|
527
591
|
|
592
|
+
assert_equal('http://host:8080/api/v1/proxy/nodes/srvname:srvportname',
|
593
|
+
client.proxy_url('node', 'srvname', 'srvportname'))
|
594
|
+
|
528
595
|
# Check integer port
|
529
596
|
assert_equal('http://host:8080/api/v1/proxy/nodes/srvname:5001',
|
530
597
|
client.proxy_url('nodes', 'srvname', 5001))
|
598
|
+
|
599
|
+
assert_equal('http://host:8080/api/v1/proxy/nodes/srvname:5001',
|
600
|
+
client.proxy_url('node', 'srvname', 5001))
|
531
601
|
end
|
532
602
|
|
533
603
|
def test_attr_readers
|
@@ -546,6 +616,9 @@ class KubeClientTest < MiniTest::Test
|
|
546
616
|
|
547
617
|
def test_nil_items
|
548
618
|
# handle https://github.com/kubernetes/kubernetes/issues/13096
|
619
|
+
stub_request(:get, %r{/api/v1$})
|
620
|
+
.to_return(body: open_test_file('core_api_resource_list.json'),
|
621
|
+
status: 200)
|
549
622
|
stub_request(:get, %r{/persistentvolumeclaims})
|
550
623
|
.to_return(body: open_test_file('persistent_volume_claims_nil_items.json'),
|
551
624
|
status: 200)
|