kubeclient 4.9.0 → 4.9.1

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: 3c8f79b61300006829c55c6b13715e6073a1cf9517ad8334959ff64706bee4ca
4
- data.tar.gz: 04ae220b4f78422992e34538e5b47a0dbf0a832aa2eb9f1ac86d3f1c221cd088
3
+ metadata.gz: 1ea191875dc5c9e99d49152f6615caa50478bc8604a4de9c6fdda0d46da75ea5
4
+ data.tar.gz: 84214e5b1f2f3116aeb646828e0a5cf6456173493abf1fb384fe6132a723271d
5
5
  SHA512:
6
- metadata.gz: b7c9ab202ff3e30f5884fd2f80987fe87a3a65a86fa1a3ecdba16383cbb958fdb98f02dd48a00a5ac50fac828b335a33b33f634f7e2cbe7913883e5aa9a81fa4
7
- data.tar.gz: 52078faf6ec204c2b08658d83604fb84c7e68ad409d754ada7ae9d0d989fbce01ae53b2c33993dc71a6bed5851904fe22b6cd3688f67fa1c4bf9cd7704c43f71
6
+ metadata.gz: 549974ed0fbec82aa99df19db4829af4da21eec3ab037037c9a6880ab2b7f0bbf9a854ee9e1713a9eedccf6e7fafbc593301a8e67b745e54d88f9da158f6b596
7
+ data.tar.gz: 2f44720eca3c585e69c562b218f6e17c1ed0fb13dd5e26177fef6fa3ec610a6c0b1f056102ac3d3e3d9cf21801fe13d8560c509423838304cac0a40b66eedae8
@@ -4,6 +4,13 @@ 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.9.1 — 2020-08-31
8
+ ### Fixed
9
+ - Now should work with apiserver deployed not at root of domain but a sub-path,
10
+ which is standard with Rancher.
11
+ Notably, `create_...` methods were sending bad apiVersion and getting 400 error.
12
+ (#457, hopefully fixes #318, #418 and https://gitlab.com/gitlab-org/gitlab/-/issues/22043)
13
+
7
14
  ## 4.9.0 - 2020-08-03
8
15
  ### Added
9
16
  - Support for `user: exec` credential plugins using TLS client auth (#453)
@@ -194,10 +194,22 @@ module Kubeclient
194
194
  def handle_uri(uri, path)
195
195
  raise ArgumentError, 'Missing uri' unless uri
196
196
  @api_endpoint = (uri.is_a?(URI) ? uri : URI.parse(uri))
197
- @api_endpoint.path = path if @api_endpoint.path.empty?
198
- @api_endpoint.path = @api_endpoint.path.chop if @api_endpoint.path.end_with?('/')
199
- components = @api_endpoint.path.to_s.split('/') # ["", "api"] or ["", "apis", batch]
200
- @api_group = components.length > 2 ? components[2] + '/' : ''
197
+
198
+ # This regex will anchor at the last `/api`, `/oapi` or`/apis/:group`) part of the URL
199
+ # The whole path will be matched and if existing, the api_group will be extracted.
200
+ re = /^(?<path>.*\/o?api(?:s\/(?<apigroup>[^\/]+))?)$/mi
201
+ match = re.match(@api_endpoint.path.chomp('/'))
202
+
203
+ if match
204
+ # Since `re` captures 2 groups, match will always have 3 elements
205
+ # If thus we have a non-nil value in match 2, this is our api_group.
206
+ @api_group = match[:apigroup].nil? ? '' : match[:apigroup] + '/'
207
+ @api_endpoint.path = match[:path]
208
+ else
209
+ # This is a fallback, for when `/api` was not provided as part of the uri
210
+ @api_group = ''
211
+ @api_endpoint.path = @api_endpoint.path.chomp('/') + path
212
+ end
201
213
  end
202
214
 
203
215
  def build_namespace_prefix(namespace)
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '4.9.0'.freeze
3
+ VERSION = '4.9.1'.freeze
4
4
  end
@@ -0,0 +1,160 @@
1
+ require_relative 'test_helper'
2
+
3
+ # URLHandling tests
4
+ class TestCommonUrlHandling < MiniTest::Test
5
+ def test_no_path_in_uri
6
+ client = Kubeclient::Client.new('http://localhost:8080', 'v1')
7
+ rest_client = client.rest_client
8
+ assert_equal('v1', client.instance_variable_get(:@api_version))
9
+ assert_equal('', client.instance_variable_get(:@api_group))
10
+ assert_equal('http://localhost:8080/api/v1', rest_client.url.to_s)
11
+ end
12
+
13
+ def test_with_api_path_in_uri
14
+ client = Kubeclient::Client.new('http://localhost:8080/api', 'v1')
15
+ rest_client = client.rest_client
16
+ assert_equal('v1', client.instance_variable_get(:@api_version))
17
+ assert_equal('', client.instance_variable_get(:@api_group))
18
+ assert_equal('http://localhost:8080/api/v1', rest_client.url.to_s)
19
+ end
20
+
21
+ def test_with_api_path_in_uri_other_version
22
+ client = Kubeclient::Client.new('http://localhost:8080/api', 'v2')
23
+ rest_client = client.rest_client
24
+ assert_equal('v2', client.instance_variable_get(:@api_version))
25
+ assert_equal('', client.instance_variable_get(:@api_group))
26
+ assert_equal('http://localhost:8080/api/v2', rest_client.url.to_s)
27
+ end
28
+
29
+ def test_with_api_group_path_in_uri
30
+ client = Kubeclient::Client.new('http://localhost:8080/apis/this_is_the_group', 'v1')
31
+ rest_client = client.rest_client
32
+ assert_equal('v1', client.instance_variable_get(:@api_version))
33
+ assert_equal('this_is_the_group/', client.instance_variable_get(:@api_group))
34
+ assert_equal('http://localhost:8080/apis/this_is_the_group/v1', rest_client.url.to_s)
35
+ end
36
+
37
+ def test_with_api_group_path_in_uri_other_version
38
+ client = Kubeclient::Client.new('http://localhost:8080/apis/this_is_the_group', 'v2')
39
+ rest_client = client.rest_client
40
+ assert_equal('v2', client.instance_variable_get(:@api_version))
41
+ assert_equal('this_is_the_group/', client.instance_variable_get(:@api_group))
42
+ assert_equal('http://localhost:8080/apis/this_is_the_group/v2', rest_client.url.to_s)
43
+ end
44
+
45
+ def test_with_api_path_in_uri_trailing_slash
46
+ client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
47
+ rest_client = client.rest_client
48
+ assert_equal('v1', client.instance_variable_get(:@api_version))
49
+ assert_equal('', client.instance_variable_get(:@api_group))
50
+ assert_equal('http://localhost:8080/api/v1', rest_client.url.to_s)
51
+ end
52
+
53
+ def test_with_api_path_in_api
54
+ client = Kubeclient::Client.new('http://localhost:8080/api/but/I/want/a/hidden/k8s/api', 'v1')
55
+ rest_client = client.rest_client
56
+ assert_equal('v1', client.instance_variable_get(:@api_version))
57
+ assert_equal('', client.instance_variable_get(:@api_group))
58
+ assert_equal('http://localhost:8080/api/but/I/want/a/hidden/k8s/api/v1', rest_client.url.to_s)
59
+ end
60
+
61
+ def test_with_api_group_path_in_api
62
+ client = Kubeclient::Client.new(
63
+ 'http://localhost:8080/api/but/I/want/a/hidden/k8s/apis/this_is_the_group',
64
+ 'v1'
65
+ )
66
+ rest_client = client.rest_client
67
+ assert_equal('v1', client.instance_variable_get(:@api_version))
68
+ assert_equal('this_is_the_group/', client.instance_variable_get(:@api_group))
69
+ assert_equal(
70
+ 'http://localhost:8080/api/but/I/want/a/hidden/k8s/apis/this_is_the_group/v1',
71
+ rest_client.url.to_s
72
+ )
73
+ end
74
+
75
+ def test_rancher_with_api_path_in_uri
76
+ client = Kubeclient::Client.new('http://localhost:8080/k8s/clusters/c-somerancherID/api', 'v1')
77
+ rest_client = client.rest_client
78
+ assert_equal('v1', client.instance_variable_get(:@api_version))
79
+ assert_equal('', client.instance_variable_get(:@api_group))
80
+ assert_equal('http://localhost:8080/k8s/clusters/c-somerancherID/api/v1', rest_client.url.to_s)
81
+ end
82
+
83
+ def test_rancher_no_api_path_in_uri
84
+ client = Kubeclient::Client.new('http://localhost:8080/k8s/clusters/c-somerancherID', 'v1')
85
+ rest_client = client.rest_client
86
+ assert_equal('v1', client.instance_variable_get(:@api_version))
87
+ assert_equal('', client.instance_variable_get(:@api_group))
88
+ assert_equal('http://localhost:8080/k8s/clusters/c-somerancherID/api/v1', rest_client.url.to_s)
89
+ end
90
+
91
+ def test_rancher_no_api_path_in_uri_trailing_slash
92
+ client = Kubeclient::Client.new('http://localhost:8080/k8s/clusters/c-somerancherID/', 'v1')
93
+ rest_client = client.rest_client
94
+ assert_equal('v1', client.instance_variable_get(:@api_version))
95
+ assert_equal('', client.instance_variable_get(:@api_group))
96
+ assert_equal('http://localhost:8080/k8s/clusters/c-somerancherID/api/v1', rest_client.url.to_s)
97
+ end
98
+
99
+ def test_rancher_with_api_path_in_uri_trailing_slash
100
+ client = Kubeclient::Client.new('http://localhost:8080/k8s/clusters/c-somerancherID/api/', 'v1')
101
+ rest_client = client.rest_client
102
+ assert_equal('v1', client.instance_variable_get(:@api_version))
103
+ assert_equal('', client.instance_variable_get(:@api_group))
104
+ assert_equal('http://localhost:8080/k8s/clusters/c-somerancherID/api/v1', rest_client.url.to_s)
105
+ end
106
+
107
+ def test_rancher_with_api_group_in_uri_trailing_slash
108
+ client = Kubeclient::Client.new(
109
+ 'http://localhost:8080/k8s/clusters/c-somerancherID/apis/this_is_the_group',
110
+ 'v1'
111
+ )
112
+ rest_client = client.rest_client
113
+ assert_equal('v1', client.instance_variable_get(:@api_version))
114
+ assert_equal('this_is_the_group/', client.instance_variable_get(:@api_group))
115
+ assert_equal(
116
+ 'http://localhost:8080/k8s/clusters/c-somerancherID/apis/this_is_the_group/v1',
117
+ rest_client.url.to_s
118
+ )
119
+ end
120
+
121
+ def test_with_openshift_api_path_in_uri
122
+ client = Kubeclient::Client.new('http://localhost:8080/oapi', 'v1')
123
+ rest_client = client.rest_client
124
+ assert_equal('v1', client.instance_variable_get(:@api_version))
125
+ assert_equal('', client.instance_variable_get(:@api_group))
126
+ assert_equal('http://localhost:8080/oapi/v1', rest_client.url.to_s)
127
+ end
128
+
129
+ def test_arbitrary_path_with_openshift_api_path_in_uri
130
+ client = Kubeclient::Client.new('http://localhost:8080/foobarbaz/oapi', 'v1')
131
+ rest_client = client.rest_client
132
+ assert_equal('v1', client.instance_variable_get(:@api_version))
133
+ assert_equal('', client.instance_variable_get(:@api_group))
134
+ assert_equal('http://localhost:8080/foobarbaz/oapi/v1', rest_client.url.to_s)
135
+ end
136
+
137
+ def test_with_openshift_api_path_in_uri_trailing_slash
138
+ client = Kubeclient::Client.new('http://localhost:8080/oapi/', 'v1')
139
+ rest_client = client.rest_client
140
+ assert_equal('v1', client.instance_variable_get(:@api_version))
141
+ assert_equal('', client.instance_variable_get(:@api_group))
142
+ assert_equal('http://localhost:8080/oapi/v1', rest_client.url.to_s)
143
+ end
144
+
145
+ def test_with_arbitrary_path_in_uri
146
+ client = Kubeclient::Client.new('http://localhost:8080/foobarbaz', 'v1')
147
+ rest_client = client.rest_client
148
+ assert_equal('v1', client.instance_variable_get(:@api_version))
149
+ assert_equal('', client.instance_variable_get(:@api_group))
150
+ assert_equal('http://localhost:8080/foobarbaz/api/v1', rest_client.url.to_s)
151
+ end
152
+
153
+ def test_with_arbitrary_and_api_path_in_uri
154
+ client = Kubeclient::Client.new('http://localhost:8080/foobarbaz/api', 'v1')
155
+ rest_client = client.rest_client
156
+ assert_equal('v1', client.instance_variable_get(:@api_version))
157
+ assert_equal('', client.instance_variable_get(:@api_group))
158
+ assert_equal('http://localhost:8080/foobarbaz/api/v1', rest_client.url.to_s)
159
+ end
160
+ 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: 4.9.0
4
+ version: 4.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alissa Bonas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-03 00:00:00.000000000 Z
11
+ date: 2020-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -324,6 +324,7 @@ files:
324
324
  - test/json/versions_list.json
325
325
  - test/json/watch_stream.json
326
326
  - test/test_common.rb
327
+ - test/test_common_url_handling.rb
327
328
  - test/test_component_status.rb
328
329
  - test/test_config.rb
329
330
  - test/test_endpoint.rb
@@ -450,6 +451,7 @@ test_files:
450
451
  - test/json/versions_list.json
451
452
  - test/json/watch_stream.json
452
453
  - test/test_common.rb
454
+ - test/test_common_url_handling.rb
453
455
  - test/test_component_status.rb
454
456
  - test/test_config.rb
455
457
  - test/test_endpoint.rb