kubeclient 0.1.16 → 0.1.17

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: 06875bb69db97a971297a9623c7dddc960311aa7
4
- data.tar.gz: e6fabf77ca3e62b6bbe8a4de5046bdbcacf4c91a
3
+ metadata.gz: d22e1e45425956eb53bd9177f30d99985689a53f
4
+ data.tar.gz: 2027dcdc5c43ba8920792de49c5b35ead7e98e64
5
5
  SHA512:
6
- metadata.gz: cd8718be9eeff6a72038e92aade155552a4199ef13d7c8adbf94a4b4e828fee49098cfbf2fa69b997957ad138ec78d358c684036598c5118bd62d5d562c572ef
7
- data.tar.gz: 6a257ee339f7268225e66e671401e54cc7c9179e31f3f44374a648d8eb5005e8c1fb4b2a746628bb5ab396f9b3bb4a43053472858533a0bd775093128d9ef282
6
+ metadata.gz: e71f71efb21a87e7184ddc2415f950d82d931bfc2b02bac01af66c87b1a97afd8bad320918fcc602e80c710ebae67d411542686c1b6bb7e67cf8b77d126f52ac
7
+ data.tar.gz: 4f0a8c4b33a3871ec3a8c0f9e4f8de1628b9bf6dc9ce0fc12c23865037ec74e8cc47f7f6feb110370bbcc4c2c0eb1409e04f78fdfeda01a8482d381051d5f449
data/README.md CHANGED
@@ -69,12 +69,14 @@ If you are using basic authentication or bearer tokens as described
69
69
  of the following:
70
70
 
71
71
  ```ruby
72
- client.bearer_token('MDExMWJkMjItOWY1Ny00OGM5LWJlNDEtMjBiMzgxODkxYzYz')
72
+ client.basic_auth('username', 'password')
73
73
  ```
74
+
74
75
  <br>
75
76
  or <br>
77
+
76
78
  ```ruby
77
- client.basic_auth('username', 'password')
79
+ client.bearer_token('MDExMWJkMjItOWY1Ny00OGM5LWJlNDEtMjBiMzgxODkxYzYz')
78
80
  ```
79
81
 
80
82
  If you are running your app using kubeclient inside a Kubernetes cluster, then you can have a bearer token file
@@ -86,8 +88,8 @@ for more details).
86
88
 
87
89
  ## Examples:
88
90
 
89
- #### Get all pods
90
- And respectively: `get_services`, `get_nodes`, `get_replication_controllers`
91
+ #### Get all instances of a specific entity type
92
+ Such as: `get_pods`, `get_services`, `get_nodes`, `get_replication_controllers`
91
93
 
92
94
  ```ruby
93
95
  pods = client.get_pods
@@ -102,8 +104,8 @@ You can specify multiple labels (that option will return entities which have bot
102
104
  pods = client.get_pods(label_selector: 'name=redis-master,app=redis')
103
105
  ```
104
106
 
105
- #### Get a specific node
106
- And respectively: `get_service "service name"` , `get_pod "pod name"` , `get_replication_controller "rc name"`
107
+ #### Get a specific instance of an entity (by name)
108
+ Such as: `get_service "service name"` , `get_pod "pod name"` , `get_replication_controller "rc name"`
107
109
 
108
110
  The GET request should include the namespace name, except for nodes and namespaces entities.
109
111
 
@@ -118,17 +120,17 @@ service = client.get_service "guestbook", 'development'
118
120
  Note - Kubernetes doesn't work with the uid, but rather with the 'name' property.
119
121
  Querying with uid causes 404.
120
122
 
121
- #### Delete a service
123
+ #### Delete an entity (by name)
122
124
 
123
- And respectively `delete_pod "pod id"` , `delete_replication_controller "rc id"`, `delete node "node id"`
125
+ For example: `delete_pod "pod name"` , `delete_replication_controller "rc name"`, `delete node "node name"`
124
126
 
125
- Input parameter - id (string) specifying service id, pod id, replication controller id.
127
+ Input parameter - name (string) specifying service name, pod name, replication controller name.
126
128
  ```ruby
127
129
  client.delete_service "redis-service"
128
130
  ```
129
131
 
130
- #### Create a service
131
- And respectively: `create_pod pod_object`, `create_replication_controller rc_obj`
132
+ #### Create an entity
133
+ For example: `create_pod pod_object`, `create_replication_controller rc_obj`
132
134
 
133
135
  Input parameter - object of type `Service`, `Pod`, `ReplicationController`.
134
136
 
@@ -145,8 +147,8 @@ service.spec.selector.role = "master"
145
147
  client.create_service service`
146
148
  ```
147
149
 
148
- #### Update entity
149
- And respectively `update_pod`, `update_service`, `update_replication_controller`
150
+ #### Update an entity
151
+ For example: `update_pod`, `update_service`, `update_replication_controller`
150
152
 
151
153
  Input parameter - object of type `Service`, `Pod`, `ReplicationController`
152
154
 
@@ -156,7 +158,7 @@ The below example is for v1beta3
156
158
  client.update_service service1
157
159
  ```
158
160
 
159
- #### all_entities
161
+ #### Get all entities of all types : all_entities
160
162
  Returns a hash with 7 keys (node, service, pod, replication_controller, namespace, endpoint and event). Each key points to an EntityList of same type.
161
163
 
162
164
  This method is a convenience method instead of calling each entity's get method separately.
data/lib/kubeclient.rb CHANGED
@@ -32,6 +32,7 @@ module Kubeclient
32
32
  def initialize(uri, version = 'v1beta3')
33
33
  handle_uri(uri, '/api')
34
34
  @api_version = version
35
+ @headers = {}
35
36
  ssl_options
36
37
  end
37
38
 
@@ -71,7 +71,6 @@ module Kubeclient
71
71
  verify_ssl: @ssl_options[:verify_ssl],
72
72
  ssl_client_cert: @ssl_options[:client_cert],
73
73
  ssl_client_key: @ssl_options[:client_key],
74
- bearer_token: @bearer_token,
75
74
  user: @basic_auth_user,
76
75
  password: @basic_auth_password
77
76
  }
@@ -102,9 +101,9 @@ module Kubeclient
102
101
  verify_mode: @ssl_options[:verify_ssl],
103
102
  cert: @ssl_options[:client_cert],
104
103
  key: @ssl_options[:client_key],
105
- bearer_token: @bearer_token,
106
104
  basic_auth_user: @basic_auth_user,
107
- basic_auth_password: @basic_auth_password
105
+ basic_auth_password: @basic_auth_password,
106
+ headers: @headers
108
107
  }
109
108
 
110
109
  WatchStream.new(uri, options)
@@ -113,12 +112,13 @@ module Kubeclient
113
112
  def get_entities(entity_type, klass, options)
114
113
  params = {}
115
114
  if options[:label_selector]
116
- params['labelSelector'] = options[:label_selector]
115
+ params['params'] = { labelSelector: options[:label_selector] }
117
116
  end
118
117
 
119
118
  # TODO: namespace support?
120
119
  response = handle_exception do
121
- rest_client[resource_name(entity_type)].get(params: params)
120
+ rest_client[resource_name(entity_type)]
121
+ .get(params.merge(@headers))
122
122
  end
123
123
 
124
124
  result = JSON.parse(response)
@@ -137,7 +137,8 @@ module Kubeclient
137
137
  def get_entity(entity_type, klass, name, namespace = nil)
138
138
  ns_prefix = build_namespace_prefix(namespace)
139
139
  response = handle_exception do
140
- rest_client[ns_prefix + resource_name(entity_type) + "/#{name}"].get
140
+ rest_client[ns_prefix + resource_name(entity_type) + "/#{name}"]
141
+ .get(@headers)
141
142
  end
142
143
  result = JSON.parse(response)
143
144
  new_entity(result, klass)
@@ -147,7 +148,7 @@ module Kubeclient
147
148
  ns_prefix = build_namespace_prefix(namespace)
148
149
  handle_exception do
149
150
  rest_client[ns_prefix + resource_name(entity_type) + "/#{name}"]
150
- .delete
151
+ .delete(@headers)
151
152
  end
152
153
  end
153
154
 
@@ -164,7 +165,8 @@ module Kubeclient
164
165
  hash['kind'] = entity_type
165
166
  hash['apiVersion'] = @api_version
166
167
  response = handle_exception do
167
- rest_client[ns_prefix + resource_name(entity_type)].post(hash.to_json)
168
+ rest_client[ns_prefix + resource_name(entity_type)]
169
+ .post(hash.to_json, @headers)
168
170
  end
169
171
  result = JSON.parse(response)
170
172
  new_entity(result, klass)
@@ -178,7 +180,7 @@ module Kubeclient
178
180
  ns_prefix = build_namespace_prefix(entity_config.metadata.namespace)
179
181
  handle_exception do
180
182
  rest_client[ns_prefix + resource_name(entity_type) + "/#{name}"]
181
- .put(hash.to_json)
183
+ .put(hash.to_json, @headers)
182
184
  end
183
185
  end
184
186
 
@@ -207,7 +209,7 @@ module Kubeclient
207
209
 
208
210
  def api
209
211
  response = handle_exception do
210
- create_rest_client.get
212
+ create_rest_client.get(@headers)
211
213
  end
212
214
  JSON.parse(response)
213
215
  end
@@ -223,10 +225,8 @@ module Kubeclient
223
225
  end
224
226
 
225
227
  def bearer_token(bearer_token)
226
- @bearer_token = bearer_token
227
- RestClient.add_before_execution_proc do |req|
228
- req['authorization'] = "Bearer #{@bearer_token}"
229
- end
228
+ @headers ||= {}
229
+ @headers[:Authorization] = "Bearer #{bearer_token}"
230
230
  end
231
231
 
232
232
  def basic_auth(user, password)
@@ -1,5 +1,5 @@
1
1
  # Kubernetes HTTP Exceptions
2
- class KubeException < Exception
2
+ class KubeException < StandardError
3
3
  attr_reader :error_code, :message
4
4
 
5
5
  def initialize(error_code, message)
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '0.1.16'
3
+ VERSION = '0.1.17'
4
4
  end
@@ -39,8 +39,8 @@ module Kubeclient
39
39
  @options[:basic_auth_password]
40
40
  end
41
41
 
42
- if @options[:bearer_token]
43
- request['authorization'] = "Bearer #{@options[:bearer_token]}"
42
+ @options[:headers].each do |header, value|
43
+ request[header] = value
44
44
  end
45
45
  request
46
46
  end
@@ -232,6 +232,21 @@ class KubeClientTest < MiniTest::Test
232
232
  assert_instance_of(Kubeclient::Namespace, result['namespace'][0])
233
233
  end
234
234
 
235
+ def test_api_bearer_token_with_params_success
236
+ stub_request(:get, 'http://localhost:8080/api/v1beta3/pods?labelSelector=name=redis-master')
237
+ .with(headers: { Authorization: 'Bearer valid_token' })
238
+ .to_return(body: open_test_json_file('pod_list_b3.json'),
239
+ status: 200)
240
+
241
+ client = Kubeclient::Client.new 'http://localhost:8080/api/'
242
+ client.bearer_token('valid_token')
243
+
244
+ pods = client.get_pods(label_selector: 'name=redis-master')
245
+
246
+ assert_equal('Pod', pods.kind)
247
+ assert_equal(1, pods.size)
248
+ end
249
+
235
250
  def test_api_bearer_token_success
236
251
  stub_request(:get, 'http://localhost:8080/api/v1beta3/pods')
237
252
  .with(headers: { Authorization: 'Bearer valid_token' })
@@ -245,7 +260,6 @@ class KubeClientTest < MiniTest::Test
245
260
 
246
261
  assert_equal('Pod', pods.kind)
247
262
  assert_equal(1, pods.size)
248
- RestClient.reset_before_execution_procs
249
263
  end
250
264
 
251
265
  def test_api_bearer_token_failure
@@ -262,7 +276,6 @@ class KubeClientTest < MiniTest::Test
262
276
  exception = assert_raises(KubeException) { client.get_pods }
263
277
  assert_equal(403, exception.error_code)
264
278
  assert_equal(error_message, exception.message)
265
- RestClient.reset_before_execution_procs
266
279
  end
267
280
 
268
281
  def test_api_basic_auth_success
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.1.16
4
+ version: 0.1.17
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-05-19 00:00:00.000000000 Z
11
+ date: 2015-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler