kubeclient 4.1.0 → 4.1.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: 648349cb119637758bb60353e75a42c7763f9a8926f57f692659de19c457ef2c
4
- data.tar.gz: ee020c04dcd67303cc7b2077d2ffbe570cd638f88b852dd5582b7daa9acb169b
3
+ metadata.gz: 6ac264e165704f976eae8ecab0b3106b021af071e38d7385fc88d5f12751d337
4
+ data.tar.gz: 963542f98fd9dbdba4dcf5ada66e1308250ee4521bb81851bb2b02d5621d9822
5
5
  SHA512:
6
- metadata.gz: 53a76a8f582b0d359f164c0f0bf1dc0cdfe863da4f49bf7abe171bcb49b06b60b389a1fed372be1748f512e6e4c6bd58731e52b2ff9b3a4ddac665a2573cb870
7
- data.tar.gz: d6337a1735a87f5410cacfedf0c69cd9e9c70d4eacc370bb7bf70eca2d61afc30801f3faa968f19c1204bd7484ec8cd43eddd02a986f9d73e70ac7016eb762f4
6
+ metadata.gz: 949fc44fb2c395ecd6fda5435953f74ae443968ca3d33b3dafdaa7724d5019d870cbcccc7e70c436a79a029e470ec5e383fd92926311c21eb074c71194c2c393
7
+ data.tar.gz: a1ec16df3211a8c10496462010c9900cf3f93c11b1acaa85de5dafcbb15e5ad4ace9c531dc40c1c3b104f5371eddca7c6c3d5298887097f66879a283e6d28f59
data/CHANGELOG.md CHANGED
@@ -4,7 +4,15 @@ 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.1.0 — 2018-11-28
7
+ ## 4.1.1 — 2018-12-17
8
+
9
+ ### Fixed
10
+
11
+ - Fixed method names for non-suffix plurals such as y -> ies (#377).
12
+
13
+ ## 4.1.0 — 2018-11-28 — REGRESSION
14
+
15
+ This version broke method names where plural is not just adding a suffix, notably y -> ies (bug #376).
8
16
 
9
17
  ### Fixed
10
18
  - Support custom resources with lowercase `kind` (#361).
@@ -33,7 +41,7 @@ Kubeclient release versioning follows [SemVer](https://semver.org/).
33
41
 
34
42
  ## 3.1.1 - 2018-06-01 — REGRESSION
35
43
 
36
- In this version `Kubeclient::Config.read` raises Psych::DisallowedClass on legal yaml configs containing a timestamp, for example gcp access-token expiry (#337).
44
+ In this version `Kubeclient::Config.read` raises Psych::DisallowedClass on legal yaml configs containing a timestamp, for example gcp access-token expiry (bug #337).
37
45
 
38
46
  ### Security
39
47
  - Changed `Kubeclient::Config.read` to use `YAML.safe_load` (#334).
@@ -132,13 +132,13 @@ module Kubeclient
132
132
  end
133
133
 
134
134
  def self.parse_definition(kind, name)
135
- # Kubernetes gives us have 3 inputs:
136
- # kind: "ComponentStatus"
137
- # name: "componentstatuses"
138
- # singularName: "componentstatus" (usually kind.downcase)
135
+ # Kubernetes gives us 3 inputs:
136
+ # kind: "ComponentStatus", "NetworkPolicy", "Endpoints"
137
+ # name: "componentstatuses", "networkpolicies", "endpoints"
138
+ # singularName: "componentstatus" etc (usually omitted, defaults to kind.downcase)
139
139
  # and want to derive singular and plural method names, with underscores:
140
- # "component_status"
141
- # "component_statuses"
140
+ # "network_policy"
141
+ # "network_policies"
142
142
  # kind's CamelCase word boundaries determine our placement of underscores.
143
143
 
144
144
  if IRREGULAR_NAMES[kind]
@@ -150,13 +150,22 @@ module Kubeclient
150
150
  # But how? If it differs from kind.downcase, kind's word boundaries don't apply.
151
151
  singular_name = kind.downcase
152
152
 
153
- if name.start_with?(kind.downcase)
154
- plural_suffix = name[kind.downcase.length..-1] # "es"
155
- singular_underscores = ClientMixin.underscore_entity(kind) # "component_status"
156
- method_names = [singular_underscores, singular_underscores + plural_suffix]
157
- else
158
- # Something weird, can't infer underscores for plural so just give them up
153
+ if !(/[A-Z]/ =~ kind)
154
+ # Some custom resources have a fully lowercase kind - can't infer underscores.
159
155
  method_names = [singular_name, name]
156
+ else
157
+ # Some plurals are not exact suffixes, e.g. NetworkPolicy -> networkpolicies.
158
+ # So don't expect full last word to match.
159
+ /^(?<prefix>(.*[A-Z]))(?<singular_suffix>[^A-Z]*)$/ =~ kind # "NetworkP", "olicy"
160
+ if name.start_with?(prefix.downcase)
161
+ plural_suffix = name[prefix.length..-1] # "olicies"
162
+ prefix_underscores = ClientMixin.underscore_entity(prefix) # "network_p"
163
+ method_names = [prefix_underscores + singular_suffix, # "network_policy"
164
+ prefix_underscores + plural_suffix] # "network_policies"
165
+ else
166
+ # Something weird, can't infer underscores for plural so just give them up
167
+ method_names = [singular_name, name]
168
+ end
160
169
  end
161
170
  end
162
171
 
@@ -507,6 +516,9 @@ module Kubeclient
507
516
  @entities = {}
508
517
  fetch_entities['resources'].each do |resource|
509
518
  next if resource['name'].include?('/')
519
+ # Not a regular entity, special functionality covered by `process_template`.
520
+ # https://github.com/openshift/origin/issues/21668
521
+ next if resource['kind'] == 'Template' && resource['name'] == 'processedtemplates'
510
522
  resource['kind'] ||=
511
523
  Kubeclient::Common::MissingKindCompatibility.resource_kind(resource['name'])
512
524
  entity = ClientMixin.parse_definition(resource['kind'], resource['name'])
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '4.1.0'.freeze
3
+ VERSION = '4.1.1'.freeze
4
4
  end
@@ -0,0 +1,217 @@
1
+ {
2
+ "kind": "APIResourceList",
3
+ "groupVersion": "extensions/v1beta1",
4
+ "resources": [
5
+ {
6
+ "name": "daemonsets",
7
+ "singularName": "",
8
+ "namespaced": true,
9
+ "kind": "DaemonSet",
10
+ "verbs": [
11
+ "create",
12
+ "delete",
13
+ "deletecollection",
14
+ "get",
15
+ "list",
16
+ "patch",
17
+ "update",
18
+ "watch"
19
+ ],
20
+ "shortNames": [
21
+ "ds"
22
+ ]
23
+ },
24
+ {
25
+ "name": "daemonsets/status",
26
+ "singularName": "",
27
+ "namespaced": true,
28
+ "kind": "DaemonSet",
29
+ "verbs": [
30
+ "get",
31
+ "patch",
32
+ "update"
33
+ ]
34
+ },
35
+ {
36
+ "name": "deployments",
37
+ "singularName": "",
38
+ "namespaced": true,
39
+ "kind": "Deployment",
40
+ "verbs": [
41
+ "create",
42
+ "delete",
43
+ "deletecollection",
44
+ "get",
45
+ "list",
46
+ "patch",
47
+ "update",
48
+ "watch"
49
+ ],
50
+ "shortNames": [
51
+ "deploy"
52
+ ]
53
+ },
54
+ {
55
+ "name": "deployments/rollback",
56
+ "singularName": "",
57
+ "namespaced": true,
58
+ "kind": "DeploymentRollback",
59
+ "verbs": [
60
+ "create"
61
+ ]
62
+ },
63
+ {
64
+ "name": "deployments/scale",
65
+ "singularName": "",
66
+ "namespaced": true,
67
+ "group": "extensions",
68
+ "version": "v1beta1",
69
+ "kind": "Scale",
70
+ "verbs": [
71
+ "get",
72
+ "patch",
73
+ "update"
74
+ ]
75
+ },
76
+ {
77
+ "name": "deployments/status",
78
+ "singularName": "",
79
+ "namespaced": true,
80
+ "kind": "Deployment",
81
+ "verbs": [
82
+ "get",
83
+ "patch",
84
+ "update"
85
+ ]
86
+ },
87
+ {
88
+ "name": "ingresses",
89
+ "singularName": "",
90
+ "namespaced": true,
91
+ "kind": "Ingress",
92
+ "verbs": [
93
+ "create",
94
+ "delete",
95
+ "deletecollection",
96
+ "get",
97
+ "list",
98
+ "patch",
99
+ "update",
100
+ "watch"
101
+ ],
102
+ "shortNames": [
103
+ "ing"
104
+ ]
105
+ },
106
+ {
107
+ "name": "ingresses/status",
108
+ "singularName": "",
109
+ "namespaced": true,
110
+ "kind": "Ingress",
111
+ "verbs": [
112
+ "get",
113
+ "patch",
114
+ "update"
115
+ ]
116
+ },
117
+ {
118
+ "name": "networkpolicies",
119
+ "singularName": "",
120
+ "namespaced": true,
121
+ "kind": "NetworkPolicy",
122
+ "verbs": [
123
+ "create",
124
+ "delete",
125
+ "deletecollection",
126
+ "get",
127
+ "list",
128
+ "patch",
129
+ "update",
130
+ "watch"
131
+ ],
132
+ "shortNames": [
133
+ "netpol"
134
+ ]
135
+ },
136
+ {
137
+ "name": "podsecuritypolicies",
138
+ "singularName": "",
139
+ "namespaced": false,
140
+ "kind": "PodSecurityPolicy",
141
+ "verbs": [
142
+ "create",
143
+ "delete",
144
+ "deletecollection",
145
+ "get",
146
+ "list",
147
+ "patch",
148
+ "update",
149
+ "watch"
150
+ ],
151
+ "shortNames": [
152
+ "psp"
153
+ ]
154
+ },
155
+ {
156
+ "name": "replicasets",
157
+ "singularName": "",
158
+ "namespaced": true,
159
+ "kind": "ReplicaSet",
160
+ "verbs": [
161
+ "create",
162
+ "delete",
163
+ "deletecollection",
164
+ "get",
165
+ "list",
166
+ "patch",
167
+ "update",
168
+ "watch"
169
+ ],
170
+ "shortNames": [
171
+ "rs"
172
+ ]
173
+ },
174
+ {
175
+ "name": "replicasets/scale",
176
+ "singularName": "",
177
+ "namespaced": true,
178
+ "group": "extensions",
179
+ "version": "v1beta1",
180
+ "kind": "Scale",
181
+ "verbs": [
182
+ "get",
183
+ "patch",
184
+ "update"
185
+ ]
186
+ },
187
+ {
188
+ "name": "replicasets/status",
189
+ "singularName": "",
190
+ "namespaced": true,
191
+ "kind": "ReplicaSet",
192
+ "verbs": [
193
+ "get",
194
+ "patch",
195
+ "update"
196
+ ]
197
+ },
198
+ {
199
+ "name": "replicationcontrollers",
200
+ "singularName": "",
201
+ "namespaced": true,
202
+ "kind": "ReplicationControllerDummy",
203
+ "verbs": []
204
+ },
205
+ {
206
+ "name": "replicationcontrollers/scale",
207
+ "singularName": "",
208
+ "namespaced": true,
209
+ "kind": "Scale",
210
+ "verbs": [
211
+ "get",
212
+ "patch",
213
+ "update"
214
+ ]
215
+ }
216
+ ]
217
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "apiVersion": "template.openshift.io/v1",
3
+ "kind": "Template",
4
+ "metadata": {
5
+ "creationTimestamp": "2018-12-17T16:11:36Z",
6
+ "name": "my-template",
7
+ "namespace": "default",
8
+ "resourceVersion": "21954",
9
+ "selfLink": "/apis/template.openshift.io/v1/namespaces/default/templates/my-template",
10
+ "uid": "6e03e3e6-0216-11e9-b1e0-68f728fac3ab"
11
+ },
12
+ "objects": [
13
+ {
14
+ "apiVersion": "v1",
15
+ "kind": "Service",
16
+ "metadata": {
17
+ "name": "${NAME_PREFIX}my-service"
18
+ }
19
+ }
20
+ ],
21
+ "parameters": [
22
+ {
23
+ "description": "Prefix for names",
24
+ "name": "NAME_PREFIX"
25
+ }
26
+ ]
27
+ }
@@ -0,0 +1,75 @@
1
+ {
2
+ "kind": "APIResourceList",
3
+ "apiVersion": "v1",
4
+ "groupVersion": "template.openshift.io/v1",
5
+ "resources": [
6
+ {
7
+ "name": "brokertemplateinstances",
8
+ "singularName": "",
9
+ "namespaced": false,
10
+ "kind": "BrokerTemplateInstance",
11
+ "verbs": [
12
+ "create",
13
+ "delete",
14
+ "deletecollection",
15
+ "get",
16
+ "list",
17
+ "patch",
18
+ "update",
19
+ "watch"
20
+ ]
21
+ },
22
+ {
23
+ "name": "processedtemplates",
24
+ "singularName": "",
25
+ "namespaced": true,
26
+ "kind": "Template",
27
+ "verbs": [
28
+ "create"
29
+ ]
30
+ },
31
+ {
32
+ "name": "templateinstances",
33
+ "singularName": "",
34
+ "namespaced": true,
35
+ "kind": "TemplateInstance",
36
+ "verbs": [
37
+ "create",
38
+ "delete",
39
+ "deletecollection",
40
+ "get",
41
+ "list",
42
+ "patch",
43
+ "update",
44
+ "watch"
45
+ ]
46
+ },
47
+ {
48
+ "name": "templateinstances/status",
49
+ "singularName": "",
50
+ "namespaced": true,
51
+ "kind": "TemplateInstance",
52
+ "verbs": [
53
+ "get",
54
+ "patch",
55
+ "update"
56
+ ]
57
+ },
58
+ {
59
+ "name": "templates",
60
+ "singularName": "",
61
+ "namespaced": true,
62
+ "kind": "Template",
63
+ "verbs": [
64
+ "create",
65
+ "delete",
66
+ "deletecollection",
67
+ "get",
68
+ "list",
69
+ "patch",
70
+ "update",
71
+ "watch"
72
+ ]
73
+ }
74
+ ]
75
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "kind": "TemplateList",
3
+ "apiVersion": "template.openshift.io/v1",
4
+ "metadata": {
5
+ "selfLink": "/apis/template.openshift.io/v1/namespaces/default/templates",
6
+ "resourceVersion": "22758"
7
+ },
8
+ "items": [
9
+ {
10
+ "metadata": {
11
+ "name": "my-template",
12
+ "namespace": "default",
13
+ "selfLink": "/apis/template.openshift.io/v1/namespaces/default/templates/my-template",
14
+ "uid": "6e03e3e6-0216-11e9-b1e0-68f728fac3ab",
15
+ "resourceVersion": "21954",
16
+ "creationTimestamp": "2018-12-17T16:11:36Z"
17
+ },
18
+ "objects": [
19
+ {
20
+ "apiVersion": "v1",
21
+ "kind": "Service",
22
+ "metadata": {
23
+ "name": "${NAME_PREFIX}my-service"
24
+ }
25
+ }
26
+ ],
27
+ "parameters": [
28
+ {
29
+ "name": "NAME_PREFIX",
30
+ "description": "Prefix for names"
31
+ }
32
+ ]
33
+ }
34
+ ]
35
+ }
data/test/test_common.rb CHANGED
@@ -74,4 +74,17 @@ class CommonTest < MiniTest::Test
74
74
  formatted = client.send(:format_datetime, value)
75
75
  assert_equal(formatted, '2018-04-30T19:20:33.000000000+00:00')
76
76
  end
77
+
78
+ def test_parse_definition_with_unconventional_names
79
+ %w[
80
+ PluralPolicy pluralpolicies plural_policy plural_policies
81
+ LatinDatum latindata latin_datum latin_data
82
+ Noseparator noseparators noseparator noseparators
83
+ lowercase lowercases lowercase lowercases
84
+ ].each_slice(4) do |kind, plural, expected_single, expected_plural|
85
+ method_names = Kubeclient::ClientMixin.parse_definition(kind, plural).method_names
86
+ assert_equal(method_names[0], expected_single)
87
+ assert_equal(method_names[1], expected_plural)
88
+ end
89
+ end
77
90
  end
@@ -41,6 +41,18 @@ class TestMissingMethods < MiniTest::Test
41
41
  end
42
42
  end
43
43
 
44
+ def test_nonsuffix_plurals
45
+ stub_request(:get, %r{/apis/extensions/v1beta1$}).to_return(
46
+ body: open_test_file('extensions_v1beta1_api_resource_list.json'),
47
+ status: 200
48
+ )
49
+ client = Kubeclient::Client.new('http://localhost:8080/apis/extensions', 'v1beta1')
50
+ assert_equal(true, client.respond_to?(:get_network_policy))
51
+ assert_equal(true, client.respond_to?(:get_network_policies))
52
+ assert_equal(true, client.respond_to?(:get_pod_security_policy))
53
+ assert_equal(true, client.respond_to?(:get_pod_security_policies))
54
+ end
55
+
44
56
  def test_irregular_names
45
57
  stub_core_api_list
46
58
  client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
@@ -41,4 +41,40 @@ class TestProcessTemplate < MiniTest::Test
41
41
  data['metadata']['namespace'] == 'default'
42
42
  end
43
43
  end
44
+
45
+ # Ensure _template and _templates methods hit `/templates` rather than
46
+ # `/processedtemplates` URL.
47
+ def test_templates_methods
48
+ stub_request(:get, %r{/apis/template\.openshift\.io/v1$}).to_return(
49
+ body: open_test_file('template.openshift.io_api_resource_list.json'),
50
+ status: 200
51
+ )
52
+ client = Kubeclient::Client.new('http://localhost:8080/apis/template.openshift.io', 'v1')
53
+
54
+ expected_url = 'http://localhost:8080/apis/template.openshift.io/v1/namespaces/default/templates'
55
+ stub_request(:get, expected_url)
56
+ .to_return(body: open_test_file('template_list.json'), status: 200)
57
+ client.get_templates(namespace: 'default')
58
+ assert_requested(:get, expected_url, times: 1)
59
+
60
+ expected_url = 'http://localhost:8080/apis/template.openshift.io/v1/namespaces/default/templates/my-template'
61
+ stub_request(:get, expected_url)
62
+ .to_return(body: open_test_file('template.json'), status: 200)
63
+ client.get_template('my-template', 'default')
64
+ assert_requested(:get, expected_url, times: 1)
65
+ end
66
+
67
+ def test_no_processedtemplates_methods
68
+ stub_request(:get, %r{/apis/template\.openshift\.io/v1$}).to_return(
69
+ body: open_test_file('template.openshift.io_api_resource_list.json'),
70
+ status: 200
71
+ )
72
+ client = Kubeclient::Client.new('http://localhost:8080/apis/template.openshift.io', 'v1')
73
+ client.discover
74
+
75
+ refute_respond_to(client, :get_processedtemplates)
76
+ refute_respond_to(client, :get_processedtemplate)
77
+ refute_respond_to(client, :get_processed_templates)
78
+ refute_respond_to(client, :get_processed_template)
79
+ end
44
80
  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.1.0
4
+ version: 4.1.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: 2018-11-28 00:00:00.000000000 Z
11
+ date: 2018-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -224,6 +224,7 @@ files:
224
224
  - test/json/endpoint_list.json
225
225
  - test/json/entity_list.json
226
226
  - test/json/event_list.json
227
+ - test/json/extensions_v1beta1_api_resource_list.json
227
228
  - test/json/limit_range.json
228
229
  - test/json/limit_range_list.json
229
230
  - test/json/namespace.json
@@ -258,6 +259,9 @@ files:
258
259
  - test/json/service_list.json
259
260
  - test/json/service_patch.json
260
261
  - test/json/service_update.json
262
+ - test/json/template.json
263
+ - test/json/template.openshift.io_api_resource_list.json
264
+ - test/json/template_list.json
261
265
  - test/json/versions_list.json
262
266
  - test/json/watch_stream.json
263
267
  - test/test_common.rb
@@ -338,6 +342,7 @@ test_files:
338
342
  - test/json/endpoint_list.json
339
343
  - test/json/entity_list.json
340
344
  - test/json/event_list.json
345
+ - test/json/extensions_v1beta1_api_resource_list.json
341
346
  - test/json/limit_range.json
342
347
  - test/json/limit_range_list.json
343
348
  - test/json/namespace.json
@@ -372,6 +377,9 @@ test_files:
372
377
  - test/json/service_list.json
373
378
  - test/json/service_patch.json
374
379
  - test/json/service_update.json
380
+ - test/json/template.json
381
+ - test/json/template.openshift.io_api_resource_list.json
382
+ - test/json/template_list.json
375
383
  - test/json/versions_list.json
376
384
  - test/json/watch_stream.json
377
385
  - test/test_common.rb