kubeclient 4.7.0 → 4.8.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +27 -0
- data/kubeclient.gemspec +1 -1
- data/lib/kubeclient/common.rb +18 -1
- data/lib/kubeclient/version.rb +1 -1
- data/test/test_service.rb +27 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48d448677cbf44234e974ccb8abd00002c729b059f8857120f11d7a017c63f96
|
4
|
+
data.tar.gz: 1db9a01ab5819636816562bd60b563db6e1aa20aa45f8e8b1283da35e1c77a37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3ba57f5db5c09035f1ae3265203f5eb64858b7383c9cb73a9e2186befc4b7c120db3984634626895143c5409c9b943103d93a106274b4d61f57579d2e22ba93
|
7
|
+
data.tar.gz: 2154232e7359a4e3eae7191093338cce2f6daa44abf30f663bbe59631435927519f7e342dd103a485726375bdfde5d556c3a825b3dbd063d23f055e5eb16ad1e
|
data/CHANGELOG.md
CHANGED
@@ -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.8.0 — 2020-07-03
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- Support for server-side apply (#448).
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- Declared forgotten dependency on jsonpath, needed for `gcp` provider with `cmd-path` (#450).
|
14
|
+
|
7
15
|
## 4.7.0 — 2020-06-14
|
8
16
|
|
9
17
|
### Fixed
|
data/README.md
CHANGED
@@ -447,6 +447,9 @@ update_foo(Kubeclient::Resource.new({metadata: {name: 'name', ...}, ...})) # gl
|
|
447
447
|
|
448
448
|
patch_foo('name', patch, 'namespace') # namespaced
|
449
449
|
patch_foo('name', patch) # global
|
450
|
+
|
451
|
+
apply_foo(Kubeclient::Resource.new({metadata: {name: 'name', namespace: 'namespace', ...}, ...}), field_manager: 'myapp', **opts)
|
452
|
+
apply_foo(Kubeclient::Resource.new({metadata: {name: 'name', ...}, ...}), field_manager: 'myapp', **opts) # global
|
450
453
|
```
|
451
454
|
|
452
455
|
These grew to be quite inconsistent :confounded:, see https://github.com/abonas/kubeclient/issues/312 and https://github.com/abonas/kubeclient/issues/332 for improvement plans.
|
@@ -702,6 +705,30 @@ patched = client.patch_pod("docker-registry", {metadata: {annotations: {key: 'va
|
|
702
705
|
|
703
706
|
`patch_#{entity}` is called using a [strategic merge patch](https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#notes-on-the-strategic-merge-patch). `json_patch_#{entity}` and `merge_patch_#{entity}` are also available that use JSON patch and JSON merge patch, respectively. These strategies are useful for resources that do not support strategic merge patch, such as Custom Resources. Consult the [Kubernetes docs](https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment) for more information about the different patch strategies.
|
704
707
|
|
708
|
+
### Apply an entity
|
709
|
+
|
710
|
+
This is similar to `kubectl apply --server-side` (kubeclient doesn't implement logic for client-side apply). See https://kubernetes.io/docs/reference/using-api/api-concepts/#server-side-apply
|
711
|
+
|
712
|
+
For example: `apply_pod`
|
713
|
+
|
714
|
+
Input parameters - resource (Kubeclient::Resource) representing the desired state of the resource, field_manager (String) to identify the system managing the state of the resource, force (Boolean) whether or not to override a field managed by someone else.
|
715
|
+
|
716
|
+
Example:
|
717
|
+
|
718
|
+
```ruby
|
719
|
+
service = Kubeclient::Resource.new(
|
720
|
+
metadata: {
|
721
|
+
name: 'redis-master',
|
722
|
+
namespace: 'staging',
|
723
|
+
},
|
724
|
+
spec: {
|
725
|
+
...
|
726
|
+
}
|
727
|
+
)
|
728
|
+
|
729
|
+
client.apply_service(service, field_manager: 'myapp')
|
730
|
+
```
|
731
|
+
|
705
732
|
### Get all entities of all types : all_entities
|
706
733
|
|
707
734
|
Makes requests for all entities of each discovered kind (in this client's API group). This method is a convenience method instead of calling each entity's get method separately.
|
data/kubeclient.gemspec
CHANGED
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency 'googleauth', '~> 0.5.1'
|
31
31
|
spec.add_development_dependency('mocha', '~> 1.5')
|
32
32
|
spec.add_development_dependency 'openid_connect', '~> 1.1'
|
33
|
-
spec.add_development_dependency 'jsonpath', '~> 1.0'
|
34
33
|
|
34
|
+
spec.add_dependency 'jsonpath', '~> 1.0'
|
35
35
|
spec.add_dependency 'rest-client', '~> 2.0'
|
36
36
|
spec.add_dependency 'recursive-open-struct', '~> 1.1', '>= 1.1.1'
|
37
37
|
spec.add_dependency 'http', '>= 3.0', '< 5.0'
|
data/lib/kubeclient/common.rb
CHANGED
@@ -5,7 +5,7 @@ module Kubeclient
|
|
5
5
|
# Common methods
|
6
6
|
# this is mixed in by other gems
|
7
7
|
module ClientMixin
|
8
|
-
ENTITY_METHODS = %w[get watch delete create update patch json_patch merge_patch].freeze
|
8
|
+
ENTITY_METHODS = %w[get watch delete create update patch json_patch merge_patch apply].freeze
|
9
9
|
|
10
10
|
DEFAULT_SSL_OPTIONS = {
|
11
11
|
client_cert: nil,
|
@@ -254,6 +254,10 @@ module Kubeclient
|
|
254
254
|
do |name, patch, namespace = nil|
|
255
255
|
patch_entity(entity.resource_name, name, patch, 'merge-patch', namespace)
|
256
256
|
end
|
257
|
+
|
258
|
+
define_singleton_method("apply_#{entity.method_names[0]}") do |*args|
|
259
|
+
apply_entity(entity.resource_name, *args)
|
260
|
+
end
|
257
261
|
end
|
258
262
|
end
|
259
263
|
# rubocop:enable Metrics/BlockLength
|
@@ -411,6 +415,19 @@ module Kubeclient
|
|
411
415
|
format_response(@as, response.body)
|
412
416
|
end
|
413
417
|
|
418
|
+
def apply_entity(resource_name, resource, field_manager:, force: true)
|
419
|
+
name = "#{resource[:metadata][:name]}?fieldManager=#{field_manager}&force=#{force}"
|
420
|
+
ns_prefix = build_namespace_prefix(resource[:metadata][:namespace])
|
421
|
+
response = handle_exception do
|
422
|
+
rest_client[ns_prefix + resource_name + "/#{name}"]
|
423
|
+
.patch(
|
424
|
+
resource.to_json,
|
425
|
+
{ 'Content-Type' => 'application/apply-patch+yaml' }.merge(@headers)
|
426
|
+
)
|
427
|
+
end
|
428
|
+
format_response(@as, response.body)
|
429
|
+
end
|
430
|
+
|
414
431
|
def all_entities(options = {})
|
415
432
|
discover unless @discovered
|
416
433
|
@entities.values.each_with_object({}) do |entity, result_hash|
|
data/lib/kubeclient/version.rb
CHANGED
data/test/test_service.rb
CHANGED
@@ -274,6 +274,33 @@ class TestService < MiniTest::Test
|
|
274
274
|
end
|
275
275
|
end
|
276
276
|
|
277
|
+
def test_apply_service
|
278
|
+
service = Kubeclient::Resource.new
|
279
|
+
name = 'my_service'
|
280
|
+
|
281
|
+
service.metadata = {}
|
282
|
+
service.metadata.name = name
|
283
|
+
service.metadata.namespace = 'development'
|
284
|
+
service.metadata.annotations = {}
|
285
|
+
service.metadata.annotations['key'] = 'value'
|
286
|
+
|
287
|
+
stub_core_api_list
|
288
|
+
resource_name = "#{name}?fieldManager=myapp&force=true"
|
289
|
+
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{resource_name}"
|
290
|
+
stub_request(:patch, expected_url)
|
291
|
+
.to_return(body: open_test_file('service_patch.json'), status: 200)
|
292
|
+
|
293
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
294
|
+
service = client.apply_service(service, field_manager: 'myapp')
|
295
|
+
assert_kind_of(RecursiveOpenStruct, service)
|
296
|
+
|
297
|
+
assert_requested(:patch, expected_url, times: 1) do |req|
|
298
|
+
data = JSON.parse(req.body)
|
299
|
+
req.headers['Content-Type'] == 'application/apply-patch+yaml' &&
|
300
|
+
data['metadata']['annotations']['key'] == 'value'
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
277
304
|
def test_json_patch_service
|
278
305
|
service = Kubeclient::Resource.new
|
279
306
|
name = 'my-service'
|
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.
|
4
|
+
version: 4.8.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: 2020-
|
11
|
+
date: 2020-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,7 +157,7 @@ dependencies:
|
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '1.0'
|
160
|
-
type: :
|
160
|
+
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|