k8s-client 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/k8s/api/metav1.rb +1 -0
- data/lib/k8s/api/metav1/watch_event.rb +20 -0
- data/lib/k8s/client.rb +2 -0
- data/lib/k8s/client/version.rb +1 -1
- data/lib/k8s/resource_client.rb +44 -2
- data/lib/k8s/transport.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6021ff799426838c2f3d874b13b2cd2d53ac8298ccfbb983e3ca53943dcfb3be
|
4
|
+
data.tar.gz: 516330c9bcb21af9221eef99f3304187cde161db1d9f7cc8ec1d9c1a1ac4360f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed9e425df7d635def2d912a4083ac64dd189dc2c644983e162066a2f9b3026b4192a79bcfe64df6f38a35bffc5cc970cb6966ab1e12a4b7a3aadff2aa5a6aa9a
|
7
|
+
data.tar.gz: ac16a5c433205dc8a9db24d73413d4053c73cc4da9eac09a180e472d96f87c3ce300e32c70079e9b745f6fed18e507609b352b6e3e10e5d9e09235103668fb8e
|
data/README.md
CHANGED
@@ -204,6 +204,14 @@ client.api('apps/v1').resource('deployments', namespace: 'default').merge_patch(
|
|
204
204
|
})
|
205
205
|
```
|
206
206
|
|
207
|
+
### Watching resources
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
client.api('v1').resource('pods', namespace: 'default').watch(labelSelector: {'role' => 'test'}) do |watch_event|
|
211
|
+
puts "type=#{watch_event.type} pod=#{watch_event.resource.metadata.name}"
|
212
|
+
end
|
213
|
+
```
|
214
|
+
|
207
215
|
## Contributing
|
208
216
|
|
209
217
|
Bug reports and pull requests are welcome on GitHub at https://github.com/kontena/k8s-client.
|
data/lib/k8s/api/metav1.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../resource'
|
4
|
+
|
5
|
+
module K8s
|
6
|
+
module API
|
7
|
+
module MetaV1
|
8
|
+
# @see https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#WatchEvent
|
9
|
+
class WatchEvent < Resource
|
10
|
+
attribute :type, Types::Strict::String
|
11
|
+
attribute :object, Types::Strict::Hash
|
12
|
+
|
13
|
+
# @return [K8s::Resource]
|
14
|
+
def resource
|
15
|
+
@resource ||= K8s::Resource.new(object)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/k8s/client.rb
CHANGED
data/lib/k8s/client/version.rb
CHANGED
data/lib/k8s/resource_client.rb
CHANGED
@@ -189,9 +189,19 @@ module K8s
|
|
189
189
|
|
190
190
|
# @param labelSelector [nil, String, Hash{String => String}]
|
191
191
|
# @param fieldSelector [nil, String, Hash{String => String}]
|
192
|
+
# @param namespace [nil, String]
|
192
193
|
# @return [Array<resource_class>]
|
193
194
|
def list(labelSelector: nil, fieldSelector: nil, namespace: @namespace)
|
194
|
-
list =
|
195
|
+
list = meta_list(labelSelector: labelSelector, fieldSelector: fieldSelector, namespace: namespace)
|
196
|
+
process_list(list)
|
197
|
+
end
|
198
|
+
|
199
|
+
# @param labelSelector [nil, String, Hash{String => String}]
|
200
|
+
# @param fieldSelector [nil, String, Hash{String => String}]
|
201
|
+
# @param namespace [nil, String]
|
202
|
+
# @return [K8s::API::MetaV1::List]
|
203
|
+
def meta_list(labelSelector: nil, fieldSelector: nil, namespace: @namespace)
|
204
|
+
@transport.request(
|
195
205
|
method: 'GET',
|
196
206
|
path: path(namespace: namespace),
|
197
207
|
response_class: K8s::API::MetaV1::List,
|
@@ -200,7 +210,39 @@ module K8s
|
|
200
210
|
'fieldSelector' => selector_query(fieldSelector)
|
201
211
|
)
|
202
212
|
)
|
203
|
-
|
213
|
+
end
|
214
|
+
|
215
|
+
# @param labelSelector [nil, String, Hash{String => String}]
|
216
|
+
# @param fieldSelector [nil, String, Hash{String => String}]
|
217
|
+
# @param resourceVersion [nil, String]
|
218
|
+
# @param timeout [nil, Integer]
|
219
|
+
# @yield [K8S::API::MetaV1::WatchEvent]
|
220
|
+
# @raise [Excon::Error]
|
221
|
+
def watch(labelSelector: nil, fieldSelector: nil, resourceVersion: nil, timeout: nil, namespace: @namespace)
|
222
|
+
method = 'GET'
|
223
|
+
path = path(namespace: namespace)
|
224
|
+
@transport.request(
|
225
|
+
method: method,
|
226
|
+
path: path,
|
227
|
+
response_class: K8s::API::MetaV1::List,
|
228
|
+
query: make_query(
|
229
|
+
'labelSelector' => selector_query(labelSelector),
|
230
|
+
'fieldSelector' => selector_query(fieldSelector),
|
231
|
+
'resourceVersion' => resourceVersion,
|
232
|
+
'watch' => '1'
|
233
|
+
),
|
234
|
+
response_block: lambda do |chunk, _, _|
|
235
|
+
data = JSON.parse(chunk)
|
236
|
+
event = K8s::API::MetaV1::WatchEvent.new(data)
|
237
|
+
resourceVersion = event.resource&.metadata&.resourceVersion
|
238
|
+
yield event
|
239
|
+
end,
|
240
|
+
read_timeout: timeout
|
241
|
+
)
|
242
|
+
rescue Excon::Error::Timeout
|
243
|
+
retry if timeout.nil?
|
244
|
+
|
245
|
+
raise K8s::Error::Timeout.new(method, path, 408, 'timeout')
|
204
246
|
end
|
205
247
|
|
206
248
|
# @return [Bool]
|
data/lib/k8s/transport.rb
CHANGED
@@ -190,6 +190,8 @@ module K8s
|
|
190
190
|
end
|
191
191
|
|
192
192
|
if response.status.between? 200, 299
|
193
|
+
return response_data if content_type == 'text/plain'
|
194
|
+
|
193
195
|
unless response_data.is_a? Hash
|
194
196
|
raise K8s::Error::API.new(method, path, response.status, "Invalid JSON response: #{response_data.inspect}")
|
195
197
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k8s-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kontena, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -192,6 +192,7 @@ files:
|
|
192
192
|
- lib/k8s/api/metav1/list.rb
|
193
193
|
- lib/k8s/api/metav1/object.rb
|
194
194
|
- lib/k8s/api/metav1/status.rb
|
195
|
+
- lib/k8s/api/metav1/watch_event.rb
|
195
196
|
- lib/k8s/api/version.rb
|
196
197
|
- lib/k8s/api_client.rb
|
197
198
|
- lib/k8s/client.rb
|