kubeclient 4.2.1 → 4.2.2

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
  SHA256:
3
- metadata.gz: 899369e46efd1bf4032090102865ed5cdac2a345e16ee61ac1aef5f4155edec4
4
- data.tar.gz: 00a58a06ec28e4c61483f728df95bdf7c687aa0a3ed82814461121d74a196633
3
+ metadata.gz: 9e11771dcb8f222f6c3a3bb4fb1c8b3db8cc745a9d2dbe8b2ff3edfe02382f3d
4
+ data.tar.gz: a5edd9efc28428fd2e5d232a1bdce0a1f5d0bd56fad06cff4d10e82e03bdc3f6
5
5
  SHA512:
6
- metadata.gz: d8483af344834c6dd7b8040776fb1ef6a31688c5520a414eef5c47719f541c47db96402b0da6fd5a7b675e2d76d166ee90acfdc0ba36f8c6dd4c3363cf8fb216
7
- data.tar.gz: f59b9016c41784d2bc5c6e23d294b4f6dfa00907d535bda173ac6d9b3d07ab106e6811b1a22741b7a40ff1cef3972f471cc0bdb9034846313e6b8959ac2731e3
6
+ metadata.gz: 17cdfd31bf3df9292a2edf052071e99b30e62ee6ebfd05bce7b710623cc7c0ae57acb1c469787cee49bd472dc1661d687908acbb364cc8d36723f7ee4b07d273
7
+ data.tar.gz: f739a8fc768a688853e2f6e55232087bdfbdc31b26a86ca6ffe6ecc87996b72906a2d60d674c5aae3d5023d578b5cc9d20611a349f1cfc0d2ee1d2511e4f4c7c
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.a
14
14
  mkmf.log
15
15
  *.idea*
16
+ /Gemfile.dev.rb
@@ -19,9 +19,11 @@ Metrics/ModuleLength:
19
19
  Style/MethodCallWithArgsParentheses:
20
20
  Enabled: true
21
21
  IgnoredMethods: [require, raise, include, attr_reader, refute, assert]
22
- Exclude: [Gemfile, Rakefile, kubeclient.gemspec]
22
+ Exclude: [Gemfile, Rakefile, kubeclient.gemspec, Gemfile.dev.rb]
23
23
  Security/MarshalLoad:
24
24
  Exclude: [test/**/*]
25
+ Style/FileName:
26
+ Exclude: [Gemfile, Rakefile, Gemfile.dev.rb]
25
27
  Style/MethodCallWithArgsParentheses:
26
28
  IgnoredMethods:
27
29
  - require_relative
