kubeclient 0.0.6 → 0.0.7

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGU0ZWMzMDI2NTkyM2E2OWJjNjg3ZGM3ZmNkZDBkZmYyNmI5YTYzNg==
4
+ NmEwNzNiNzUyOWYxZDFlYzE2M2Q4MDY1MjdhMDIwNjM5YmFkZDMzNQ==
5
5
  data.tar.gz: !binary |-
6
- Yzc4YzNkMDA5MWM2OGQ0ZjlmNTUzNjQ0NDc0NzJmYjdiNjRhZjEwNA==
6
+ Mzc5MGZlMWI5OWMxNWU5YjI4OGEwODBjM2ExNzkxMzBhNGY4ZDYyNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjFhN2QzNDg3YTkwZWFkYTA1MzQ4OGJiYjk5ZDBkZTM3NjBjMzBjOWQyYzZj
10
- ZDY1NmUyOTVhYTBlMjVhZDE3MzdhYWU1ZDYxZTEzNjU3YmIwMDg0YmE4NTQ1
11
- N2RhNmYzZDJkMzdlMTc4ZTYwNmYyMDM0ZTg2OGY1MTVjYThmMzM=
9
+ NGQzYjU2ZTQ3NGMyNWFiMmM5OTc4MTdhNWMxMDAzZDFiNTIyZTUzMTk1N2Zi
10
+ NGQxNTUyMGI4N2VkYjI0NGFhYTJjMDIwNmRmOThiNjkzOGRiYjRhOGMxNjdj
11
+ NTBlOWQ2MDNlMWNiN2NmNzZiMmE3OGJmNTQ2ZWMyNmE3ZjJiMTY=
12
12
  data.tar.gz: !binary |-
13
- YzU5MDAwZGU1MTEyMTU0YmE3MmZhYTlkZmRmYTYzNGRiNzEzNjViN2YyN2Q0
14
- YzlmMWMwZGNiNGE1ZGIyOTc2OGM2YzFlNWJlNTZlNTlkNDk5ZDVhNTBiMzI2
15
- NTg1NjhhN2VkNGVjNTRhMmJiYTMxNzhmODBhODhkODQzY2QyNDk=
13
+ Y2JhZmZhM2U5NzViZDgzMzgyODc5YzRlNzQ0MzgwODU4NmUyNDNkYjNmYjg3
14
+ MjFlNTYzNzU2Nzg3MmM3MjA0ZTA1MTliNWE1ZWRhYzZkZThlNzdmYmJkYTJh
15
+ MWFkYWJmZjkzM2FiM2NkZGQzMzhiMGVhOWRmZTMxMDYzZDlkYjQ=
data/lib/kubeclient.rb CHANGED
@@ -28,6 +28,14 @@ module Kubeclient
28
28
  RestClient::Resource.new(@api_endpoint)
29
29
  end
30
30
 
31
+ protected
32
+ def create_entity(hash, entity, method_name)
33
+ entity.classify.constantize.new(hash)
34
+ end
35
+
36
+
37
+ public
38
+
31
39
  ENTITIES.each do |entity|
32
40
 
33
41
  #get all entities of a type e.g. get_nodes, get_pods, etc.
@@ -58,33 +66,6 @@ module Kubeclient
58
66
  create_entity(result, entity, "underscore")
59
67
  end
60
68
 
61
- protected
62
- def create_entity(hash, entity, method_name)
63
- rename_keys(hash,method_name, nil)
64
- entity.classify.constantize.new(hash)
65
- end
66
-
67
- #recursively rename the keys in hash including
68
- #nested hashes to/from ruby style
69
- protected
70
- def rename_keys(hash, method_name, method_param)
71
- hash.keys.each { |key|
72
- method_object = key.to_s.method(method_name)
73
- if method_param != nil
74
- new_key = method_object.call(method_param)
75
- else
76
- new_key = method_object.call
77
- end
78
- hash[new_key] = hash[key]
79
- hash.delete(key) unless new_key == key
80
-
81
- #recursive call to take care of values that are hashes themselves
82
- if hash[new_key].is_a?(Hash) then rename_keys(hash[new_key],method_name, method_param) end
83
-
84
- }
85
- hash
86
- end
87
-
88
69
  define_method("delete_#{entity.underscore}") do |id|
89
70
  begin
90
71
  rest_client[entity.underscore.pluralize+"/" +id].delete
@@ -98,8 +79,6 @@ module Kubeclient
98
79
  define_method("create_#{entity.underscore}") do |entity_config|
99
80
  #to_hash should be called because of issue #9 in recursive open struct
100
81
  hash = entity_config.to_hash
101
- #keys should be renamed from underscore to k8s json naming style (camelized w first word lowercase)
102
- hash = rename_keys(hash, "camelize", :lower)
103
82
  begin
