kubeclient 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8b9d95f0fd01cbb76accf474c6526a663f9c579
4
- data.tar.gz: d2304b7eff799c416993399a15f99de3e2e0a6c2
3
+ metadata.gz: cef89055e5f58a17421b6a66f2ad2f3d099a2f76
4
+ data.tar.gz: 01dcd7211472e9cf10df4ce73ea4eef569c24481
5
5
  SHA512:
6
- metadata.gz: d42a19e312327a1cfa9ade3a6a25a32f9fca63ddcfabcc66d5a888b528316aad59a014481198762eedd4499cbb57849dbbaddc3f68ef8044ed1851199072b9e5
7
- data.tar.gz: a1e5288ffbf0268e33b5494393b1f77274e8755a580c63c219b9cf57cf5c5a31b4415cff201e4aa0d4dbeac418b0d69b2c69c36791d7d57b37c73d479ab0a65e
6
+ metadata.gz: fff797cb134a26fd50e3265b1ba303fb5b22d7d02086b1c20c292e8277923f5fe0d3e74a824767bf2315a9644dc46b19da31929e5c04e866e9929b1b0f4d203d
7
+ data.tar.gz: c5c57ca8ffa4da1ca041053ba43191716caf17e2aa7307559c3406c3abacc85dfaf07102e0368adf8dbf8558e6bbd6177e474db52f572b259b879f10bf00f94c
data/.rubocop.yml CHANGED
@@ -4,3 +4,5 @@ ClassLength:
4
4
  Enabled: false
5
5
  Metrics/AbcSize:
6
6
  Enabled: false
7
+ Metrics/LineLength:
8
+ Max: 100
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Dependency Status](https://gemnasium.com/abonas/kubeclient.svg)](https://gemnasium.com/abonas/kubeclient)
7
7
 
8
8
  A Ruby client for Kubernetes REST api.
9
- The client supports GET, POST, PUT, DELETE on nodes, pods, secrets, services, replication controllers, namespaces and endpoints.
9
+ The client supports GET, POST, PUT, DELETE on nodes, pods, secrets, services, replication controllers, namespaces, resource quotas, limit ranges and endpoints.
10
10
  The client currently supports Kubernetes REST api version v1beta3.
11
11
 
12
12
  ## Installation
@@ -118,7 +118,7 @@ client = Kubeclient::Client.new 'https://localhost:8443/api/' , 'v1beta3',
118
118
  ## Examples:
119
119
 
120
120
  #### Get all instances of a specific entity type
121
- Such as: `get_pods`, `get_secrets`, `get_services`, `get_nodes`, `get_replication_controllers`
121
+ Such as: `get_pods`, `get_secrets`, `get_services`, `get_nodes`, `get_replication_controllers`, `get_resource_quotas`, `get_limit_ranges`
122
122
 
123
123
  ```ruby
124
124
  pods = client.get_pods
@@ -134,7 +134,7 @@ pods = client.get_pods(label_selector: 'name=redis-master,app=redis')
134
134
  ```
135
135
 
136
136
  #### Get a specific instance of an entity (by name)
137
- Such as: `get_service "service name"` , `get_pod "pod name"` , `get_replication_controller "rc name"`, `get_secret "secret name"`
137
+ Such as: `get_service "service name"` , `get_pod "pod name"` , `get_replication_controller "rc name"`, `get_secret "secret name"`, `get_resource_quota "resource quota name"`, `get_limit_range "limit range name"`
138
138
 
139
139
  The GET request should include the namespace name, except for nodes and namespaces entities.
140
140
 
@@ -159,7 +159,7 @@ client.delete_service "redis-service"
159
159
  ```
160
160
 
161
161
  #### Create an entity
162
- For example: `create_pod pod_object`, `create_replication_controller rc_obj`, `create_secret secret_object`
162
+ For example: `create_pod pod_object`, `create_replication_controller rc_obj`, `create_secret secret_object`, `create_resource_quota resource_quota_object`, `create_limit_range limit_range_object`
163
163
 
164
164
  Input parameter - object of type `Service`, `Pod`, `ReplicationController`.
165
165
 
@@ -177,9 +177,9 @@ client.create_service service`
177
177
  ```
178
178
 
179
179
  #### Update an entity
180
- For example: `update_pod`, `update_service`, `update_replication_controller`, `update_secret`
180
+ For example: `update_pod`, `update_service`, `update_replication_controller`, `update_secret`, `update_resource_quota`, `update_limit_range`
181
181
 
182
- Input parameter - object of type `Service`, `Pod`, `ReplicationController`
182
+ Input parameter - object of type `Pod`, `Service`, `ReplicationController` etc.
183
183
 
184
184
  The below example is for v1beta3
185
185
 
@@ -188,7 +188,7 @@ client.update_service service1
188
188
  ```
189
189
 
190
190
  #### Get all entities of all types : all_entities
191
- Returns a hash with 8 keys (node, secret, service, pod, replication_controller, namespace, endpoint and event). Each key points to an EntityList of same type.
191
+ Returns a hash with 10 keys (node, secret, service, pod, replication_controller, namespace, resource_quota, limit_range, endpoint and event). Each key points to an EntityList of same type.
192
192
 
193
193
  This method is a convenience method instead of calling each entity's get method separately.
194
194
 
data/lib/kubeclient.rb CHANGED
@@ -12,14 +12,13 @@ module Kubeclient
12
12
  # Kubernetes Client
13
13
  class Client < Common::Client
14
14
  attr_reader :api_endpoint
15
-
16
15
  # Dynamically creating classes definitions (class Pod, class Service, etc.),
17
16
  # The classes are extending RecursiveOpenStruct.
18
17
  # This cancels the need to define the classes
19
18
  # manually on every new entity addition,
20
19
  # and especially since currently the class body is empty
21
20
  ENTITY_TYPES = %w(Pod Service ReplicationController Node Event Endpoint
22
- Namespace Secret).map do |et|
21
+ Namespace Secret ResourceQuota LimitRange).map do |et|
23
22
  clazz = Class.new(RecursiveOpenStruct) do
