kubeclient 0.1.1 → 0.1.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.
- checksums.yaml +5 -13
- data/.rubocop.yml +6 -0
- data/README.md +7 -0
- data/Rakefile +6 -3
- data/kubeclient.gemspec +14 -13
- data/lib/kubeclient/entity_list.rb +4 -3
- data/lib/kubeclient/event.rb +4 -0
- data/lib/kubeclient/kube_exception.rb +3 -3
- data/lib/kubeclient/node.rb +2 -2
- data/lib/kubeclient/pod.rb +1 -1
- data/lib/kubeclient/replication_controller.rb +2 -2
- data/lib/kubeclient/service.rb +0 -1
- data/lib/kubeclient/version.rb +2 -1
- data/lib/kubeclient/watch.rb +4 -0
- data/lib/kubeclient/watch_stream.rb +29 -0
- data/lib/kubeclient.rb +99 -90
- data/test/json/entity_list_b1.json +43 -0
- data/test/json/event_list_b3.json +35 -0
- data/test/json/get_all_nodes_b1.json +36 -0
- data/test/json/get_all_pods_b1.json +10 -0
- data/test/json/get_all_replication_b1.json +10 -0
- data/test/json/get_all_services_b1.json +43 -0
- data/test/json/node_b1.json +15 -0
- data/test/json/node_b3.json +27 -0
- data/test/json/pod_b1.json +27 -0
- data/test/json/pod_b3.json +92 -0
- data/test/json/replication_controller_b1.json +66 -0
- data/test/json/replication_controller_b3.json +57 -0
- data/test/json/service_b1.json +20 -0
- data/test/json/service_b3.json +27 -0
- data/test/json/service_exception_b1.json +12 -0
- data/test/json/watch_stream_b3.json +3 -0
- data/test/kubeclient_test.rb +63 -50
- data/test/node_test.rb +30 -33
- data/test/pod_test.rb +19 -24
- data/test/replication_controller_test.rb +34 -33
- data/test/service_test.rb +66 -53
- data/test/watch_test.rb +40 -0
- metadata +70 -18
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"kind": "Service",
|
3
|
+
"id": "redisslave",
|
4
|
+
"uid": "6a022e83-8ea7-11e4-a6e7-3c970e4a436a",
|
5
|
+
"creationTimestamp": "2014-12-28T17:37:21+02:00",
|
6
|
+
"selfLink": "/api/v1beta1/services/redisslave?namespace=default",
|
7
|
+
"resourceVersion": 8,
|
8
|
+
"apiVersion": "v1beta1",
|
9
|
+
"namespace": "default",
|
10
|
+
"port": 10001,
|
11
|
+
"protocol": "TCP",
|
12
|
+
"labels": {
|
13
|
+
"name": "redisslave"
|
14
|
+
},
|
15
|
+
"selector": {
|
16
|
+
"name": "redisslave"
|
17
|
+
},
|
18
|
+
"containerPort": 6379,
|
19
|
+
"portalIP": "10.0.0.248"
|
20
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"kind": "Service",
|
3
|
+
"apiVersion": "v1beta3",
|
4
|
+
"metadata": {
|
5
|
+
"name": "kubernetes-ro",
|
6
|
+
"namespace": "default",
|
7
|
+
"selfLink": "/api/v1beta3/services/kubernetes-ro?namespace=default",
|
8
|
+
"uid": "ffb153db-a230-11e4-a36b-3c970e4a436a",
|
9
|
+
"resourceVersion": "4",
|
10
|
+
"creationTimestamp": "2015-01-22T14:20:05+02:00",
|
11
|
+
"labels": {
|
12
|
+
"component": "apiserver",
|
13
|
+
"provider": "kubernetes"
|
14
|
+
}
|
15
|
+
},
|
16
|
+
"spec": {
|
17
|
+
"port": 80,
|
18
|
+
"protocol": "TCP",
|
19
|
+
"selector": null,
|
20
|
+
"portalIP": "10.0.0.154",
|
21
|
+
"containerPort": 0,
|
22
|
+
"sessionAffinity": "None"
|
23
|
+
},
|
24
|
+
"status": {
|
25
|
+
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,3 @@
|
|
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/kubeclient_test.rb
CHANGED
@@ -3,90 +3,103 @@ require 'json'
|
|
3
3
|
require 'webmock/minitest'
|
4
4
|
require './lib/kubeclient'
|
5
5
|
|
6
|
+
def open_test_json_file(name)
|
7
|
+
File.new(File.join(File.dirname(__FILE__), 'json', name))
|
8
|
+
end
|
6
9
|
|
10
|
+
# Kubernetes client entity tests
|
7
11
|
class KubeClientTest < MiniTest::Test
|
8
|
-
|
9
12
|
def test_json
|
10
13
|
our_object = Service.new
|
11
14
|
our_object.foo = 'bar'
|
12
15
|
our_object.nested = {}
|
13
16
|
our_object.nested.again = {}
|
14
17
|
our_object.nested.again.again = {}
|
15
|
-
our_object.nested.again.again.name =
|
18
|
+
our_object.nested.again.again.name = 'aaron'
|
19
|
+
|
20
|
+
expected = { 'foo' => 'bar', 'nested' => { 'again' => { 'again' =>
|
21
|
+
{ 'name' => 'aaron' } } } }
|
16
22
|
|
17
|
-
|
18
|
-
assert_equal({"foo"=>"bar", "nested"=>{"again"=>{"again"=>{"name"=>"aaron"}}}},
|
19
|
-
hash)
|
23
|
+
assert_equal(expected, JSON.parse(JSON.dump(our_object.to_h)))
|
20
24
|
end
|
21
25
|
|
22
26
|
def test_exception
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
to_return(:body => json_response, :status => 409)
|
27
|
+
stub_request(:post, /\/services/)
|
28
|
+
.to_return(body: open_test_json_file('service_exception_b1.json'),
|
29
|
+
status: 409)
|
27
30
|
|
28
31
|
service = Service.new
|
29
32
|
service.id = 'redisslave'
|
30
33
|
service.port = 80
|
31
34
|
service.container_port = 6379
|
32
|
-
service.protocol =
|
35
|
+
service.protocol = 'TCP'
|
33
36
|
|
34
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/'
|
35
|
-
exception = assert_raises(KubeException) { service = client.create_service service }
|
37
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
exception = assert_raises(KubeException) do
|
40
|
+
service = client.create_service service
|
41
|
+
end
|
40
42
|
|
43
|
+
assert_instance_of(KubeException, exception)
|
44
|
+
assert_equal('service redisslave already exists', exception.message)
|
45
|
+
assert_equal(409, exception.error_code)
|
41
46
|
end
|
42
47
|
|
43
48
|
def test_entity_list
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
stub_request(:get, /\/services/)
|
50
|
+
.to_return(body: open_test_json_file('entity_list_b1.json'),
|
51
|
+
status: 200)
|
52
|
+
|
53
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
|
48
54
|
services = client.get_services
|
55
|
+
|
49
56
|
refute_empty(services)
|
50
|
-
assert_instance_of(EntityList,services)
|
51
|
-
assert_equal(
|
52
|
-
assert_equal(2,services.size)
|
53
|
-
assert_instance_of(Service,services[0])
|
54
|
-
assert_instance_of(Service,services[1])
|
57
|
+
assert_instance_of(EntityList, services)
|
58
|
+
assert_equal('Service', services.kind)
|
59
|
+
assert_equal(2, services.size)
|
60
|
+
assert_instance_of(Service, services[0])
|
61
|
+
assert_instance_of(Service, services[1])
|
55
62
|
end
|
56
63
|
|
57
64
|
def test_get_all
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
stub_request(:get,
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
65
|
+
stub_request(:get, /\/services/)
|
66
|
+
.to_return(body: open_test_json_file('get_all_services_b1.json'),
|
67
|
+
status: 200)
|
68
|
+
|
69
|
+
stub_request(:get, /\/pods/)
|
70
|
+
.to_return(body: open_test_json_file('get_all_pods_b1.json'),
|
71
|
+
status: 200)
|
72
|
+
|
73
|
+
stub_request(:get, /\/nodes/)
|
74
|
+
.to_return(body: open_test_json_file('get_all_nodes_b1.json'),
|
75
|
+
status: 200)
|
76
|
+
|
77
|
+
stub_request(:get, /\/replicationControllers/)
|
78
|
+
.to_return(body: open_test_json_file('get_all_replication_b1.json'),
|
79
|
+
status: 200)
|
80
|
+
|
81
|
+
stub_request(:get, /\/events/)
|
82
|
+
.to_return(body: open_test_json_file('event_list_b3.json'), status: 200)
|
83
|
+
|
84
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
|
74
85
|
result = client.get_all_entities
|
75
|
-
assert_equal(
|
76
|
-
assert_instance_of(EntityList, result[
|
77
|
-
assert_instance_of(EntityList, result[
|
78
|
-
assert_instance_of(EntityList, result[
|
79
|
-
assert_instance_of(EntityList, result[
|
80
|
-
assert_instance_of(
|
81
|
-
assert_instance_of(
|
86
|
+
assert_equal(5, result.keys.size)
|
87
|
+
assert_instance_of(EntityList, result['node'])
|
88
|
+
assert_instance_of(EntityList, result['service'])
|
89
|
+
assert_instance_of(EntityList, result['replication_controller'])
|
90
|
+
assert_instance_of(EntityList, result['pod'])
|
91
|
+
assert_instance_of(EntityList, result['event'])
|
92
|
+
assert_instance_of(Service, result['service'][0])
|
93
|
+
assert_instance_of(Node, result['node'][0])
|
94
|
+
assert_instance_of(Event, result['event'][0])
|
82
95
|
end
|
83
96
|
|
97
|
+
private
|
98
|
+
|
84
99
|
# dup method creates a shallow copy which is not good in this case
|
85
100
|
# since rename_keys changes the input hash
|
86
101
|
# hence need to create a deep_copy
|
87
|
-
private
|
88
102
|
def deep_copy(hash)
|
89
103
|
Marshal.load(Marshal.dump(hash))
|
90
104
|
end
|
91
|
-
|
92
|
-
end
|
105
|
+
end
|
data/test/node_test.rb
CHANGED
@@ -4,45 +4,42 @@ require 'kubeclient/node'
|
|
4
4
|
require 'json'
|
5
5
|
require './lib/kubeclient'
|
6
6
|
|
7
|
+
# Node entity tests
|
7
8
|
class NodeTest < MiniTest::Test
|
8
9
|
def test_get_from_json_v1
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
assert_respond_to(node,
|
19
|
-
assert_respond_to(node,
|
20
|
-
assert_respond_to(node,
|
21
|
-
assert_respond_to(node,
|
22
|
-
assert_respond_to(node,
|
23
|
-
|
24
|
-
|
25
|
-
assert_equal
|
26
|
-
assert_equal 1000, node.resources.capacity.cpu
|
10
|
+
stub_request(:get, /\/nodes/)
|
11
|
+
.to_return(body: open_test_json_file('node_b1.json'),
|
12
|
+
status: 200)
|
13
|
+
|
14
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
|
15
|
+
node = client.get_node('127.0.0.1')
|
16
|
+
|
17
|
+
assert_instance_of(Node, node)
|
18
|
+
assert_respond_to(node, 'creationTimestamp')
|
19
|
+
assert_respond_to(node, 'uid')
|
20
|
+
assert_respond_to(node, 'id')
|
21
|
+
assert_respond_to(node, 'resources')
|
22
|
+
assert_respond_to(node, 'resourceVersion')
|
23
|
+
assert_respond_to(node, 'apiVersion')
|
24
|
+
|
25
|
+
assert_equal(7, node.resourceVersion)
|
26
|
+
assert_equal(1000, node.resources.capacity.cpu)
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_get_from_json_v3
|
30
|
-
|
30
|
+
stub_request(:get, /\/nodes/)
|
31
|
+
.to_return(body: open_test_json_file('node_b3.json'),
|
32
|
+
status: 200)
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
|
35
|
+
node = client.get_node('127.0.0.1')
|
34
36
|
|
35
|
-
|
36
|
-
node = client.get_node "127.0.0.1"
|
37
|
-
|
38
|
-
assert_instance_of(Node,node)
|
39
|
-
|
40
|
-
assert_equal("01018013-a231-11e4-a36b-3c970e4a436a", node.metadata.uid)
|
41
|
-
assert_equal("127.0.0.1", node.metadata.name)
|
42
|
-
assert_equal("7", node.metadata.resourceVersion)
|
43
|
-
assert_equal("v1beta3", node.apiVersion)
|
44
|
-
assert_equal("2015-01-22T14:20:08+02:00", node.metadata.creationTimestamp)
|
37
|
+
assert_instance_of(Node, node)
|
45
38
|
|
39
|
+
assert_equal('01018013-a231-11e4-a36b-3c970e4a436a', node.metadata.uid)
|
40
|
+
assert_equal('127.0.0.1', node.metadata.name)
|
41
|
+
assert_equal('7', node.metadata.resourceVersion)
|
42
|
+
assert_equal('v1beta3', node.apiVersion)
|
43
|
+
assert_equal('2015-01-22T14:20:08+02:00', node.metadata.creationTimestamp)
|
46
44
|
end
|
47
|
-
|
48
|
-
end
|
45
|
+
end
|
data/test/pod_test.rb
CHANGED
@@ -4,37 +4,32 @@ require 'kubeclient/pod'
|
|
4
4
|
require 'json'
|
5
5
|
require './lib/kubeclient'
|
6
6
|
|
7
|
+
# Pod entity tests
|
7
8
|
class PodTest < MiniTest::Test
|
8
|
-
|
9
9
|
def test_get_from_json_v1
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
stub_request(:get, /.*pods*/).
|
14
|
-
to_return(:body => json_response, :status => 200)
|
10
|
+
stub_request(:get, /\/pods/)
|
11
|
+
.to_return(body: open_test_json_file('pod_b1.json'),
|
12
|
+
status: 200)
|
15
13
|
|
16
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/'
|
17
|
-
pod = client.get_pod
|
14
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
|
15
|
+
pod = client.get_pod 'redis-master-pod'
|
18
16
|
|
19
|
-
assert_instance_of(Pod,pod)
|
20
|
-
assert_equal(
|
21
|
-
assert_equal(
|
17
|
+
assert_instance_of(Pod, pod)
|
18
|
+
assert_equal('redis-master-pod', pod.id)
|
19
|
+
assert_equal('redis-master',
|
20
|
+
pod.desiredState.manifest.containers[0]['name'])
|
22
21
|
end
|
23
22
|
|
24
23
|
def test_get_from_json_v3
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
stub_request(:get, /.*pods*/).
|
29
|
-
to_return(:body => json_response, :status => 200)
|
24
|
+
stub_request(:get, /\/pods/)
|
25
|
+
.to_return(body: open_test_json_file('pod_b3.json'),
|
26
|
+
status: 200)
|
30
27
|
|
31
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/'
|
32
|
-
pod = client.get_pod
|
33
|
-
|
34
|
-
assert_instance_of(Pod,pod)
|
35
|
-
assert_equal("redis-master3",pod.metadata.name)
|
36
|
-
assert_equal("dockerfile/redis",pod.spec.containers[0]["image"])
|
28
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
|
29
|
+
pod = client.get_pod 'redis-master-pod'
|
37
30
|
|
31
|
+
assert_instance_of(Pod, pod)
|
32
|
+
assert_equal('redis-master3', pod.metadata.name)
|
33
|
+
assert_equal('dockerfile/redis', pod.spec.containers[0]['image'])
|
38
34
|
end
|
39
|
-
|
40
|
-
end
|
35
|
+
end
|
@@ -4,42 +4,43 @@ require './lib/kubeclient'
|
|
4
4
|
require 'kubeclient/replication_controller'
|
5
5
|
require 'json'
|
6
6
|
|
7
|
+
# Replication Controller entity tests
|
7
8
|
class ReplicationControllerTest < MiniTest::Test
|
8
|
-
|
9
9
|
def test_get_from_json_v1
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/'
|
15
|
-
rc = client.get_replication_controller
|
16
|
-
|
17
|
-
assert_instance_of(ReplicationController,rc)
|
18
|
-
assert_equal(
|
19
|
-
assert_equal(
|
20
|
-
assert_equal(
|
21
|
-
assert_equal(3,rc.desiredState.replicas)
|
22
|
-
assert_equal(
|
23
|
-
#the access to containers is not as nice as rest of the properties,
|
24
|
-
#
|
25
|
-
|
10
|
+
stub_request(:get, /\/replicationControllers/)
|
11
|
+
.to_return(body: open_test_json_file('replication_controller_b1.json'),
|
12
|
+
status: 200)
|
13
|
+
|
14
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
|
15
|
+
rc = client.get_replication_controller 'frontendController'
|
16
|
+
|
17
|
+
assert_instance_of(ReplicationController, rc)
|
18
|
+
assert_equal('frontendController', rc.id)
|
19
|
+
assert_equal('f4e5966c-8eb2-11e4-a6e7-3c970e4a436a', rc.uid)
|
20
|
+
assert_equal('default', rc.namespace)
|
21
|
+
assert_equal(3, rc.desiredState.replicas)
|
22
|
+
assert_equal('frontend', rc.desiredState.replicaSelector.name)
|
23
|
+
# the access to containers is not as nice as rest of the properties,
|
24
|
+
# but it's about to change in beta v3, hence it can significantly
|
25
|
+
# impact the design of the client. to be revisited after beta v3 api
|
26
|
+
# is released.
|
27
|
+
assert_equal('php-redis', rc.desiredState.podTemplate
|
28
|
+
.desiredState.manifest.containers[0]['name'])
|
26
29
|
end
|
27
30
|
|
28
31
|
def test_get_from_json_v3
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
assert_equal(
|
39
|
-
assert_equal(
|
40
|
-
assert_equal(
|
41
|
-
assert_equal(
|
42
|
-
assert_equal("guestbook",rc.spec.selector.name)
|
32
|
+
stub_request(:get, /\/replicationcontrollers/)
|
33
|
+
.to_return(body: open_test_json_file('replication_controller_b3.json'),
|
34
|
+
status: 200)
|
35
|
+
|
36
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
|
37
|
+
rc = client.get_replication_controller 'frontendController'
|
38
|
+
|
39
|
+
assert_instance_of(ReplicationController, rc)
|
40
|
+
assert_equal('guestbook-controller', rc.metadata.name)
|
41
|
+
assert_equal('c71aa4c0-a240-11e4-a265-3c970e4a436a', rc.metadata.uid)
|
42
|
+
assert_equal('default', rc.metadata.namespace)
|
43
|
+
assert_equal(3, rc.spec.replicas)
|
44
|
+
assert_equal('guestbook', rc.spec.selector.name)
|
43
45
|
end
|
44
|
-
|
45
|
-
end
|
46
|
+
end
|
data/test/service_test.rb
CHANGED
@@ -4,9 +4,28 @@ require 'kubeclient/service'
|
|
4
4
|
require 'json'
|
5
5
|
require './lib/kubeclient'
|
6
6
|
|
7
|
+
# Service entity tests
|
7
8
|
class ServiceTest < MiniTest::Test
|
8
9
|
def test_get_from_json_v1
|
9
|
-
mock = Service.new(
|
10
|
+
mock = Service.new(
|
11
|
+
'kind' => 'Service',
|
12
|
+
'id' => 'redis-service',
|
13
|
+
'uid' => 'fb01a69c-8ae2-11e4-acc5-3c970e4a436a',
|
14
|
+
'namespace' => 'default',
|
15
|
+
'port' => 80,
|
16
|
+
'protocol' => 'TCP',
|
17
|
+
'labels' => {
|
18
|
+
'component' => 'apiserver',
|
19
|
+
'provider' => 'kubernetes'
|
20
|
+
},
|
21
|
+
'selector' => nil,
|
22
|
+
'creation_timestamp' => '2014-12-23T22:33:40+02:00',
|
23
|
+
'self_link' => '/api/v1beta1/services/kubernetes-ro?namespace=default',
|
24
|
+
'resource_version' => 4,
|
25
|
+
'api_version' => 'v1beta1',
|
26
|
+
'container_port' => 0,
|
27
|
+
'portal_ip' => '10.0.0.54'
|
28
|
+
)
|
10
29
|
|
11
30
|
assert_equal 'redis-service', mock.id
|
12
31
|
assert_equal 'apiserver', mock.labels.component
|
@@ -16,83 +35,77 @@ class ServiceTest < MiniTest::Test
|
|
16
35
|
our_service = Service.new
|
17
36
|
our_service.id = 'redis-service'
|
18
37
|
our_service.port = 80
|
19
|
-
our_service.protocol =
|
38
|
+
our_service.protocol = 'TCP'
|
20
39
|
our_service.labels = {}
|
21
40
|
our_service.labels.component = 'apiserver'
|
22
41
|
our_service.labels.provider = 'kubernetes'
|
23
42
|
|
24
|
-
assert_equal
|
25
|
-
assert_equal
|
43
|
+
assert_equal('kubernetes', our_service.labels.provider)
|
44
|
+
assert_equal('apiserver', our_service.labels.component)
|
26
45
|
|
27
46
|
hash = our_service.to_h
|
28
47
|
|
29
48
|
assert_equal our_service.labels.provider, hash[:labels][:provider]
|
30
49
|
end
|
31
50
|
|
32
|
-
|
33
51
|
def test_conversion_from_json_v1
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
assert_equal(
|
45
|
-
assert_equal(
|
46
|
-
assert_equal(
|
47
|
-
assert_equal(
|
48
|
-
assert_equal(
|
49
|
-
assert_equal(
|
50
|
-
assert_equal(
|
51
|
-
assert_equal(
|
52
|
-
assert_equal(
|
53
|
-
assert_equal("default",service.namespace)
|
54
|
-
|
52
|
+
stub_request(:get, /\/services/)
|
53
|
+
.to_return(body: open_test_json_file('service_b1.json'),
|
54
|
+
status: 200)
|
55
|
+
|
56
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
|
57
|
+
service = client.get_service 'redisslave'
|
58
|
+
|
59
|
+
assert_instance_of(Service, service)
|
60
|
+
# checking that creationTimestamp was renamed properly
|
61
|
+
assert_equal('2014-12-28T17:37:21+02:00', service.creationTimestamp)
|
62
|
+
assert_equal('6a022e83-8ea7-11e4-a6e7-3c970e4a436a', service.uid)
|
63
|
+
assert_equal('redisslave', service.id)
|
64
|
+
assert_equal(8, service.resourceVersion)
|
65
|
+
assert_equal('v1beta1', service.apiVersion)
|
66
|
+
assert_equal('10.0.0.248', service.portalIP)
|
67
|
+
assert_equal(6379, service.containerPort)
|
68
|
+
assert_equal('TCP', service.protocol)
|
69
|
+
assert_equal(10_001, service.port)
|
70
|
+
assert_equal('default', service.namespace)
|
55
71
|
end
|
56
72
|
|
57
73
|
def test_conversion_from_json_v3
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
service
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
assert_equal(
|
70
|
-
assert_equal(
|
71
|
-
assert_equal(
|
72
|
-
assert_equal(
|
73
|
-
assert_equal(
|
74
|
-
assert_equal(
|
75
|
-
assert_equal(
|
76
|
-
assert_equal(
|
77
|
-
assert_equal(
|
78
|
-
assert_equal("default",service.metadata.namespace)
|
79
|
-
|
74
|
+
stub_request(:get, /\/services/)
|
75
|
+
.to_return(body: open_test_json_file('service_b3.json'),
|
76
|
+
status: 200)
|
77
|
+
|
78
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
|
79
|
+
service = client.get_service 'redisslave'
|
80
|
+
|
81
|
+
assert_instance_of(Service, service)
|
82
|
+
# checking that creationTimestamp was renamed properly
|
83
|
+
assert_equal('2015-01-22T14:20:05+02:00',
|
84
|
+
service.metadata.creationTimestamp)
|
85
|
+
assert_equal('ffb153db-a230-11e4-a36b-3c970e4a436a', service.metadata.uid)
|
86
|
+
assert_equal('kubernetes-ro', service.metadata.name)
|
87
|
+
assert_equal('4', service.metadata.resourceVersion)
|
88
|
+
assert_equal('v1beta3', service.apiVersion)
|
89
|
+
assert_equal('10.0.0.154', service.spec.portalIP)
|
90
|
+
assert_equal(0, service.spec.containerPort)
|
91
|
+
assert_equal('TCP', service.spec.protocol)
|
92
|
+
assert_equal(80, service.spec.port)
|
93
|
+
assert_equal('default', service.metadata.namespace)
|
80
94
|
end
|
81
95
|
|
82
96
|
def test_delete_service
|
83
97
|
our_service = Service.new
|
84
98
|
our_service.id = 'redis-service'
|
85
99
|
our_service.port = 80
|
86
|
-
our_service.protocol =
|
100
|
+
our_service.protocol = 'TCP'
|
87
101
|
our_service.labels = {}
|
88
102
|
our_service.labels.component = 'apiserver'
|
89
103
|
our_service.labels.provider = 'kubernetes'
|
90
104
|
|
91
|
-
stub_request(:delete,
|
92
|
-
|
105
|
+
stub_request(:delete, /\/services/)
|
106
|
+
.to_return(status: 200)
|
93
107
|
|
94
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/'
|
108
|
+
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
|
95
109
|
client.delete_service our_service.id
|
96
|
-
|
97
110
|
end
|
98
111
|
end
|