104
83
  rest_client[entity.pluralize.camelize(:lower)].post(hash.to_json)
105
84
  rescue RestClient::Exception => e
@@ -114,8 +93,6 @@ module Kubeclient
114
93
  hash = entity_config.to_hash
115
94
  #temporary solution to delete id till this issue is solved: https://github.com/GoogleCloudPlatform/kubernetes/issues/3085
116
95
  hash.delete(:id)
117
- #keys should be renamed from underscore to k8s json naming style (camelized w first word lowercase)
118
- hash = rename_keys(hash, "camelize", :lower)
119
96
  begin
120
97
  rest_client[entity.underscore.pluralize+"/#{id}"].put(hash.to_json)
121
98
  rescue RestClient::Exception => e
@@ -134,7 +111,7 @@ module Kubeclient
134
111
  # build hash of entity name to array of the entities
135
112
  method_name = "get_#{entity.underscore.pluralize}"
136
113
  key_name = entity.underscore
137
- result_hash[key_name] = self.method(method_name).call
114
+ result_hash[key_name] = send(method_name)
138
115
  end
139
116
  result_hash
140
117
  end
@@ -1,3 +1,3 @@
1
1
  module Kubeclient
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -2,51 +2,10 @@ require 'minitest/autorun'
2
2
  require 'json'
3
3
  require 'webmock/minitest'
4
4
  require './lib/kubeclient'
5
- require './test/kubeclient'
6
5
 
7
6
 
8
7
  class KubeClientTest < MiniTest::Test
9
8
 
10
- def test_renaming_keys
11
- json_response = "{\n \"kind\": \"Node\",\n \"id\": \"127.0.0.1\",\n \"uid\": \"b0ddfa00-8b5b-11e4-a8c4-3c970e4a436a\",\n \"creationTimestamp\": \"2014-12-24T12:57:45+02:00\",\n \"selfLink\": \"/api/v1beta1/nodes/127.0.0.1\",\n \"resourceVersion\": 7,\n \"apiVersion\": \"v1beta1\",\n \"resources\": {\n \"capacity\": {\n \"cpu\": 1000,\n \"memory\": 3221225472\n }\n }\n}"
12
- stub_request(:get, /.*nodes*/).
13
- to_return(:body => json_response, :status => 200)
14
-
15
- client = Kubeclient::Client.new 'http://localhost:8080/api/' , "v1beta1"
16
- original_hash = JSON.parse(json_response)
17
- #convert to ruby style
18
- hash_after_rename_underscore = client.rename_keys(deep_copy(original_hash),"underscore", nil)
19
- #convert back to camelized style with first word downcase
20
- hash_after_rename_camelize = client.rename_keys(deep_copy(hash_after_rename_underscore), "camelize", :lower)
21
-
22
- assert_equal(original_hash, hash_after_rename_camelize)
23
- assert_equal(7,hash_after_rename_camelize["resourceVersion"])
24
- assert_equal(7,hash_after_rename_underscore["resource_version"])
25
- assert_equal(nil, hash_after_rename_underscore["resourceVersion"])
26
-
27
-
28
- end
29
-
30
- #testing that keys renaming works on deeper level
31
- #the json doesn't necessarily represent a valid k8s entity , it's for testing renaming purposes
32
- def test_renaming_keys_deep
33
- json_response = "{\n \"kind\": \"Node\",\n \"id\": \"127.0.0.1\",\n \"uid\": \"b0ddfa00-8b5b-11e4-a8c4-3c970e4a436a\",\n \"creationTimestamp\": \"2014-12-24T12:57:45+02:00\",\n \"selfLink\": \"/api/v1beta1/nodes/127.0.0.1\",\n \"resourceVersion\": 7,\n \"apiVersion\": \"v1beta1\",\n \"hostResources\": {\n \"capacity\": {\n \"cpu\": 1000,\n \"memorySize\": 3221225472\n }\n }\n}"
34
- stub_request(:get, /.*nodes*/).
35
- to_return(:body => json_response, :status => 200)
36
-
37
- client = Kubeclient::Client.new 'http://localhost:8080/api/' , "v1beta1"
38
- original_hash = JSON.parse(json_response)
39
- #convert to ruby style
40
- hash_after_rename_underscore = client.rename_keys(deep_copy(original_hash),"underscore", nil)
41
- #convert back to camelized style with first word downcase
42
- hash_after_rename_camelize = client.rename_keys(deep_copy(hash_after_rename_underscore), "camelize", :lower)
43
-
44
- assert_equal(original_hash, hash_after_rename_camelize)
45
- assert_equal(3221225472,hash_after_rename_camelize["hostResources"]["capacity"]["memorySize"])
46
- assert_equal(nil,hash_after_rename_underscore["host_resources"]["capacity"]["memorySize"])
47
- assert_equal(3221225472,hash_after_rename_underscore["host_resources"]["capacity"]["memory_size"])
48
- end
49
-
50
9
  def test_json