24
23
  def initialize(hash = nil, args = {})
25
24
  args.merge!(recurse_over_arrays: true)
@@ -68,19 +67,6 @@ module Kubeclient
68
67
 
69
68
  private
70
69
 
71
- def validate_auth_options(opts)
72
- exclusive_keys = [:bearer_token, :bearer_token_file, :user]
73
-
74
- return if exclusive_keys.none? { |s| opts.key?(s) }
75
-
76
- msg = 'Invalid auth options: specify only one of user/password,' \
77
- ' bearer_token or bearer_token_file'
78
- fail ArgumentError, msg unless exclusive_keys.one? { |s| opts.key?(s) }
79
-
80
- msg = 'Basic auth requires both user & password'
81
- fail ArgumentError, msg if opts.key?(:user) && !opts.key?(:password)
82
- end
83
-
84
70
  def validate_bearer_token_file(bearer_token_file)
85
71
  msg = "Token file #{bearer_token_file} does not exist"
86
72
  fail ArgumentError, msg unless File.file?(bearer_token_file)
@@ -32,7 +32,7 @@ module Kubeclient
32
32
  def self.define_entity_methods(entity_types)
33
33
  entity_types.each do |klass, entity_type|
34
34
  entity_name = entity_type.underscore
35
- entity_name_plural = entity_name.pluralize
35
+ entity_name_plural = pluralize_entity(entity_name)
36
36
 
37
37
  # get all entities of a type e.g. get_nodes, get_pods, etc.
38
38
  define_method("get_#{entity_name_plural}") do |options = {}|
@@ -64,6 +64,11 @@ module Kubeclient
64
64
  end
65
65
  end
66
66
 
67
+ def self.pluralize_entity(entity_name)
68
+ return entity_name + 's' if entity_name.end_with? 'quota'
69
+ entity_name.pluralize
70
+ end
71
+
67
72
  def create_rest_client(path = nil)
68
73
  path ||= @api_endpoint.path
