kubeclient 0.1.7 → 0.1.8

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.

@@ -0,0 +1,8 @@
1
+ {
2
+ "kind": "Status",
3
+ "apiVersion": "v1beta3",
4
+ "metadata": {},
5
+ "status": "Failure",
6
+ "message": "converting to : type names don't match (Pod, Namespace)",
7
+ "code": 500
8
+ }
@@ -4,9 +4,9 @@
4
4
  "metadata": {
5
5
  "name": "127.0.0.1",
6
6
  "selfLink": "/api/v1beta3/nodes/127.0.0.1",
7
- "uid": "01018013-a231-11e4-a36b-3c970e4a436a",
8
- "resourceVersion": "7",
9
- "creationTimestamp": "2015-01-22T14:20:08+02:00"
7
+ "uid": "041143c5-ce39-11e4-ac24-3c970e4a436a",
8
+ "resourceVersion": "1724",
9
+ "creationTimestamp": "2015-03-19T15:08:20+02:00"
10
10
  },
11
11
  "spec": {
12
12
  "capacity": {
@@ -19,9 +19,11 @@
19
19
  "conditions": [
20
20
  {
21
21
  "kind": "Ready",
22
- "status": "Full",
23
- "lastTransitionTime": null
22
+ "status": "None",
23
+ "lastProbeTime": "2015-03-20T14:16:52+02:00",
24
+ "lastTransitionTime": "2015-03-19T15:08:20+02:00",
25
+ "reason": "Node health check failed: kubelet /healthz endpoint returns not ok"
24
26
  }
25
27
  ]
26
28
  }
27
- }
29
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "kind": "NodeList",
3
+ "apiVersion": "v1beta3",
4
+ "metadata": {
5
+ "selfLink": "/api/v1beta3/nodes",
6
+ "resourceVersion": "137"
7
+ },
8
+ "items": [
9
+ {
10
+ "metadata": {
11
+ "name": "127.0.0.1",
12
+ "selfLink": "/api/v1beta3/nodes/127.0.0.1",
13
+ "uid": "041143c5-ce39-11e4-ac24-3c970e4a436a",
14
+ "resourceVersion": "137",
15
+ "creationTimestamp": "2015-03-19T15:08:20+02:00"
16
+ },
17
+ "spec": {
18
+ "capacity": {
19
+ "cpu": "1",
20
+ "memory": "3Gi"
21
+ }
22
+ },
23
+ "status": {
24
+ "hostIP": "127.0.0.1",
25
+ "conditions": [
26
+ {
27
+ "kind": "Ready",
28
+ "status": "None",
29
+ "lastProbeTime": "2015-03-19T15:29:33+02:00",
30
+ "lastTransitionTime": "2015-03-19T15:08:20+02:00",
31
+ "reason": "Node health check failed: kubelet /healthz endpoint returns not ok"
32
+ }
33
+ ]
34
+ }
35
+ }
36
+ ]
37
+ }
@@ -0,0 +1,75 @@
1
+ {
2
+ "kind": "PodList",
3
+ "apiVersion": "v1beta3",
4
+ "metadata": {
5
+ "selfLink": "/api/v1beta3/pods",
6
+ "resourceVersion": "1315"
7
+ },
8
+ "items": [
9
+ {
10
+ "metadata": {
11
+ "name": "redis-master3",
12
+ "namespace": "default",
13
+ "selfLink": "/api/v1beta3/pods/redis-master3?namespace=default",
14
+ "uid": "1da148b4-cef5-11e4-ac24-3c970e4a436a",
15
+ "resourceVersion": "1301",
16
+ "creationTimestamp": "2015-03-20T13:34:48+02:00",
17
+ "labels": {
18
+ "mylabel": "mylabelvalue",
19
+ "role": "pod"
20
+ }
21
+ },
22
+ "spec": {
23
+ "volumes": null,
24
+ "containers": [
25
+ {
26
+ "name": "master",
27
+ "image": "dockerfile/redis",
28
+ "ports": [
29
+ {
30
+ "hostPort": 6379,
31
+ "containerPort": 6379,
32
+ "protocol": "TCP"
33
+ }
34
+ ],
35
+ "resources": {
36
+ "limits": {
37
+ "cpu": "100m"
38
+ }
39
+ },
40
+ "terminationMessagePath": "/dev/termination-log",
41
+ "imagePullPolicy": "IfNotPresent",
42
+ "capabilities": {}
43
+ },
44
+ {
45
+ "name": "php-redis",
46
+ "image": "kubernetes/example-guestbook-php-redis",
47
+ "ports": [
48
+ {
49
+ "hostPort": 8000,
50
+ "containerPort": 80,
51
+ "protocol": "TCP"
52
+ }
53
+ ],
54
+ "resources": {
55
+ "limits": {
56
+ "cpu": "100m",
57
+ "memory": "50000000"
58
+ }
59
+ },
60
+ "terminationMessagePath": "/dev/termination-log",
61
+ "imagePullPolicy": "IfNotPresent",
62
+ "capabilities": {}
63
+ }
64
+ ],
65
+ "restartPolicy": {
66
+ "always": {}
67
+ },
68
+ "dnsPolicy": "ClusterFirst"
69
+ },
70
+ "status": {
71
+ "phase": "Pending"
72
+ }
73
+ }
74
+ ]
75
+ }
@@ -0,0 +1,64 @@
1
+ {
2
+ "kind": "ReplicationControllerList",
3
+ "apiVersion": "v1beta3",
4
+ "metadata": {
5
+ "selfLink": "/api/v1beta3/namespaces/default/replicationcontrollers",
6
+ "resourceVersion": "1636"
7
+ },
8
+ "items": [
9
+ {
10
+ "metadata": {
11
+ "name": "redis-master-controller",
12
+ "namespace": "default",
13
+ "selfLink": "/api/v1beta3/namespaces/default/replicationcontrollers/redis-master-controller?namespace=default",
14
+ "uid": "108eb547-cefa-11e4-ac24-3c970e4a436a",
15
+ "resourceVersion": "1631",
16
+ "creationTimestamp": "2015-03-20T14:10:14+02:00",
17
+ "labels": {
18
+ "name": "redis-master"
19
+ }
20
+ },
21
+ "spec": {
22
+ "replicas": 1,
23
+ "selector": {
24
+ "name": "redis-master"
25
+ },
26
+ "template": {
27
+ "metadata": {
28
+ "creationTimestamp": null,
29
+ "labels": {
30
+ "app": "redis",
31
+ "name": "redis-master"
32
+ }
33
+ },
34
+ "spec": {
35
+ "volumes": null,
36
+ "containers": [
37
+ {
38
+ "name": "redis-master",
39
+ "image": "dockerfile/redis",
40
+ "ports": [
41
+ {
42
+ "containerPort": 6379,
43
+ "protocol": "TCP"
44
+ }
45
+ ],
46
+ "resources": {},
47
+ "terminationMessagePath": "/dev/termination-log",
48
+ "imagePullPolicy": "IfNotPresent",
49
+ "capabilities": {}
50
+ }
51
+ ],
52
+ "restartPolicy": {
53
+ "always": {}
54
+ },
55
+ "dnsPolicy": "ClusterFirst"
56
+ }
57
+ }
58
+ },
59
+ "status": {
60
+ "replicas": 1
61
+ }
62
+ }
63
+ ]
64
+ }
@@ -0,0 +1 @@
1
+ 404: Page Not Found
@@ -0,0 +1,7 @@
1
+ {
2
+ "versions": [
3
+ "v1beta1",
4
+ "v1beta2",
5
+ "v1beta3"
6
+ ]
7
+ }
@@ -7,7 +7,7 @@ end
7
7
  # Kubernetes client entity tests