51
10
  our_object = Service.new
52
11
  our_object.foo = 'bar'
data/test/node_test.rb CHANGED
@@ -16,14 +16,14 @@ class NodeTest < MiniTest::Test
16
16
 
17
17
  assert_instance_of(Node,node)
18
18
  #checking that creationTimestamp was renamed properly
19
- assert_respond_to(node, "creation_timestamp")
19
+ assert_respond_to(node, "creationTimestamp")
20
20
  assert_respond_to(node, "uid")
21
21
  assert_respond_to(node, "id")
22
22
  assert_respond_to(node, "resources")
23
- assert_respond_to(node, "resource_version")
24
- assert_respond_to(node, "api_version")
23
+ assert_respond_to(node, "resourceVersion")
24
+ assert_respond_to(node, "apiVersion")
25
25
 
26
- assert_equal 7, node.resource_version
26
+ assert_equal 7, node.resourceVersion
27
27
  assert_equal 1000, node.resources.capacity.cpu
28
28
  end
29
29
 
data/test/pod_test.rb CHANGED
@@ -18,7 +18,7 @@ class PodTest < MiniTest::Test
18
18
 
19
19
  assert_instance_of(Pod,pod)
20
20
  assert_equal("redis-master-pod",pod.id)
21
- assert_equal("redis-master",pod.desired_state.manifest.containers[0]['name'])
21
+ assert_equal("redis-master",pod.desiredState.manifest.containers[0]['name'])
22
22
  end
23
23
 
24
24
  end
@@ -18,10 +18,10 @@ class ReplicationControllerTest < MiniTest::Test
18
18
  assert_equal("frontendController",rc.id)
19
19
  assert_equal("f4e5966c-8eb2-11e4-a6e7-3c970e4a436a",rc.uid)
20
20
  assert_equal("default",rc.namespace)
21
- assert_equal(3,rc.desired_state.replicas)
22
- assert_equal("frontend",rc.desired_state.replica_selector.name)
21
+ assert_equal(3,rc.desiredState.replicas)
22
+ assert_equal("frontend",rc.desiredState.replicaSelector.name)
23
23
  #the access to containers is not as nice as rest of the properties, but it's about to change in beta v3,
24
24
  #hence it can significantly impact the design of the client. to be revisited after beta v3 api is released.
25
- assert_equal("php-redis",rc.desired_state.pod_template.desired_state.manifest.containers[0]['name'])
25
+ assert_equal("php-redis",rc.desiredState.podTemplate.desiredState.manifest.containers[0]['name'])
26
26
  end
27
27
  end
data/test/service_test.rb CHANGED
@@ -42,13 +42,13 @@ class ServiceTest < MiniTest::Test
42
42
 
43
43
  assert_instance_of(Service,service)
44
44
  #checking that creationTimestamp was renamed properly
45
- assert_equal("2014-12-28T17:37:21+02:00",service.creation_timestamp)
45
+ assert_equal("2014-12-28T17:37:21+02:00",service.creationTimestamp)
46
46
  assert_equal("6a022e83-8ea7-11e4-a6e7-3c970e4a436a",service.uid)
47
47
  assert_equal("redisslave",service.id)
48
- assert_equal(8,service.resource_version)
49
- assert_equal("v1beta1",service.api_version)
50
- assert_equal("10.0.0.248",service.portal_ip)
51
- assert_equal(6379,service.container_port)
48
+ assert_equal(8,service.resourceVersion)
49
+ assert_equal("v1beta1",service.apiVersion)
50
+ assert_equal("10.0.0.248",service.portalIP)
51
+ assert_equal(6379,service.containerPort)
52
52
  assert_equal("TCP",service.protocol)
53
53
  assert_equal(10001,service.port)
54
54
  assert_equal("default",service.namespace)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubeclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alissa Bonas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-13 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,7 +143,6 @@ files:
143
143
  - lib/kubeclient/replication_controller.rb
144
144
  - lib/kubeclient/service.rb
145
145
  - lib/kubeclient/version.rb
146
- - test/kubeclient.rb
147
146
  - test/kubeclient_test.rb
148
147
  - test/node_test.rb
149
148
  - test/pod_test.rb
@@ -174,7 +173,6 @@ signing_key:
174
173
  specification_version: 4
175
174
  summary: A client for Kubernetes REST api
176
175
  test_files:
177
- - test/kubeclient.rb
178
176
  - test/kubeclient_test.rb
179
177
  - test/node_test.rb
180
178
  - test/pod_test.rb
data/test/kubeclient.rb DELETED
@@ -1,6 +0,0 @@
1
- module Kubeclient
2
- #using this in order to test a protected method
3
- class Client
4
- public :rename_keys
5
- end
6
- end