69
74
  options = {
@@ -192,14 +197,15 @@ module Kubeclient
192
197
  entity_types.each_with_object({}) do |(_, entity_type), result_hash|
193
198
  # method call for get each entities
194
199
  # build hash of entity name to array of the entities
195
- method_name = "get_#{entity_type.underscore.pluralize}"
200
+ entity_name = self.class.pluralize_entity entity_type.underscore
201
+ method_name = "get_#{entity_name}"
196
202
  key_name = entity_type.underscore
197
203
  result_hash[key_name] = send(method_name)
198
204
  end
199
205
  end
200
206
 
201
207
  def resource_name(entity_type)
202
- entity_type.pluralize.downcase
208
+ self.class.pluralize_entity entity_type.downcase
203
209
  end
204
210
 
205
211
  def api_valid?
@@ -220,6 +226,19 @@ module Kubeclient
220
226
  @headers ||= {}
221
227
  @headers[:Authorization] = "Bearer #{bearer_token}"
222
228
  end
229
+
230
+ def validate_auth_options(opts)
231
+ exclusive_keys = [:bearer_token, :bearer_token_file, :user]
232
+
233
+ return if exclusive_keys.none? { |s| opts.key?(s) }
234
+
235
+ msg = 'Invalid auth options: specify only one of user/password,' \
236
+ ' bearer_token or bearer_token_file'
237
+ fail ArgumentError, msg unless exclusive_keys.one? { |s| opts.key?(s) }
238
+
239
+ msg = 'Basic auth requires both user & password'
240
+ fail ArgumentError, msg if opts.key?(:user) && !opts.key?(:password)
241
+ end
223
242
  end
224
243
  end
225
244
  end
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
@@ -0,0 +1,23 @@
1
+ {
2
+ "kind": "LimitRange",
3
+ "apiVersion": "v1",
4
+ "metadata": {
5
+ "name": "limits",
6
+ "namespace": "quota-example",
7
+ "selfLink": "/api/v1/namespaces/quota-example/limitranges/limits",
8
+ "uid": "7a76a44c-3e9d-11e5-8214-0aaeec44370e",
9
+ "resourceVersion": "103384",
10
+ "creationTimestamp": "2015-08-09T13:49:39Z"
11
+ },
12
+ "spec": {
13
+ "limits": [
14
+ {
15
+ "type": "Container",
16
+ "default": {
17
+ "cpu": "100m",
18
+ "memory": "512Mi"
19
+ }
20
+ }
21
+ ]
22
+ }
23
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "kind": "LimitRangeList",
3
+ "apiVersion": "v1",
4
+ "metadata": {
5
+ "selfLink": "/api/v1/namespaces/quota-example/limitranges/",
6
+ "resourceVersion": "103421"
7
+ },
8
+ "items": [
9
+ {
10
+ "metadata": {
11
+ "name": "limits",
12
+ "namespace": "quota-example",
13
+ "selfLink": "/api/v1/namespaces/quota-example/limitranges/limits",
14
+ "uid": "7a76a44c-3e9d-11e5-8214-0aaeec44370e",
15
+ "resourceVersion": "103384",
16
+ "creationTimestamp": "2015-08-09T13:49:39Z"
17
+ },
18
+ "spec": {
19
+ "limits": [
20
+ {
21
+ "type": "Container",
22
+ "default": {
23
+ "cpu": "100m",
24
+ "memory": "512Mi"
25
+ }
26
+ }
27
+ ]
28
+ }
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,46 @@
1
+ {
2
+ "kind": "ResourceQuota",
3
+ "apiVersion": "v1",
4
+ "metadata": {
5
+ "name": "quota",
6
+ "namespace": "quota-example",
7
+ "selfLink": "/api/v1/namespaces/quota-example/resourcequotas/quota",
8
+ "uid": "ab9f24a4-3c43-11e5-8214-0aaeec44370e",
9
+ "resourceVersion": "12919",
10
+ "creationTimestamp": "2015-08-06T14:01:44Z"
11
+ },
12
+ "spec": {
13
+ "hard": {
14
+ "cpu": "20",
15
+ "memory": "1Gi",
16
+ "persistentvolumeclaims": "10",
17
+ "pods": "10",
18
+ "replicationcontrollers": "20",
19
+ "resourcequotas": "1",
20
+ "secrets": "10",
21
+ "services": "5"
22
+ }
23
+ },
24
+ "status": {
25
+ "hard": {
26
+ "cpu": "20",
27
+ "memory": "1Gi",
28
+ "persistentvolumeclaims": "10",
29
+ "pods": "10",
30
+ "replicationcontrollers": "20",
31
+ "resourcequotas": "1",
32
+ "secrets": "10",
33
+ "services": "5"
34
+ },
35
+ "used": {
36
+ "cpu": "0",
37
+ "memory": "0",
38
+ "persistentvolumeclaims": "0",
39
+ "pods": "0",
40
+ "replicationcontrollers": "1",
41
+ "resourcequotas": "1",
42
+ "secrets": "9",
43
+ "services": "0"
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,54 @@
1
+ {
2
+ "kind": "ResourceQuotaList",
3
+ "apiVersion": "v1",
4
+ "metadata": {
5
+ "selfLink": "/api/v1/namespaces/quota-example/resourcequotas/",
6
+ "resourceVersion": "102452"
7
+ },
8
+ "items": [
9
+ {
10
+ "metadata": {
11
+ "name": "quota",
12
+ "namespace": "quota-example",
13
+ "selfLink": "/api/v1/namespaces/quota-example/resourcequotas/quota",
14
+ "uid": "ab9f24a4-3c43-11e5-8214-0aaeec44370e",
15
+ "resourceVersion": "12919",
16
+ "creationTimestamp": "2015-08-06T14:01:44Z"
17
+ },
18
+ "spec": {
19
+ "hard": {
20
+ "cpu": "20",
21
+ "memory": "1Gi",
22
+ "persistentvolumeclaims": "10",
23
+ "pods": "10",
24
+ "replicationcontrollers": "20",
25
+ "resourcequotas": "1",
26
+ "secrets": "10",
27
+ "services": "5"
28
+ }
29
+ },
30
+ "status": {
31
+ "hard": {
32
+ "cpu": "20",
33
+ "memory": "1Gi",
34
+ "persistentvolumeclaims": "10",
35
+ "pods": "10",
36
+ "replicationcontrollers": "20",
37
+ "resourcequotas": "1",
38
+ "secrets": "10",
39
+ "services": "5"
40
+ },
41
+ "used": {
42
+ "cpu": "0",
43
+ "memory": "0",
44
+ "persistentvolumeclaims": "0",
45
+ "pods": "0",
46
+ "replicationcontrollers": "1",
47
+ "resourcequotas": "1",
48
+ "secrets": "9",
49
+ "services": "0"
50
+ }
51
+ }
52
+ }
53
+ ]
54
+ }
@@ -219,9 +219,17 @@ class KubeClientTest < MiniTest::Test
219
219
  .to_return(body: open_test_json_file('secret_list_b3.json'),
220
220
  status: 200)
221
221
 
222
+ stub_request(:get, %r{/resourcequotas})
223
+ .to_return(body: open_test_json_file('resource_quota_list.json'),
224
+ status: 200)
225
+
226
+ stub_request(:get, %r{/limitranges})
227
+ .to_return(body: open_test_json_file('limit_range_list.json'),
228
+ status: 200)
229
+
222
230
  client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
223
231
  result = client.all_entities
224
- assert_equal(8, result.keys.size)
232
+ assert_equal(10, result.keys.size)
225
233
  assert_instance_of(Kubeclient::Common::EntityList, result['node'])
226
234
  assert_instance_of(Kubeclient::Common::EntityList, result['service'])
227
235
  assert_instance_of(Kubeclient::Common::EntityList,
@@ -236,6 +244,8 @@ class KubeClientTest < MiniTest::Test
236
244
  assert_instance_of(Kubeclient::Endpoint, result['endpoint'][0])
237
245
  assert_instance_of(Kubeclient::Namespace, result['namespace'][0])
238
246
  assert_instance_of(Kubeclient::Secret, result['secret'][0])
247
+ assert_instance_of(Kubeclient::ResourceQuota, result['resource_quota'][0])
248
+ assert_instance_of(Kubeclient::LimitRange, result['limit_range'][0])
239
249
  end
240
250
 
241
251
  def test_api_bearer_token_with_params_success
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ # LimitRange tests
4
+ class TestLimitRange < MiniTest::Test
5
+ def test_get_from_json_v3
6
+ stub_request(:get, %r{/limitranges})
7
+ .to_return(body: open_test_json_file('limit_range.json'),
8
+ status: 200)
9
+
10
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
11
+ limit_range = client.get_limit_range 'limits', 'quota-example'
12
+
13
+ assert_instance_of(Kubeclient::LimitRange, limit_range)
14
+ assert_equal('limits', limit_range.metadata.name)
15
+ assert_equal('Container', limit_range.spec.limits[0].type)
16
+ assert_equal('100m', limit_range.spec.limits[0].default.cpu)
17
+ assert_equal('512Mi', limit_range.spec.limits[0].default.memory)
18
+
19
+ assert_requested(:get,
20
+ 'http://localhost:8080/api/v1/namespaces/quota-example/limitranges/limits',
21
+ times: 1)
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ # ResourceQuota tests
4
+ class TestResourceQuota < MiniTest::Test
5
+ def test_get_from_json_v3
6
+ stub_request(:get, %r{/resourcequotas})
7
+ .to_return(body: open_test_json_file('resource_quota.json'),
8
+ status: 200)
9
+
10
+ client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
11
+ quota = client.get_resource_quota 'quota', 'quota-example'
12
+
13
+ assert_instance_of(Kubeclient::ResourceQuota, quota)
14
+ assert_equal('quota', quota.metadata.name)
15
+ assert_equal('20', quota.spec.hard.cpu)
16
+ assert_equal('10', quota.spec.hard.secrets)
17
+
18
+ assert_requested(:get,
19
+ 'http://localhost:8080/api/v1/namespaces/quota-example/resourcequotas/quota',
20
+ times: 1)
21
+ end
22
+ end
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.3.0
4
+ version: 0.4.0
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-07-28 00:00:00.000000000 Z
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -165,6 +165,8 @@ files:
165
165
  - test/json/endpoint_list_b3.json
166
166
  - test/json/entity_list_b3.json
167
167
  - test/json/event_list_b3.json
168
+ - test/json/limit_range.json
169
+ - test/json/limit_range_list.json
168
170
  - test/json/namespace_b3.json
169
171
  - test/json/namespace_exception_b3.json
170
172
  - test/json/namespace_list_b3.json
@@ -174,6 +176,8 @@ files:
174
176
  - test/json/pod_list_b3.json
175
177
  - test/json/replication_controller_b3.json
176
178
  - test/json/replication_controller_list_b3.json
179
+ - test/json/resource_quota.json
180
+ - test/json/resource_quota_list.json
177
181
  - test/json/secret_list_b3.json
178
182
  - test/json/service_b3.json
179
183
  - test/json/service_illegal_json_404.json
@@ -183,10 +187,12 @@ files:
183
187
  - test/json/watch_stream_b3.json
184
188
  - test/test_helper.rb
185
189
  - test/test_kubeclient.rb
190
+ - test/test_limit_range.rb
186
191
  - test/test_namespace.rb
187
192
  - test/test_node.rb
188
193
  - test/test_pod.rb
189
194
  - test/test_replication_controller.rb
195
+ - test/test_resource_quota.rb
190
196
  - test/test_secret.rb
191
197
  - test/test_service.rb
192
198
  - test/test_watch.rb
@@ -223,6 +229,8 @@ test_files:
223
229
  - test/json/endpoint_list_b3.json
224
230
  - test/json/entity_list_b3.json
225
231
  - test/json/event_list_b3.json
232
+ - test/json/limit_range.json
233
+ - test/json/limit_range_list.json
226
234
  - test/json/namespace_b3.json
227
235
  - test/json/namespace_exception_b3.json
228
236
  - test/json/namespace_list_b3.json
@@ -232,6 +240,8 @@ test_files:
232
240
  - test/json/pod_list_b3.json
233
241
  - test/json/replication_controller_b3.json
234
242
  - test/json/replication_controller_list_b3.json
243
+ - test/json/resource_quota.json
244
+ - test/json/resource_quota_list.json
235
245
  - test/json/secret_list_b3.json
236
246
  - test/json/service_b3.json
237
247
  - test/json/service_illegal_json_404.json
@@ -241,10 +251,12 @@ test_files:
241
251
  - test/json/watch_stream_b3.json
242
252
  - test/test_helper.rb
243
253
  - test/test_kubeclient.rb
254
+ - test/test_limit_range.rb
244
255
  - test/test_namespace.rb
245
256
  - test/test_node.rb
246
257
  - test/test_pod.rb
247
258
  - test/test_replication_controller.rb
259
+ - test/test_resource_quota.rb
248
260
  - test/test_secret.rb
249
261
  - test/test_service.rb
250
262
  - test/test_watch.rb