8
8
  class KubeClientTest < MiniTest::Test
9
9
  def test_json
10
- our_object = Service.new
10
+ our_object = Kubeclient::Service.new
11
11
  our_object.foo = 'bar'
12
12
  our_object.nested = {}
13
13
  our_object.nested.again = {}
@@ -20,42 +20,122 @@ class KubeClientTest < MiniTest::Test
20
20
  assert_equal(expected, JSON.parse(JSON.dump(our_object.to_h)))
21
21
  end
22
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
+
23
45
  def test_exception
24
46
  stub_request(:post, /\/services/)
25
- .to_return(body: open_test_json_file('service_exception_b1.json'),
47
+ .to_return(body: open_test_json_file('namespace_exception_b3.json'),
26
48
  status: 409)
27
49
 
28
- service = Service.new
50
+ service = Kubeclient::Service.new
29
51
  service.id = 'redisslave'
30
52
  service.port = 80
31
53
  service.container_port = 6379
32
54
  service.protocol = 'TCP'
33
55
 
34
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
56
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
35
57
 
36
58
  exception = assert_raises(KubeException) do
37
59
  service = client.create_service service
38
60
  end
39
61
 
40
62
  assert_instance_of(KubeException, exception)
41
- assert_equal('service redisslave already exists', exception.message)
63
+ assert_equal("converting to : type names don't match (Pod, Namespace)",
64
+ exception.message)
42
65
  assert_equal(409, exception.error_code)
43
66
  end
44
67
 
68
+ def test_api
69
+ stub_request(:get, 'http://localhost:8080/api/')
70
+ .to_return(status: 200, body: open_test_json_file('versions_list.json'))
71
+
72
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
73
+ response = client.api
74
+ assert_includes(response, 'versions')
75
+ end
76
+
77
+ def test_api_valid
78
+ stub_request(:get, 'http://localhost:8080/api/')
79
+ .to_return(status: 200, body: open_test_json_file('versions_list.json'))
80
+
81
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
82
+ assert client.api_valid?
83
+ end
84
+
85
+ def test_api_valid_with_invalid_json
86
+ stub_request(:get, 'http://localhost:8080/api/')
87
+ .to_return(status: 200, body: '{}')
88
+
89
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
90
+ refute client.api_valid?
91
+ end
92
+
93
+ def test_api_valid_with_bad_endpoint
94
+ stub_request(:get, 'http://localhost:8080/api/')
95
+ .to_return(status: [404, 'Resource Not Found'])
96
+
97
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
98
+ assert_raises(KubeException) { client.api_valid? }
99
+ end
100
+
101
+ def test_api_valid_with_non_json
102
+ stub_request(:get, 'http://localhost:8080/api/')
103
+ .to_return(status: 200, body: '<html></html>')
104
+
105
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
106
+ assert_raises(JSON::ParserError) { client.api_valid? }
107
+ end
108
+
109
+ def test_nonjson_exception
110
+ stub_request(:get, /\/servic/)
111
+ .to_return(body: open_test_json_file('service_illegal_json_404.json'),
112
+ status: 404)
113
+
114
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
115
+
116
+ exception = assert_raises(KubeException) do
117
+ client.get_services
118
+ end
119
+
120
+ assert_instance_of(KubeException, exception)
121
+ assert_equal('404 Resource Not Found', exception.message)
122
+ assert_equal(404, exception.error_code)
123
+ end
124
+
45
125
  def test_entity_list
46
126
  stub_request(:get, /\/services/)
47
- .to_return(body: open_test_json_file('entity_list_b1.json'),
127
+ .to_return(body: open_test_json_file('entity_list_b3.json'),
48
128
  status: 200)
49
129
 
50
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
130
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
51
131
  services = client.get_services
52
132
 
53
133
  refute_empty(services)
54
- assert_instance_of(EntityList, services)
134
+ assert_instance_of(Kubeclient::EntityList, services)
55
135
  assert_equal('Service', services.kind)
56
136
  assert_equal(2, services.size)
57
- assert_instance_of(Service, services[0])
58
- assert_instance_of(Service, services[1])
137
+ assert_instance_of(Kubeclient::Service, services[0])
138
+ assert_instance_of(Kubeclient::Service, services[1])
59
139
  end
60
140
 
61
141
  def test_empty_list
@@ -65,26 +145,26 @@ class KubeClientTest < MiniTest::Test
65
145
 
66
146
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
67
147
  pods = client.get_pods
68
- assert_instance_of(EntityList, pods)
148
+ assert_instance_of(Kubeclient::EntityList, pods)
69
149
  assert_equal(0, pods.size)
70
150
  end
71
151
 
72
152
  def test_get_all
73
153
  stub_request(:get, /\/services/)
74
- .to_return(body: open_test_json_file('get_all_services_b1.json'),
154
+ .to_return(body: open_test_json_file('get_all_services_b3.json'),
75
155
  status: 200)
76
156
 
77
157
  stub_request(:get, /\/pods/)
78
- .to_return(body: open_test_json_file('get_all_pods_b1.json'),
158
+ .to_return(body: open_test_json_file('pod_list_b3.json'),
79
159
  status: 200)
80
160
 
81
161
  stub_request(:get, /\/nodes/)
82
- .to_return(body: open_test_json_file('get_all_nodes_b1.json'),
162
+ .to_return(body: open_test_json_file('node_list_b3.json'),
83
163
  status: 200)
84
164
 
85
- stub_request(:get, /\/replicationControllers/)
86
- .to_return(body: open_test_json_file('get_all_replication_b1.json'),
87
- status: 200)
165
+ stub_request(:get, /\/replicationcontrollers/)
166
+ .to_return(body: open_test_json_file('replication_controller_list_' \
167
+ 'b3.json'), status: 200)
88
168
 
89
169
  stub_request(:get, /\/events/)
90
170
  .to_return(body: open_test_json_file('event_list_b3.json'), status: 200)
@@ -97,20 +177,20 @@ class KubeClientTest < MiniTest::Test
97
177
  .to_return(body: open_test_json_file('namespace_list_b3.json'),
98
178
  status: 200)
99
179
 
100
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta1'
180
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
101
181
  result = client.all_entities
102
182
  assert_equal(7, result.keys.size)
103
- assert_instance_of(EntityList, result['node'])
104
- assert_instance_of(EntityList, result['service'])
105
- assert_instance_of(EntityList, result['replication_controller'])
106
- assert_instance_of(EntityList, result['pod'])
107
- assert_instance_of(EntityList, result['event'])
108
- assert_instance_of(EntityList, result['namespace'])
109
- assert_instance_of(Service, result['service'][0])
110
- assert_instance_of(Node, result['node'][0])
111
- assert_instance_of(Event, result['event'][0])
112
- assert_instance_of(Endpoint, result['endpoint'][0])
113
- assert_instance_of(Namespace, result['namespace'][0])
183
+ assert_instance_of(Kubeclient::EntityList, result['node'])
184
+ assert_instance_of(Kubeclient::EntityList, result['service'])
185
+ assert_instance_of(Kubeclient::EntityList, result['replication_controller'])
186
+ assert_instance_of(Kubeclient::EntityList, result['pod'])
187
+ assert_instance_of(Kubeclient::EntityList, result['event'])
188
+ assert_instance_of(Kubeclient::EntityList, result['namespace'])
189
+ assert_instance_of(Kubeclient::Service, result['service'][0])
190
+ assert_instance_of(Kubeclient::Node, result['node'][0])
191
+ assert_instance_of(Kubeclient::Event, result['event'][0])
192
+ assert_instance_of(Kubeclient::Endpoint, result['endpoint'][0])
193
+ assert_instance_of(Kubeclient::Namespace, result['namespace'][0])
114
194
  end
115
195
 
116
196
  private
@@ -10,7 +10,7 @@ class TestNamespace < MiniTest::Test
10
10
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
11
11
  namespace = client.get_namespace 'staging'
12
12
 
13
- assert_instance_of(Namespace, namespace)
13
+ assert_instance_of(Kubeclient::Namespace, namespace)
14
14
  assert_equal('e388bc10-c021-11e4-a514-3c970e4a436a', namespace.metadata.uid)
15
15
  assert_equal('staging', namespace.metadata.name)
16
16
  assert_equal('1168', namespace.metadata.resourceVersion)
@@ -18,7 +18,7 @@ class TestNamespace < MiniTest::Test
18
18
  end
19
19
 
20
20
  def test_delete_namespace_v1beta3
21
- our_namespace = Namespace.new
21
+ our_namespace = Kubeclient::Namespace.new
22
22
  our_namespace.name = 'staging'
23
23
 
24
24
  stub_request(:delete, /\/namespaces/)