kubeclient 4.5.0 → 4.6.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/.travis.yml +2 -0
- data/CHANGELOG.md +10 -1
- data/README.md +15 -7
- data/lib/kubeclient/aws_eks_credentials.rb +1 -1
- data/lib/kubeclient/common.rb +25 -7
- data/lib/kubeclient/version.rb +1 -1
- data/test/test_pod_log.rb +37 -3
- data/test/test_watch.rb +13 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb667e5ef31b7fa7057dbcdebe65d3f5ba1914f6cbdd8c7eedd2556f7bcfcb0a
|
4
|
+
data.tar.gz: 88084d0e7f317a5ca7708804d364b04b4d4c8771415223aa7a04f9dcd530d332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d69f0b0f0814a94690aaebcd4d748cc56748081d9a9abe1ab9dfaf63a64d34c71475760b22f4849d61fb7ebc180eb0aa8395b9df1697c2cafa39a54217917e1
|
7
|
+
data.tar.gz: 8353e4ceca63fd43a5b42b4254c2bfe1277411f0bd45336cf54650f949f14639f8ca0f0f6a845641810f3a795fe09fe1e3387b444044c4c659a0c2519d5207b8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,10 +4,19 @@ 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.
|
7
|
+
## 4.6.0 — 2019-12-30
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
- AmazonEksCredentials was sometimes leaving base64 padding that IAM auth of the EKS cluster rejects. Now padding is always stripped. (#424, #423)
|
8
11
|
|
9
12
|
### Added
|
13
|
+
- Allow calling `watch_foos` methods with a block, simpler to use and guarantees closing the connection. (#425)
|
14
|
+
|
15
|
+
- Support `limitBytes` query parameter for `get_pod_log`. (#426)
|
10
16
|
|
17
|
+
## 4.5.0 — 2019-09-27
|
18
|
+
|
19
|
+
### Added
|
11
20
|
- Support `:resourceVersion` parameter in `get_foos` methods (similar to existing support in `watch_foos` methods). (#420)
|
12
21
|
|
13
22
|
- Relax dependency on `http` gem to allow both 3.x and 4.x. (#413)
|
data/README.md
CHANGED
@@ -596,8 +596,7 @@ client.all_entities
|
|
596
596
|
It is possible to receive live update notices watching the relevant entities:
|
597
597
|
|
598
598
|
```ruby
|
599
|
-
|
600
|
-
watcher.each do |notice|
|
599
|
+
client.watch_pods do |notice|
|
601
600
|
# process notice data
|
602
601
|
end
|
603
602
|
```
|
@@ -605,15 +604,19 @@ end
|
|
605
604
|
It is possible to interrupt the watcher from another thread with:
|
606
605
|
|
607
606
|
```ruby
|
608
|
-
watcher.
|
607
|
+
watcher = client.watch_pods
|
608
|
+
watcher.each do |notice|
|
609
|
+
# process notice data
|
610
|
+
end
|
611
|
+
|
612
|
+
watcher.finish # other thread
|
609
613
|
```
|
610
614
|
|
611
615
|
#### Watch events for a particular object
|
612
616
|
You can use the `field_selector` option as part of the watch methods.
|
613
617
|
|
614
618
|
```ruby
|
615
|
-
|
616
|
-
watcher.each do |notice|
|
619
|
+
client.watch_events(namespace: 'development', field_selector: 'involvedObject.name=redis-master') do |notice|
|
617
620
|
# process notice date
|
618
621
|
end
|
619
622
|
```
|
@@ -670,11 +673,16 @@ client.get_pod_log('pod-name', 'default', tail_lines: 10)
|
|
670
673
|
# => "..."
|
671
674
|
```
|
672
675
|
|
676
|
+
Kubernetes can fetch a specific number of bytes from the log, but the exact size is not guaranteed and last line may not be terminated:
|
677
|
+
```ruby
|
678
|
+
client.get_pod_log('pod-name', 'default', limit_bytes: 10)
|
679
|
+
# => "..."
|
680
|
+
```
|
681
|
+
|
673
682
|
You can also watch the logs of a pod to get a stream of data:
|
674
683
|
|
675
684
|
```ruby
|
676
|
-
|
677
|
-
watcher.each do |line|
|
685
|
+
client.watch_pod_log('pod-name', 'default', container: 'ruby') do |line|
|
678
686
|
puts line
|
679
687
|
end
|
680
688
|
```
|
@@ -38,7 +38,7 @@ module Kubeclient
|
|
38
38
|
'X-K8s-Aws-Id' => eks_cluster
|
39
39
|
}
|
40
40
|
)
|
41
|
-
kube_token = 'k8s-aws-v1.' + Base64.urlsafe_encode64(presigned_url_string.to_s).
|
41
|
+
kube_token = 'k8s-aws-v1.' + Base64.urlsafe_encode64(presigned_url_string.to_s).sub(/=*$/, '') # rubocop:disable Metrics/LineLength
|
42
42
|
kube_token
|
43
43
|
end
|
44
44
|
end
|
data/lib/kubeclient/common.rb
CHANGED
@@ -213,12 +213,12 @@ module Kubeclient
|
|
213
213
|
end
|
214
214
|
|
215
215
|
# watch all entities of a type e.g. watch_nodes, watch_pods, etc.
|
216
|
-
define_singleton_method("watch_#{entity.method_names[1]}") do |options = {}|
|
216
|
+
define_singleton_method("watch_#{entity.method_names[1]}") do |options = {}, &block|
|
217
217
|
# This method used to take resource_version as a param, so
|
218
218
|
# this conversion is to keep backwards compatibility
|
219
219
|
options = { resource_version: options } unless options.is_a?(Hash)
|
220
220
|
|
221
|
-
watch_entities(entity.resource_name, options)
|
221
|
+
watch_entities(entity.resource_name, options, &block)
|
222
222
|
end
|
223
223
|
|
224
224
|
# get a single entity of a specific type by name
|
@@ -295,7 +295,9 @@ module Kubeclient
|
|
295
295
|
# :as (:raw|:ros) - defaults to :ros
|
296
296
|
# :raw - return the raw response body as a string
|
297
297
|
# :ros - return a collection of RecursiveOpenStruct objects
|
298
|
-
|
298
|
+
# Accepts an optional block, that will be called with each entity,
|
299
|
+
# otherwise returns a WatchStream
|
300
|
+
def watch_entities(resource_name, options = {}, &block)
|
299
301
|
ns = build_namespace_prefix(options[:namespace])
|
300
302
|
|
301
303
|
path = "watch/#{ns}#{resource_name}"
|
@@ -306,11 +308,13 @@ module Kubeclient
|
|
306
308
|
WATCH_ARGUMENTS.each { |k, v| params[k] = options[v] if options[v] }
|
307
309
|
uri.query = URI.encode_www_form(params) if params.any?
|
308
310
|
|
309
|
-
Kubeclient::Common::WatchStream.new(
|
311
|
+
watcher = Kubeclient::Common::WatchStream.new(
|
310
312
|
uri,
|
311
313
|
http_options(uri),
|
312
314
|
formatter: ->(value) { format_response(options[:as] || @as, value) }
|
313
315
|
)
|
316
|
+
|
317
|
+
return_or_yield_to_watcher(watcher, &block)
|
314
318
|
end
|
315
319
|
|
316
320
|
# Accepts the following options:
|
@@ -423,13 +427,14 @@ module Kubeclient
|
|
423
427
|
|
424
428
|
def get_pod_log(pod_name, namespace,
|
425
429
|
container: nil, previous: false,
|
426
|
-
timestamps: false, since_time: nil, tail_lines: nil)
|
430
|
+
timestamps: false, since_time: nil, tail_lines: nil, limit_bytes: nil)
|
427
431
|
params = {}
|
428
432
|
params[:previous] = true if previous
|
429
433
|
params[:container] = container if container
|
430
434
|
params[:timestamps] = timestamps if timestamps
|
431
435
|
params[:sinceTime] = format_datetime(since_time) if since_time
|
432
436
|
params[:tailLines] = tail_lines if tail_lines
|
437
|
+
params[:limitBytes] = limit_bytes if limit_bytes
|
433
438
|
|
434
439
|
ns = build_namespace_prefix(namespace)
|
435
440
|
handle_exception do
|
@@ -438,7 +443,7 @@ module Kubeclient
|
|
438
443
|
end
|
439
444
|
end
|
440
445
|
|
441
|
-
def watch_pod_log(pod_name, namespace, container: nil)
|
446
|
+
def watch_pod_log(pod_name, namespace, container: nil, &block)
|
442
447
|
# Adding the "follow=true" query param tells the Kubernetes API to keep
|
443
448
|
# the connection open and stream updates to the log.
|
444
449
|
params = { follow: true }
|
@@ -450,7 +455,10 @@ module Kubeclient
|
|
450
455
|
uri.path += "/#{@api_version}/#{ns}pods/#{pod_name}/log"
|
451
456
|
uri.query = URI.encode_www_form(params)
|
452
457
|
|
453
|
-
Kubeclient::Common::WatchStream.new(
|
458
|
+
watcher = Kubeclient::Common::WatchStream.new(
|
459
|
+
uri, http_options(uri), formatter: ->(value) { value }
|
460
|
+
)
|
461
|
+
return_or_yield_to_watcher(watcher, &block)
|
454
462
|
end
|
455
463
|
|
456
464
|
def proxy_url(kind, name, port, namespace = '')
|
@@ -587,6 +595,16 @@ module Kubeclient
|
|
587
595
|
raise ArgumentError, msg unless File.readable?(@auth_options[:bearer_token_file])
|
588
596
|
end
|
589
597
|
|
598
|
+
def return_or_yield_to_watcher(watcher, &block)
|
599
|
+
return watcher unless block_given?
|
600
|
+
|
601
|
+
begin
|
602
|
+
watcher.each(&block)
|
603
|
+
ensure
|
604
|
+
watcher.finish
|
605
|
+
end
|
606
|
+
end
|
607
|
+
|
590
608
|
def http_options(uri)
|
591
609
|
options = {
|
592
610
|
basic_auth_user: @auth_options[:username],
|
data/lib/kubeclient/version.rb
CHANGED
data/test/test_pod_log.rb
CHANGED
@@ -69,12 +69,31 @@ class TestPodLog < MiniTest::Test
|
|
69
69
|
times: 1)
|
70
70
|
end
|
71
71
|
|
72
|
+
def test_get_pod_limit_bytes
|
73
|
+
selected_bytes = open_test_file('pod_log.txt').read(10)
|
74
|
+
|
75
|
+
stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log})
|
76
|
+
.to_return(body: selected_bytes,
|
77
|
+
status: 200)
|
78
|
+
|
79
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
80
|
+
retrieved_log = client.get_pod_log('redis-master-pod',
|
81
|
+
'default',
|
82
|
+
limit_bytes: 10)
|
83
|
+
|
84
|
+
assert_equal(selected_bytes, retrieved_log)
|
85
|
+
|
86
|
+
assert_requested(:get,
|
87
|
+
'http://localhost:8080/api/v1/namespaces/default/pods/redis-master-pod/log?limitBytes=10',
|
88
|
+
times: 1)
|
89
|
+
end
|
90
|
+
|
72
91
|
def test_watch_pod_log
|
73
|
-
|
92
|
+
file = open_test_file('pod_log.txt')
|
93
|
+
expected_lines = file.read.split("\n")
|
74
94
|
|
75
95
|
stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log\?.*follow})
|
76
|
-
.to_return(body:
|
77
|
-
status: 200)
|
96
|
+
.to_return(body: file, status: 200)
|
78
97
|
|
79
98
|
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
80
99
|
|
@@ -85,6 +104,21 @@ class TestPodLog < MiniTest::Test
|
|
85
104
|
end
|
86
105
|
end
|
87
106
|
|
107
|
+
def test_watch_pod_log_with_block
|
108
|
+
file = open_test_file('pod_log.txt')
|
109
|
+
first = file.readlines.first.chomp
|
110
|
+
|
111
|
+
stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log\?.*follow})
|
112
|
+
.to_return(body: file, status: 200)
|
113
|
+
|
114
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
115
|
+
|
116
|
+
client.watch_pod_log('redis-master-pod', 'default') do |line|
|
117
|
+
assert_equal first, line
|
118
|
+
break
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
88
122
|
def test_watch_pod_log_follow_redirect
|
89
123
|
expected_lines = open_test_file('pod_log.txt').read.split("\n")
|
90
124
|
redirect = 'http://localhost:1234/api/namespaces/default/pods/redis-master-pod/log'
|
data/test/test_watch.rb
CHANGED
@@ -27,6 +27,19 @@ class TestWatch < MiniTest::Test
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_watch_pod_block
|
31
|
+
stub_core_api_list
|
32
|
+
stub_request(:get, %r{/watch/pods})
|
33
|
+
.to_return(body: open_test_file('watch_stream.json'),
|
34
|
+
status: 200)
|
35
|
+
|
36
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
37
|
+
yielded = []
|
38
|
+
client.watch_pods { |notice| yielded << notice.type }
|
39
|
+
|
40
|
+
assert_equal %w[ADDED MODIFIED DELETED], yielded
|
41
|
+
end
|
42
|
+
|
30
43
|
def test_watch_pod_raw
|
31
44
|
stub_core_api_list
|
32
45
|
|
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.6.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: 2019-
|
11
|
+
date: 2019-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -372,8 +372,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
372
372
|
- !ruby/object:Gem::Version
|
373
373
|
version: '0'
|
374
374
|
requirements: []
|
375
|
-
|
376
|
-
rubygems_version: 2.7.6.2
|
375
|
+
rubygems_version: 3.0.3
|
377
376
|
signing_key:
|
378
377
|
specification_version: 4
|
379
378
|
summary: A client for Kubernetes REST api
|