@@ -4,6 +4,14 @@ Notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
5
5
  Kubeclient release versioning follows [SemVer](https://semver.org/).
6
6
 
7
+ ## 4.2.2 — 2019-01-09
8
+
9
+ ### Added
10
+ - New `http_max_redirects` option (#374).
11
+
12
+ ### Changed
13
+ - Default max redirects for watch increased from 4 to 10, to match other verbs (#374).
14
+
7
15
  ## 4.2.1 — 2018-12-26
8
16
 
9
17
  ### Fixed
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ dev_gemfile = File.expand_path('Gemfile.dev.rb', __dir__)
4
+ eval_gemfile(dev_gemfile) if File.exist?(dev_gemfile)
5
+
3
6
  # Specify your gem's dependencies in kubeclient.gemspec
4
7
  gemspec
data/README.md CHANGED
@@ -218,6 +218,15 @@ client = Kubeclient::Client.new(
218
218
  )
219
219
  ```
220
220
 
221
+ ### Redirects
222
+
223
+ You can optionally not allow redirection with kubeclient. For example:
224
+
225
+ ```ruby
226
+ client = Kubeclient::Client.new(
227
+ 'https://localhost:8443/api/', http_max_redirects: 0
228
+ )
229
+ ```
221
230
 
222
231
  ### Timeouts
223
232
 
@@ -34,6 +34,7 @@ module Kubeclient
34
34
  }.freeze
35
35
 
36
36
  DEFAULT_HTTP_PROXY_URI = nil
37
+ DEFAULT_HTTP_MAX_REDIRECTS = 10
37
38
 
38
39
  SEARCH_ARGUMENTS = {
39
40
  'labelSelector' => :label_selector,
@@ -52,6 +53,7 @@ module Kubeclient
52
53
  attr_reader :ssl_options
53
54
  attr_reader :auth_options
54
55
  attr_reader :http_proxy_uri
56
+ attr_reader :http_max_redirects
55
57
  attr_reader :headers
56
58
  attr_reader :discovered
57
59
 
@@ -64,6 +66,7 @@ module Kubeclient
64
66
  socket_options: DEFAULT_SOCKET_OPTIONS,
65
67
  timeouts: DEFAULT_TIMEOUTS,
66
68
  http_proxy_uri: DEFAULT_HTTP_PROXY_URI,
69
+ http_max_redirects: DEFAULT_HTTP_MAX_REDIRECTS,
67
70
  as: :ros
68
71
  )
69
72
  validate_auth_options(auth_options)
@@ -80,6 +83,7 @@ module Kubeclient
80
83
  # @timeouts[:foo] == nil resulting in infinite timeout.
81
84
  @timeouts = DEFAULT_TIMEOUTS.merge(timeouts)
82
85
  @http_proxy_uri = http_proxy_uri ? http_proxy_uri.to_s : nil
86
+ @http_max_redirects = http_max_redirects
83
87
  @as = as
84
88
 
85
89
  if auth_options[:bearer_token]
@@ -253,6 +257,7 @@ module Kubeclient
253
257
  ssl_client_cert: @ssl_options[:client_cert],
254
258
  ssl_client_key: @ssl_options[:client_key],
255
259
  proxy: @http_proxy_uri,
260
+ max_redirects: @http_max_redirects,
256
261
  user: @auth_options[:username],
257
262
  password: @auth_options[:password],
258
263
  open_timeout: @timeouts[:open],
@@ -573,7 +578,8 @@ module Kubeclient
573
578
  basic_auth_user: @auth_options[:username],
574
579
  basic_auth_password: @auth_options[:password],
575
580
  headers: @headers,
576
- http_proxy_uri: @http_proxy_uri
581
+ http_proxy_uri: @http_proxy_uri,
582
+ http_max_redirects: http_max_redirects
577
583
  }
578
584
 
579
585
  if uri.scheme == 'https'
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '4.2.1'.freeze
3
+ VERSION = '4.2.2'.freeze
4
4
  end
@@ -8,6 +8,7 @@ module Kubeclient
8
8
  @uri = uri
9
9
  @http_client = nil
10
10
  @http_options = http_options
11
+ @http_options[:http_max_redirects] ||= Kubeclient::Client::DEFAULT_HTTP_MAX_REDIRECTS
11
12
  @formatter = formatter
12
13
  end
13
14
 
@@ -38,15 +39,31 @@ module Kubeclient
38
39
 
39
40
  private
40
41
 
42
+ def max_hops
43
+ @http_options[:http_max_redirects] + 1
44
+ end
45
+
46
+ def follow_option
47
+ if max_hops > 1
48
+ { max_hops: max_hops }
49
+ else
50
+ # i.e. Do not follow redirects as we have set http_max_redirects to 0
51
+ # Setting `{ max_hops: 1 }` does not work FWIW
52
+ false
53
+ end
54
+ end
55
+
41
56
  def build_client
57
+ client = HTTP::Client.new(follow: follow_option)
58
+
42
59
  if @http_options[:basic_auth_user] && @http_options[:basic_auth_password]
43
- HTTP.basic_auth(
60
+ client = client.basic_auth(
44
61
  user: @http_options[:basic_auth_user],
45
62
  pass: @http_options[:basic_auth_password]
46
63
  )
47
- else
48
- HTTP::Client.new
49
64
  end
65
+
66
+ client
50
67
  end
51
68
 
52
69
  def using_proxy
@@ -54,6 +54,19 @@ class KubeclientTest < MiniTest::Test
54
54
  assert_equal(watch_client.send(:build_client_options)[:proxy][:proxy_port], proxy_uri.port)
55
55
  end
56
56
 
57
+ def test_pass_max_redirects
58
+ max_redirects = 0
59
+ client = Kubeclient::Client.new('http://localhost:8080/api/', http_max_redirects: max_redirects)
60
+ rest_client = client.rest_client
61
+ assert_equal(max_redirects, rest_client.options[:max_redirects])
62
+
63
+ stub_request(:get, 'http://localhost:8080/api')
64
+ .to_return(status: 302, headers: { location: 'http://localhost:1234/api' })
65
+
66
+ exception = assert_raises(Kubeclient::HttpError) { client.api }
67
+ assert_equal(302, exception.error_code)
68
+ end
69
+
57
70
  def test_exception
58
71
  stub_core_api_list
59
72
  stub_request(:post, %r{/services})
@@ -84,4 +84,40 @@ class TestPodLog < MiniTest::Test
84
84
  assert_equal(expected_lines[index], notice)
85
85
  end
86
86
  end
87
+
88
+ def test_watch_pod_log_follow_redirect
89
+ expected_lines = open_test_file('pod_log.txt').read.split("\n")
90
+ redirect = 'http://localhost:1234/api/namespaces/default/pods/redis-master-pod/log'
91
+
92
+ stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log\?.*follow})
93
+ .to_return(status: 302, headers: { location: redirect })
94
+
95
+ stub_request(:get, redirect)
96
+ .to_return(body: open_test_file('pod_log.txt'),
97
+ status: 200)
98
+
99
+ client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
100
+ stream = client.watch_pod_log('redis-master-pod', 'default')
101
+ stream.to_enum.with_index do |notice, index|
102
+ assert_instance_of(String, notice)
103
+ assert_equal(expected_lines[index], notice)
104
+ end
105
+ end
106
+
107
+ def test_watch_pod_log_max_redirect
108
+ redirect = 'http://localhost:1234/api/namespaces/default/pods/redis-master-pod/log'
109
+
110
+ stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log\?.*follow})
111
+ .to_return(status: 302, headers: { location: redirect })
112
+
113
+ stub_request(:get, redirect)
114
+ .to_return(body: open_test_file('pod_log.txt'),
115
+ status: 200)
116
+
117
+ client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1', http_max_redirects: 0)
118
+ assert_raises(Kubeclient::HttpError) do
119
+ client.watch_pod_log('redis-master-pod', 'default').each do
120
+ end
121
+ end
122
+ end
87
123
  end
@@ -53,6 +53,45 @@ class TestWatch < MiniTest::Test
53
53
  end
54
54
  end
55
55
 
56
+ def test_watch_pod_follow_redirect
57
+ stub_core_api_list
58
+
59
+ redirect = 'http://localhost:1234/api/v1/watch/pods'
60
+ stub_request(:get, %r{/watch/pods})
61
+ .to_return(status: 302, headers: { location: redirect })
62
+
63
+ stub_request(:get, redirect).to_return(
64
+ body: open_test_file('watch_stream.json'),
65
+ status: 200
66
+ )
67
+
68
+ client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
69
+
70
+ got = nil
71
+ client.watch_pods.each { |notice| got = notice }
72
+ assert_equal('DELETED', got.type)
73
+ end
74
+
75
+ def test_watch_pod_max_redirect
76
+ stub_core_api_list
77
+
78
+ redirect = 'http://localhost:1234/api/v1/watcher/pods'
79
+ stub_request(:get, %r{/watch/pods})
80
+ .to_return(status: 302, headers: { location: redirect })
81
+
82
+ stub_request(:get, redirect).to_return(
83
+ body: open_test_file('watch_stream.json'),
84
+ status: 200
85
+ )
86
+
87
+ client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1', http_max_redirects: 0)
88
+
89
+ assert_raises(Kubeclient::HttpError) do
90
+ client.watch_pods.each do
91
+ end
92
+ end
93
+ end
94
+
56
95
  # Ensure that WatchStream respects a format that's not JSON
57
96
  def test_watch_stream_text
58
97
  url = 'http://www.example.com/foobar'
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: 4.2.1
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alissa Bonas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-26 00:00:00.000000000 Z
11
+ date: 2019-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler