kubeclient 2.2.0 → 2.3.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: 330f8bdcaf1a4801ed016ed7b1757d098e3bf63e
4
- data.tar.gz: 621396f5f5eaa61bbdcaffb81ad0362757069b90
3
+ metadata.gz: 3f4032a685c46d5955f63ffcc006171bddc30e09
4
+ data.tar.gz: 005aee870fc479f06d43d8a38aaf15f938b076dd
5
5
  SHA512:
6
- metadata.gz: c8bdec91c30c2a4ed392a0678520a77dda6ca995c7b701ac80d66f6a48bd47017a5b4ef159c52e874dc494b8720b9626b258c92209c7bbee08a521b8f9a1d2f8
7
- data.tar.gz: f31eead48ac19a797a8764437dc6010ffb9472035a144c37cfeec6465d900ad3af4a76f15f993c1495d670f27747eb4abec968a3d4b79ce1e0bbba735d90e20b
6
+ metadata.gz: 3ba975b163f88ac63f41cddddbc4e5e59b4ac4272cc4a223e7bfb718145ac92441bdbdaf5c46faf06fc1c506bbda0043a908f0082f823c10618729148ff70d24
7
+ data.tar.gz: 3a50235a3727a4707a33803b51194791808e5156157a00ba98463617a222f8549eea64c6f88ebed9b578bf08386b23ff52b019411084a571e9fd5a7f702b2995
data/README.md CHANGED
@@ -198,6 +198,9 @@ You can also load your JSONified config in from an ENV variable (e.g. `KUBE_CONF
198
198
  ```
199
199
  Kubeclient::Config.new(JSON.parse(ENV['KUBE_CONFIG']), nil)
200
200
  ```
201
+ ###Supported kubernetes versions
202
+
203
+ For 1.1 only the core api v1 is supported, all api groups are supported in later versions.
201
204
 
202
205
  ## Examples:
203
206
 
data/lib/kubeclient.rb CHANGED
@@ -7,6 +7,7 @@ require 'kubeclient/watch_notice'
7
7
  require 'kubeclient/watch_stream'
8
8
  require 'kubeclient/common'
9
9
  require 'kubeclient/config'
10
+ require 'kubeclient/missing_kind_compatibility'
10
11
 
11
12
  module Kubeclient
12
13
  # Kubernetes Client
@@ -108,13 +108,7 @@ module Kubeclient
108
108
  end
109
109
 
110
110
  def discover
111
- @entities = {}
112
- result = JSON.parse(handle_exception { rest_client.get(@headers) })
113
- result['resources'].each do |resource|
114
- next if resource['name'].include?('/') || resource['kind'].nil?
115
- entity = ClientMixin.parse_definition(resource['kind'], resource['name'])
116
- @entities[entity.method_names[0]] = entity if entity
117
- end
111
+ load_entities
118
112
  define_entity_methods
119
113
  @discovered = true
120
114
  end
@@ -151,8 +145,6 @@ module Kubeclient
151
145
  namespace.to_s.empty? ? '' : "namespaces/#{namespace}/"
152
146
  end
153
147
 
154
- public
155
-
156
148
  def self.resource_class(class_owner, entity_type)
157
149
  if class_owner.const_defined?(entity_type, false)
158
150
  class_owner.const_get(entity_type, false)
@@ -430,6 +422,21 @@ module Kubeclient
430
422
 
431
423
  private
432
424
 
425
+ def load_entities
426
+ @entities = {}
427
+ fetch_entities['resources'].each do |resource|
428
+ next if resource['name'].include?('/')
429
+ resource['kind'] = Kubeclient::Common::MissingKindCompatibility
430
+ .resource_kind(resource['name']) if resource['kind'].nil?
431
+ entity = ClientMixin.parse_definition(resource['kind'], resource['name'])
432
+ @entities[entity.method_names[0]] = entity if entity
433
+ end
434
+ end
435
+
436
+ def fetch_entities
437
+ JSON.parse(handle_exception { rest_client.get(@headers) })
438
+ end
439
+
433
440
  def bearer_token(bearer_token)
434
441
  @headers ||= {}
435
442
  @headers[:Authorization] = "Bearer #{bearer_token}"
@@ -0,0 +1,68 @@
1
+ module Kubeclient
2
+ module Common
3
+ # Backward compatibility for old versions where kind is missing (e.g. OpenShift Enterprise 3.1)
4
+ class MissingKindCompatibility
5
+ MAPPING = {
6
+ 'bindings' => 'Binding',
7
+ 'componentstatuses' => 'ComponentStatus',
8
+ 'endpoints' => 'Endpoints',
9
+ 'events' => 'Event',
10
+ 'limitranges' => 'LimitRange',
11
+ 'namespaces' => 'Namespace',
12
+ 'nodes' => 'Node',
13
+ 'persistentvolumeclaims' => 'PersistentVolumeClaim',
14
+ 'persistentvolumes' => 'PersistentVolume',
15
+ 'pods' => 'Pod',
16
+ 'podtemplates' => 'PodTemplate',
17
+ 'replicationcontrollers' => 'ReplicationController',
18
+ 'resourcequotas' => 'ResourceQuota',
19
+ 'secrets' => 'Secret',
20
+ 'securitycontextconstraints' => 'SecurityContextConstraints',
21
+ 'serviceaccounts' => 'ServiceAccount',
22
+ 'services' => 'Service',
23
+ 'buildconfigs' => 'BuildConfig',
24
+ 'builds' => 'Build',
25
+ 'clusternetworks' => 'ClusterNetwork',
26
+ 'clusterpolicies' => 'ClusterPolicy',
27
+ 'clusterpolicybindings' => 'ClusterPolicyBinding',
28
+ 'clusterrolebindings' => 'ClusterRoleBinding',
29
+ 'clusterroles' => 'ClusterRole',
30
+ 'deploymentconfigrollbacks' => 'DeploymentConfigRollback',
31
+ 'deploymentconfigs' => 'DeploymentConfig',
32
+ 'generatedeploymentconfigs' => 'DeploymentConfig',
33
+ 'groups' => 'Group',
34
+ 'hostsubnets' => 'HostSubnet',
35
+ 'identities' => 'Identity',
36
+ 'images' => 'Image',
37
+ 'imagestreamimages' => 'ImageStreamImage',
38
+ 'imagestreammappings' => 'ImageStreamMapping',
39
+ 'imagestreams' => 'ImageStream',
40
+ 'imagestreamtags' => 'ImageStreamTag',
41
+ 'localresourceaccessreviews' => 'LocalResourceAccessReview',
42
+ 'localsubjectaccessreviews' => 'LocalSubjectAccessReview',
43
+ 'netnamespaces' => 'NetNamespace',
44
+ 'oauthaccesstokens' => 'OAuthAccessToken',
45
+ 'oauthauthorizetokens' => 'OAuthAuthorizeToken',
46
+ 'oauthclientauthorizations' => 'OAuthClientAuthorization',
47
+ 'oauthclients' => 'OAuthClient',
48
+ 'policies' => 'Policy',
49
+ 'policybindings' => 'PolicyBinding',
50
+ 'processedtemplates' => 'Template',
51
+ 'projectrequests' => 'ProjectRequest',
52
+ 'projects' => 'Project',
53
+ 'resourceaccessreviews' => 'ResourceAccessReview',
54
+ 'rolebindings' => 'RoleBinding',
55
+ 'roles' => 'Role',
56
+ 'routes' => 'Route',
57
+ 'subjectaccessreviews' => 'SubjectAccessReview',
58
+ 'templates' => 'Template',
59
+ 'useridentitymappings' => 'UserIdentityMapping',
60
+ 'users' => 'User'
61
+ }
62
+
63
+ def self.resource_kind(name)
64
+ MAPPING[name]
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '2.2.0'
3
+ VERSION = '2.3.0'
4
4
  end
@@ -0,0 +1,129 @@
1
+ {
2
+ "groupVersion": "v1",
3
+ "resources": [
4
+ {
5
+ "name": "bindings",
6
+ "namespaced": true
7
+ },
8
+ {
9
+ "name": "componentstatuses",
10
+ "namespaced": true
11
+ },
12
+ {
13
+ "name": "endpoints",
14
+ "namespaced": true
15
+ },
16
+ {
17
+ "name": "events",
18
+ "namespaced": true
19
+ },
20
+ {
21
+ "name": "limitranges",
22
+ "namespaced": true
23
+ },
24
+ {
25
+ "name": "namespaces",
26
+ "namespaced": false
27
+ },
28
+ {
29
+ "name": "namespaces/finalize",
30
+ "namespaced": false
31
+ },
32
+ {
33
+ "name": "namespaces/status",
34
+ "namespaced": false
35
+ },
36
+ {
37
+ "name": "nodes",
38
+ "namespaced": false
39
+ },
40
+ {
41
+ "name": "nodes/status",
42
+ "namespaced": false
43
+ },
44
+ {
45
+ "name": "persistentvolumeclaims",
46
+ "namespaced": true
47
+ },
48
+ {
49
+ "name": "persistentvolumeclaims/status",
50
+ "namespaced": true
51
+ },
52
+ {
53
+ "name": "persistentvolumes",
54
+ "namespaced": false
55
+ },
56
+ {
57
+ "name": "persistentvolumes/status",
58
+ "namespaced": false
59
+ },
60
+ {
61
+ "name": "pods",
62
+ "namespaced": true
63
+ },
64
+ {
65
+ "name": "pods/attach",
66
+ "namespaced": true
67
+ },
68
+ {
69
+ "name": "pods/binding",
70
+ "namespaced": true
71
+ },
72
+ {
73
+ "name": "pods/exec",
74
+ "namespaced": true
75
+ },
76
+ {
77
+ "name": "pods/log",
78
+ "namespaced": true
79
+ },
80
+ {
81
+ "name": "pods/portforward",
82
+ "namespaced": true
83
+ },
84
+ {
85
+ "name": "pods/proxy",
86
+ "namespaced": true
87
+ },
88
+ {
89
+ "name": "pods/status",
90
+ "namespaced": true
91
+ },
92
+ {
93
+ "name": "podtemplates",
94
+ "namespaced": true
95
+ },
96
+ {
97
+ "name": "replicationcontrollers",
98
+ "namespaced": true
99
+ },
100
+ {
101
+ "name": "replicationcontrollers/status",
102
+ "namespaced": true
103
+ },
104
+ {
105
+ "name": "resourcequotas",
106
+ "namespaced": true
107
+ },
108
+ {
109
+ "name": "resourcequotas/status",
110
+ "namespaced": true
111
+ },
112
+ {
113
+ "name": "secrets",
114
+ "namespaced": true
115
+ },
116
+ {
117
+ "name": "securitycontextconstraints",
118
+ "namespaced": false
119
+ },
120
+ {
121
+ "name": "serviceaccounts",
122
+ "namespaced": true
123
+ },
124
+ {
125
+ "name": "services",
126
+ "namespaced": true
127
+ }
128
+ ]
129
+ }
@@ -0,0 +1,197 @@
1
+ {
2
+ "groupVersion": "v1",
3
+ "resources": [
4
+ {
5
+ "name": "buildconfigs",
6
+ "namespaced": true
7
+ },
8
+ {
9
+ "name": "buildconfigs/instantiate",
10
+ "namespaced": true
11
+ },
12
+ {
13
+ "name": "buildconfigs/instantiatebinary",
14
+ "namespaced": true
15
+ },
16
+ {
17
+ "name": "buildconfigs/webhooks",
18
+ "namespaced": true
19
+ },
20
+ {
21
+ "name": "builds",
22
+ "namespaced": true
23
+ },
24
+ {
25
+ "name": "builds/clone",
26
+ "namespaced": true
27
+ },
28
+ {
29
+ "name": "builds/details",
30
+ "namespaced": true
31
+ },
32
+ {
33
+ "name": "builds/log",
34
+ "namespaced": true
35
+ },
36
+ {
37
+ "name": "clusternetworks",
38
+ "namespaced": false
39
+ },
40
+ {
41
+ "name": "clusterpolicies",
42
+ "namespaced": false
43
+ },
44
+ {
45
+ "name": "clusterpolicybindings",
46
+ "namespaced": false
47
+ },
48
+ {
49
+ "name": "clusterrolebindings",
50
+ "namespaced": false
51
+ },
52
+ {
53
+ "name": "clusterroles",
54
+ "namespaced": false
55
+ },
56
+ {
57
+ "name": "deploymentconfigrollbacks",
58
+ "namespaced": true
59
+ },
60
+ {
61
+ "name": "deploymentconfigs",
62
+ "namespaced": true
63
+ },
64
+ {
65
+ "name": "deploymentconfigs/log",
66
+ "namespaced": true
67
+ },
68
+ {
69
+ "name": "deploymentconfigs/scale",
70
+ "namespaced": true
71
+ },
72
+ {
73
+ "name": "generatedeploymentconfigs",
74
+ "namespaced": true
75
+ },
76
+ {
77
+ "name": "groups",
78
+ "namespaced": false
79
+ },
80
+ {
81
+ "name": "hostsubnets",
82
+ "namespaced": false
83
+ },
84
+ {
85
+ "name": "identities",
86
+ "namespaced": false
87
+ },
88
+ {
89
+ "name": "images",
90
+ "namespaced": false
91
+ },
92
+ {
93
+ "name": "imagestreamimages",
94
+ "namespaced": true
95
+ },
96
+ {
97
+ "name": "imagestreammappings",
98
+ "namespaced": true
99
+ },
100
+ {
101
+ "name": "imagestreams",
102
+ "namespaced": true
103
+ },
104
+ {
105
+ "name": "imagestreams/status",
106
+ "namespaced": true
107
+ },
108
+ {
109
+ "name": "imagestreamtags",
110
+ "namespaced": true
111
+ },
112
+ {
113
+ "name": "localresourceaccessreviews",
114
+ "namespaced": true
115
+ },
116
+ {
117
+ "name": "localsubjectaccessreviews",
118
+ "namespaced": true
119
+ },
120
+ {
121
+ "name": "netnamespaces",
122
+ "namespaced": false
123
+ },
124
+ {
125
+ "name": "oauthaccesstokens",
126
+ "namespaced": false
127
+ },
128
+ {
129
+ "name": "oauthauthorizetokens",
130
+ "namespaced": false
131
+ },
132
+ {
133
+ "name": "oauthclientauthorizations",
134
+ "namespaced": false
135
+ },
136
+ {
137
+ "name": "oauthclients",
138
+ "namespaced": false
139
+ },
140
+ {
141
+ "name": "policies",
142
+ "namespaced": true
143
+ },
144
+ {
145
+ "name": "policybindings",
146
+ "namespaced": true
147
+ },
148
+ {
149
+ "name": "processedtemplates",
150
+ "namespaced": true
151
+ },
152
+ {
153
+ "name": "projectrequests",
154
+ "namespaced": false
155
+ },
156
+ {
157
+ "name": "projects",
158
+ "namespaced": false
159
+ },
160
+ {
161
+ "name": "resourceaccessreviews",
162
+ "namespaced": true
163
+ },
164
+ {
165
+ "name": "rolebindings",
166
+ "namespaced": true
167
+ },
168
+ {
169
+ "name": "roles",
170
+ "namespaced": true
171
+ },
172
+ {
173
+ "name": "routes",
174
+ "namespaced": true
175
+ },
176
+ {
177
+ "name": "routes/status",
178
+ "namespaced": true
179
+ },
180
+ {
181
+ "name": "subjectaccessreviews",
182
+ "namespaced": true
183
+ },
184
+ {
185
+ "name": "templates",
186
+ "namespaced": true
187
+ },
188
+ {
189
+ "name": "useridentitymappings",
190
+ "namespaced": false
191
+ },
192
+ {
193
+ "name": "users",
194
+ "namespaced": false
195
+ }
196
+ ]
197
+ }
@@ -0,0 +1,78 @@
1
+ require 'test_helper'
2
+
3
+ # Core api resource list without kind tests
4
+ class TestResourceListWithoutKind < MiniTest::Test
5
+ def test_get_from_json_api_v1
6
+ stub_request(:get, %r{/api/v1$})
7
+ .to_return(body: open_test_file('core_api_resource_list_without_kind.json'),
8
+ status: 200)
9
+
10
+ client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
11
+ client.discover
12
+
13
+ [
14
+ {
15
+ entity: 'pod',
16
+ type: 'Pod',
17
+ name: 'pods',
18
+ methods: %w(pod pods)
19
+ },
20
+ {
21
+ entity: 'node',
22
+ type: 'Node',
23
+ name: 'nodes',
24
+ methods: %w(node nodes)
25
+ },
26
+ {
27
+ entity: 'service',
28
+ type: 'Service',
29
+ name: 'services',
30
+ methods: %w(service services)
31
+ }
32
+ ].each { |h| assert_entities(client.instance_variable_get(:@entities)[h[:entity]], h) }
33
+
34
+ assert_requested(:get,
35
+ 'http://localhost:8080/api/v1',
36
+ times: 1)
37
+ end
38
+
39
+ def test_get_from_json_oapi_v1
40
+ stub_request(:get, %r{/oapi/v1$})
41
+ .to_return(body: open_test_file('core_oapi_resource_list_without_kind.json'),
42
+ status: 200)
43
+
44
+ client = Kubeclient::Client.new('http://localhost:8080/oapi/', 'v1')
45
+ client.discover
46
+
47
+ [
48
+ {
49
+ entity: 'template',
50
+ type: 'Template',
51
+ name: 'templates',
52
+ methods: %w(template templates)
53
+ },
54
+ {
55
+ entity: 'build',
56
+ type: 'Build',
57
+ name: 'builds',
58
+ methods: %w(build builds)
59
+ },
60
+ {
61
+ entity: 'project',
62
+ type: 'Project',
63
+ name: 'projects',
64
+ methods: %w(project projects)
65
+ }
66
+ ].each { |h| assert_entities(client.instance_variable_get(:@entities)[h[:entity]], h) }
67
+
68
+ assert_requested(:get,
69
+ 'http://localhost:8080/oapi/v1',
70
+ times: 1)
71
+ end
72
+
73
+ def assert_entities(entity, h)
74
+ assert_equal(entity.entity_type, h[:type])
75
+ assert_equal(entity.resource_name, h[:name])
76
+ assert_equal(entity.method_names, h[:methods])
77
+ end
78
+ 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: 2.2.0
4
+ version: 2.3.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-11-15 00:00:00.000000000 Z
11
+ date: 2016-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -156,6 +156,7 @@ files:
156
156
  - lib/kubeclient/config.rb
157
157
  - lib/kubeclient/entity_list.rb
158
158
  - lib/kubeclient/kube_exception.rb
159
+ - lib/kubeclient/missing_kind_compatibility.rb
159
160
  - lib/kubeclient/version.rb
160
161
  - lib/kubeclient/watch_notice.rb
161
162
  - lib/kubeclient/watch_stream.rb
@@ -172,6 +173,8 @@ files:
172
173
  - test/json/component_status_list.json
173
174
  - test/json/config_map_list.json
174
175
  - test/json/core_api_resource_list.json
176
+ - test/json/core_api_resource_list_without_kind.json
177
+ - test/json/core_oapi_resource_list_without_kind.json
175
178
  - test/json/created_endpoint.json
176
179
  - test/json/created_namespace.json
177
180
  - test/json/created_secret.json
@@ -227,6 +230,7 @@ files:
227
230
  - test/test_pod_log.rb
228
231
  - test/test_process_template.rb
229
232
  - test/test_replication_controller.rb
233
+ - test/test_resource_list_without_kind.rb
230
234
  - test/test_resource_quota.rb
231
235
  - test/test_secret.rb
232
236
  - test/test_service.rb
@@ -272,6 +276,8 @@ test_files:
272
276
  - test/json/component_status_list.json
273
277
  - test/json/config_map_list.json
274
278
  - test/json/core_api_resource_list.json
279
+ - test/json/core_api_resource_list_without_kind.json
280
+ - test/json/core_oapi_resource_list_without_kind.json
275
281
  - test/json/created_endpoint.json
276
282
  - test/json/created_namespace.json
277
283
  - test/json/created_secret.json
@@ -327,6 +333,7 @@ test_files:
327
333
  - test/test_pod_log.rb
328
334
  - test/test_process_template.rb
329
335
  - test/test_replication_controller.rb
336
+ - test/test_resource_list_without_kind.rb
330
337
  - test/test_resource_quota.rb
331
338
  - test/test_secret.rb
332
339
  - test/test_service.rb