kubeclient 1.0.0 → 1.1.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: f0dac688d6eb0963960c817696dfbd9b8f75da98
4
- data.tar.gz: 8a5be4b58833b3f9e8d84c2bb8721e53ec2db180
3
+ metadata.gz: 780e4ae994bf298d7316518d27110c3a336820c5
4
+ data.tar.gz: fabcc8d9f9f7900495f9dd75d8e15b3d41b34db8
5
5
  SHA512:
6
- metadata.gz: 5d63b1408a1788f5327377abf95d4312b086858030b18388ffd550420a05a237eb2551f579018aa573617782249cda5de2df8a6645d2806e7b86002de9507e1e
7
- data.tar.gz: 08803875c6d0d1ecb7b4e18dcf066801a325725855579d6b89ff4249638c5aa98485ed6e42012eae5fdda8d1039e96e34cb74811ef745ef2af3ade5cb5abc776
6
+ metadata.gz: dc85e7d93e8a3a042830d67ceb852ba3c946fec3636d69151382f8d5abafac415567d36ca82453ec3aca6c12df5e25d32dcde82cd2bfd4e5d27a2752bde50503
7
+ data.tar.gz: 9b029e85c7b33b2d606c39cf87204c0c418e2e79acc613e8262bed142e06297aa6945352667ea72f3a9ec0c75f03ba9750e221ec540fadea227f7c0913239712
data/.rubocop.yml CHANGED
@@ -6,3 +6,5 @@ Metrics/AbcSize:
6
6
  Enabled: false
7
7
  Metrics/LineLength:
8
8
  Max: 100
9
+ Metrics/ParameterLists:
10
+ Max: 8
data/README.md CHANGED
@@ -122,12 +122,24 @@ for more details). For example:
122
122
  ```ruby
123
123
  auth_options = {
124
124
  bearer_token_file: '/var/run/secrets/kubernetes.io/serviceaccount/token'
125
-
126
125
  }
127
126
  client = Kubeclient::Client.new 'https://localhost:8443/api/' , 'v1',
128
127
  auth_options: auth_options
129
128
  ```
130
129
 
130
+ You can also use kubeclient with non-blocking sockets such as Celluloid::IO, see [here](https://github.com/httprb/http/wiki/Parallel-requests-with-Celluloid%3A%3AIO)
131
+ for details. For example:
132
+
133
+ ```ruby
134
+ require 'celluloid/io'
135
+ socket_options = {
136
+ socket_class: Celluloid::IO::TCPSocket,
137
+ ssl_socket_class: Celluloid::IO::SSLSocket
138
+ }
139
+ client = Kubeclient::Client.new 'https://localhost:8443/api/' , 'v1',
140
+ socket_options: socket_options
141
+ ```
142
+
131
143
  ## Examples:
132
144
 
133
145
  #### Get all instances of a specific entity type
data/kubeclient.gemspec CHANGED
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency 'activesupport'
30
30
  spec.add_dependency 'json'
31
31
  spec.add_dependency 'recursive-open-struct', '= 1.0.0'
32
+ spec.add_dependency 'http', '= 0.9.8'
32
33
  end
@@ -24,6 +24,10 @@ module Kubeclient
24
24
  password: nil,
25
25
  bearer_token: nil,
26
26
  bearer_token_file: nil
27
+ },
28
+ socket_options: {
29
+ socket_class: nil,
30
+ ssl_socket_class: nil
27
31
  }
28
32
  )
29
33
  validate_auth_options(auth_options)
@@ -33,12 +37,13 @@ module Kubeclient
33
37
  @headers = {}
34
38
  @ssl_options = ssl_options
35
39
  @auth_options = auth_options
40
+ @socket_options = socket_options
36
41
 
37
42
  if auth_options[:bearer_token]
38
- @headers[:Authorization] = "Bearer #{@auth_options[:bearer_token]}"
43
+ bearer_token(@auth_options[:bearer_token])
39
44
  elsif auth_options[:bearer_token_file]
40
45
  validate_bearer_token_file
41
- @headers[:Authorization] = "Bearer #{File.read(@auth_options[:bearer_token_file])}"
46
+ bearer_token(File.read(@auth_options[:bearer_token_file]))
42
47
  end
43
48
  end
44
49
 
@@ -150,7 +155,7 @@ module Kubeclient
150
155
  uri.query = URI.encode_www_form(params.map { |k, v| [k.to_s.camelize(:lower), v] })
151
156
  end
152
157
 
153
- Kubeclient::Common::WatchStream.new(uri, net_http_options(uri))
158
+ Kubeclient::Common::WatchStream.new(uri, http_options(uri))
154
159
  end
155
160
 
156
161
  # Accepts the following string options:
@@ -272,7 +277,7 @@ module Kubeclient
272
277
  uri.path += "/#{@api_version}/#{ns}pods/#{pod_name}/log"
273
278
  uri.query = URI.encode_www_form(params)
274
279
 
275
- Kubeclient::Common::WatchStream.new(uri, net_http_options(uri), format: :text)
280
+ Kubeclient::Common::WatchStream.new(uri, http_options(uri), format: :text)
276
281
  end
277
282
 
278
283
  def proxy_url(kind, name, port, namespace = '')
@@ -329,7 +334,7 @@ module Kubeclient
329
334
  fail ArgumentError, msg unless File.readable?(@auth_options[:bearer_token_file])
330
335
  end
331
336
 
332
- def net_http_options(uri)
337
+ def http_options(uri)
333
338
  options = {
334
339
  basic_auth_user: @auth_options[:username],
335
340
  basic_auth_password: @auth_options[:password],
@@ -337,19 +342,18 @@ module Kubeclient
337
342
  }
338
343
 
339
344
  if uri.scheme == 'https'
340
- options.merge!(
341
- use_ssl: true,
345
+ options[:ssl] = {
342
346
  ca_file: @ssl_options[:ca_file],
343
347
  cert: @ssl_options[:client_cert],
344
348
  cert_store: @ssl_options[:cert_store],
345
349
  key: @ssl_options[:client_key],
346
- # ruby Net::HTTP uses verify_mode instead of verify_ssl
347
- # http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html
350
+ # ruby HTTP uses verify_mode instead of verify_ssl
351
+ # http://ruby-doc.org/stdlib-1.9.3/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html
348
352
  verify_mode: @ssl_options[:verify_ssl]
349
- )
353
+ }
350
354
  end
351
355
 
352
- options
356
+ options.merge(@socket_options)
353
357
  end
354
358
  end
355
359
  end
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
@@ -1,54 +1,63 @@
1
1
  require 'json'
2
- require 'net/http'
2
+ require 'http'
3
3
  module Kubeclient
4
4
  module Common
5
5
  # HTTP Stream used to watch changes on entities
6
6
  class WatchStream
7
7
  def initialize(uri, http_options, format: :json)
8
8
  @uri = uri
9
- @http = nil
10
- @http_options = http_options.merge(read_timeout: nil)
9
+ @http_client = nil
10
+ @http_options = http_options
11
11
  @format = format
12
12
  end
13
13
 
14
14
  def each
15
15
  @finished = false
16
- @http = Net::HTTP.start(@uri.host, @uri.port, @http_options)
17
16
 
18
- buffer = ''
19
- request = generate_request
17
+ @http_client = build_client
18
+ response = @http_client.request(:get, @uri, build_client_options)
19
+ unless response.code < 300
20
+ fail KubeException.new(response.code, response.reason, response)
21
+ end
20
22
 
21
- @http.request(request) do |response|
22
- unless response.is_a? Net::HTTPSuccess
23
- fail KubeException.new(response.code, response.message, response)
24
- end
25
- response.read_body do |chunk|
26
- buffer << chunk
27
- while (line = buffer.slice!(/.+\n/))
28
- yield @format == :json ? WatchNotice.new(JSON.parse(line)) : line.chomp
29
- end
23
+ buffer = ''
24
+ response.body.each do |chunk|
25
+ buffer << chunk
26
+ while (line = buffer.slice!(/.+\n/))
27
+ yield @format == :json ? WatchNotice.new(JSON.parse(line)) : line.chomp
30
28
  end
31
29
  end
32
- rescue Errno::EBADF
30
+ rescue IOError
33
31
  raise unless @finished
34
32
  end
35
33
 
36
- def generate_request
37
- request = Net::HTTP::Get.new(@uri)
38
- if @http_options[:basic_auth_user] && @http_options[:basic_auth_password]
39
- request.basic_auth @http_options[:basic_auth_user],
40
- @http_options[:basic_auth_password]
41
- end
34
+ def finish
35
+ @finished = true
36
+ @http_client.close unless @http_client.nil?
37
+ end
42
38
 
43
- @http_options.fetch(:headers, {}).each do |header, value|
44
- request[header.to_s] = value
39
+ private
40
+
41
+ def build_client
42
+ if @http_options[:basic_auth_user] && @http_options[:basic_auth_password]
43
+ HTTP.basic_auth(user: @http_options[:basic_auth_user],
44
+ pass: @http_options[:basic_auth_password])
45
+ else
46
+ HTTP::Client.new
45
47
  end
46
- request
47
48
  end
48
49
 
49
- def finish
50
- @finished = true
51
- @http.finish if !@http.nil? && @http.started?
50
+ def build_client_options
51
+ client_options = { headers: @http_options[:headers] }
52
+ if @http_options[:ssl]
53
+ client_options[:ssl] = @http_options[:ssl]
54
+ client_options[:ssl_socket_class] =
55
+ @http_options[:ssl_socket_class] if @http_options[:ssl_socket_class]
56
+ else
57
+ client_options[:socket_class] =
58
+ @http_options[:socket_class] if @http_options[:socket_class]
59
+ end
60
+ client_options
52
61
  end
53
62
  end
54
63
  end
data/lib/kubeclient.rb CHANGED
@@ -45,9 +45,14 @@ module Kubeclient
45
45
  password: nil,
46
46
  bearer_token: nil,
47
47
  bearer_token_file: nil
48
+ },
49
+ socket_options: {
50
+ socket_class: nil,
51
+ ssl_socket_class: nil
48
52
  }
49
53
  )
50
- initialize_client(uri, '/api', version, ssl_options: ssl_options, auth_options: auth_options)
54
+ initialize_client(uri, '/api', version, ssl_options: ssl_options, auth_options: auth_options,
55
+ socket_options: socket_options)
51
56
  end
52
57
 
53
58
  def all_entities
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: 1.0.0
4
+ version: 1.1.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: 2016-01-05 00:00:00.000000000 Z
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
152
  version: 1.0.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: http
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 0.9.8
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 0.9.8
153
167
  description: A client for Kubernetes REST api
154
168
  email:
155
169
  - abonas@redhat.com