kubeclient 0.0.2 → 0.0.3

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
- MzllNTEwNTllM2YxMDVlNmU1MTc5MDZlZTA5NmNhYjNiZjc3MDFhMw==
4
+ NGJhNjYwNWQ1OThkODNjMGE3NmM5ODNmNGMxZDk3YjQ0MjA0Y2ExNA==
5
5
  data.tar.gz: !binary |-
6
- YWRhNWM3ZTgzZTVmNzFiOTM5MjU5NjllNGFjYzQxYjgyNTFiZjU3NA==
6
+ NGNjNTY1MjZiODZiOWY3YjQ5MDczYTg0YzVhMmUxZWJmNjZhM2U4Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDVhMDkzMzQ3NTJlMTU4ZDEzZTVkNDM3ZWFjNjcwYTU3N2NhN2E5NTI0MjIw
10
- NDBlN2FkNDVhMzFhMGFlY2IzMzAyZDNkNTU1ZmY2NTEyOGQ0ZWExYzc0ZWI2
11
- ZjQ5M2ZjMzlkMzBhMjQ4ZTYwN2JmZjI0OTdjOWQ2ZTMzZDg1OWY=
9
+ Y2Y3MjMwZDhhY2Q1N2Q1ZDc3ZDFiZmNhZTI5Y2ZhMzFjYjNhN2JkZDMyMzZj
10
+ OTIxYmNhZmE5NDViZTRiZWZkYjZmNWQxYWEzOTA3ZTljM2FlMTZhZmVkNjcw
11
+ YTI2NzkwMWZjNWUxZmY2ZDA1OTQ1MDU0ZmY1YzFkOWE3MDViMjQ=
12
12
  data.tar.gz: !binary |-
13
- MDAyMDAxYWM5YWI5N2RjMjI5NTYxMTI2YTA2MGNjNjExMzY5NzYxMjEzNWEx
14
- OTIxMmIwMzE2MWM0MDRjMDg2NTk3MjBiMmI1NzVkNzVhODI0Mzg0YzJmYjA5
15
- NGFjZGQ2MzY0NGZiNWRkZmIwN2NmYTgwNjg2N2I1ZjkwNTlkM2I=
13
+ ZjRiNTk5YzE3NTIwMmU2YmUzOWIzMjFmMWUxYzI4ZDQzNTdjNWUzNGY1M2Q5
14
+ Njc0MTY1Y2M0ZjJiMTY4NGE4ZTlkYTg1NjFhNjcwMzYxOGY3MTAzYjRjYzQ3
15
+ YTJlY2MyY2JiMWY1MzVlNWRlYTQ3ODU2NWNiMzZiMTIxNDExMzE=
data/lib/kubeclient.rb CHANGED
@@ -13,7 +13,7 @@ require 'kubeclient/kube_exception'
13
13
  module Kubeclient
14
14
  class Client
15
15
  attr_reader :api_endpoint
16
- entities = %w(Pod Service ReplicationController Node)
16
+ ENTITIES = %w(Pod Service ReplicationController Node)
17
17
 
18
18
  def initialize(api_endpoint,version)
19
19
  if !api_endpoint.end_with? "/"
@@ -27,7 +27,7 @@ module Kubeclient
27
27
  RestClient::Resource.new(@api_endpoint)
28
28
  end
29
29
 
30
- entities.each do |entity|
30
+ ENTITIES.each do |entity|
31
31
 
32
32
  #get all entities of a type e.g. get_nodes, get_pods, etc.
33
33
  define_method("get_#{entity.underscore.pluralize}") do |labels=nil|
@@ -127,5 +127,18 @@ module Kubeclient
127
127
  end
128
128
 
129
129
  end
130
+
131
+ public
132
+ def get_all_entities
133
+ result_hash = {}
134
+ ENTITIES.each do |entity|
135
+ #todo method call for get each entities
136
+ # build hash of entity name to array of the entities
137
+ method_name = "get_#{entity.underscore.pluralize}"
138
+ key_name = entity.underscore
139
+ result_hash[key_name] = self.method(method_name).call
140
+ end
141
+ result_hash
142
+ end
130
143
  end
131
144
  end
@@ -1,3 +1,3 @@
1
1
  module Kubeclient
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -95,6 +95,33 @@ class KubeClientTest < MiniTest::Test
95
95
  assert_instance_of(Service,services[1])
96
96
  end
97
97
 
98
+ def test_get_all
99
+ json_response_services = "{\n \"kind\": \"ServiceList\",\n \"creationTimestamp\": null,\n \"selfLink\": \"/api/v1beta1/services\",\n \"resourceVersion\": 8,\n \"apiVersion\": \"v1beta1\",\n \"items\": [\n {\n \"id\": \"kubernetes\",\n \"uid\": \"be10c0ba-8f4e-11e4-814c-3c970e4a436a\",\n \"creationTimestamp\": \"2014-12-29T13:35:08+02:00\",\n \"selfLink\": \"/api/v1beta1/services/kubernetes?namespace=default\",\n \"resourceVersion\": 4,\n \"namespace\": \"default\",\n \"port\": 443,\n \"protocol\": \"TCP\",\n \"labels\": {\n \"component\": \"apiserver\",\n \"provider\": \"kubernetes\"\n },\n \"selector\": null,\n \"containerPort\": 0,\n \"portalIP\": \"10.0.0.151\"\n },\n {\n \"id\": \"kubernetes-ro\",\n \"uid\": \"be106b89-8f4e-11e4-814c-3c970e4a436a\",\n \"creationTimestamp\": \"2014-12-29T13:35:08+02:00\",\n \"selfLink\": \"/api/v1beta1/services/kubernetes-ro?namespace=default\",\n \"resourceVersion\": 3,\n \"namespace\": \"default\",\n \"port\": 80,\n \"protocol\": \"TCP\",\n \"labels\": {\n \"component\": \"apiserver\",\n \"provider\": \"kubernetes\"\n },\n \"selector\": null,\n \"containerPort\": 0,\n \"portalIP\": \"10.0.0.171\"\n }\n ]\n}"
100
+ stub_request(:get, /.*services*/).
101
+ to_return(:body => json_response_services, :status => 200)
102
+ json_response_pods = "{\n \"kind\": \"PodList\", \n \"creationTimestamp\": null,\n \"selfLink\": \"/api/v1beta1/pods\",\n \"resourceVersion\": 7,\n \"apiVersion\": \"v1beta1\", \"items\": [] }"
103
+ stub_request(:get, /.*pods*/).
104
+ to_return(:body => json_response_pods, :status => 200)
105
+ json_response_nodes = "{\n \"kind\": \"NodeList\",\n \"creationTimestamp\": null, \n \"selfLink\": \"/api/v1beta1/nodes\",\n \"apiVersion\": \"v1beta1\",\n \"minions\": [ \n { \n \"id\": \"127.0.0.1\",\n \"uid\": \"a7b13504-9402-11e4-9a08-3c970e4a436a\",\n \"creationTimestamp\": \"2015-01-04T13:13:05+02:00\",\n \"selfLink\": \"/api/v1beta1/nodes/127.0.0.1\", \n \"resourceVersion\": 7,\n \"resources\": { \n \"capacity\": { \n \"cpu\": 1000,\n \"memory\": 3221225472 \n } } } ], \"items\": [ { \"id\": \"127.0.0.1\", \n \"uid\": \"a7b13504-9402-11e4-9a08-3c970e4a436a\", \n \"creationTimestamp\": \"2015-01-04T13:13:05+02:00\", \n \"selfLink\": \"/api/v1beta1/nodes/127.0.0.1\",\n \"resourceVersion\": 7,\n \"resources\": { \"capacity\": { \"cpu\": 1000, \"memory\": 3221225472 } } } ] }"
106
+ stub_request(:get, /.*nodes*/).
107
+ to_return(:body => json_response_nodes, :status => 200)
108
+
109
+ json_response_replication_controllers = "{ \"kind\": \"ReplicationControllerList\", \"creationTimestamp\": null, \"selfLink\": \"/api/v1beta1/replicationControllers\", \"resourceVersion\": 7, \"apiVersion\": \"v1beta1\", \"items\": [] }"
110
+ stub_request(:get, /.*replicationControllers*/).
111
+ to_return(:body => json_response_replication_controllers, :status => 200)
112
+
113
+
114
+ client = Kubeclient::Client.new 'http://localhost:8080/api/' , "v1beta1"
115
+ result = client.get_all_entities
116
+ assert_equal(4, result.keys.size)
117
+ assert_instance_of(EntityList, result["node"])
118
+ assert_instance_of(EntityList, result["service"])
119
+ assert_instance_of(EntityList, result["replication_controller"])
120
+ assert_instance_of(EntityList, result["pod"])
121
+ assert_instance_of(Service, result["service"][0])
122
+ assert_instance_of(Node, result["node"][0])
123
+ end
124
+
98
125
  #dup method creates a shallow copy which is not good in this case since rename_keys changes the input hash
99
126
  private
100
127
  def deep_copy(hash)
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alissa Bonas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-30 00:00:00.000000000 Z
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler