k8s-ruby 0.17.1 → 0.17.2
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/.gitignore +0 -1
- data/README.md +0 -9
- data/VERSION +1 -1
- data/k8s-ruby.gemspec +1 -3
- data/lib/k8s/resource_client.rb +0 -8
- data/lib/k8s/ruby/version.rb +1 -1
- data/lib/k8s/transport.rb +0 -45
- metadata +3 -46
- data/lib/k8s/resource_client/exec.rb +0 -110
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7bf6629e29b3cf02237f6452f03b8d276d34f8cae7cd21d2200268e2c600e1c
|
4
|
+
data.tar.gz: 84ad817c8dbc5a7264312f4695399664174100a84a15612a36c21db537539783
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1931b02895f606f1e8794c65d7e3e92967f6c33c6d54fa2251e9a751dff0a81808cf5d81475c433938473d8323bc1409d56c04ab4132ba8aae833f6a0798e8d
|
7
|
+
data.tar.gz: c2313e289ed9f23de2203f48412e017c9942711f26c0c92c65dce2ec11eb0bf69650e05e8b7a9c4ef86413d960ae40af5021cb264cef92465bcc941f33d80bdb
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -226,15 +226,6 @@ client.api('v1').resource('pods', namespace: 'default').watch(labelSelector: {'r
|
|
226
226
|
end
|
227
227
|
```
|
228
228
|
|
229
|
-
|
230
|
-
### Exec into running containers
|
231
|
-
> **WARNING:** This feature is currently supported only on Linux based platforms. Windows platforms are NOT supported.
|
232
|
-
|
233
|
-
#### This opens a new shell in the `test-pod` container
|
234
|
-
```ruby
|
235
|
-
client.api('v1').resource('pods', namespace: 'default').exec(name: 'test-pod', container: 'shell', command: '/bin/sh')
|
236
|
-
```
|
237
|
-
|
238
229
|
## Contributing
|
239
230
|
|
240
231
|
Bug reports and pull requests are welcome on GitHub at [k8s-ruby/k8s-ruby](https://github.com/k8s-ruby/k8s-ruby).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.17.
|
1
|
+
0.17.2
|
data/k8s-ruby.gemspec
CHANGED
@@ -33,9 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_runtime_dependency "yajl-ruby", "~> 1.4"
|
34
34
|
spec.add_runtime_dependency "yaml-safe_load_stream3"
|
35
35
|
spec.add_runtime_dependency "base64"
|
36
|
-
|
37
|
-
spec.add_runtime_dependency "faye-websocket", "~> 0.11"
|
38
|
-
spec.add_runtime_dependency "ruby-termios", "~> 1.1" unless Gem::Platform.local.os =~ /mingw|mswin|windows/
|
36
|
+
|
39
37
|
spec.add_development_dependency "bundler", ">= 1.17", "< 3.0"
|
40
38
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
41
39
|
spec.add_development_dependency "rspec", "~> 3.7"
|
data/lib/k8s/resource_client.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "resource_client/exec" unless Gem::Platform.local.os =~ /mingw|mswin|windows/
|
4
|
-
|
5
3
|
module K8s
|
6
4
|
# Per-APIResource type client.
|
7
5
|
#
|
8
6
|
# Used to get/list/update/patch/delete specific types of resources, optionally in some specific namespace.
|
9
|
-
#
|
10
7
|
class ResourceClient
|
11
8
|
# Common helpers used in both class/instance methods
|
12
9
|
module Utils
|
@@ -39,11 +36,6 @@ module K8s
|
|
39
36
|
include Utils
|
40
37
|
extend Utils
|
41
38
|
|
42
|
-
# Don't support Exec for windows since
|
43
|
-
# it depends on ruby-termios which is not supported for Windows platforms
|
44
|
-
# @!parse include K8s::ResourceClient::Exec
|
45
|
-
include Exec if defined?(Exec)
|
46
|
-
|
47
39
|
# Pipeline list requests for multiple resource types.
|
48
40
|
#
|
49
41
|
# Returns flattened array with mixed resource kinds.
|
data/lib/k8s/ruby/version.rb
CHANGED
data/lib/k8s/transport.rb
CHANGED
@@ -388,50 +388,5 @@ module K8s
|
|
388
388
|
**options
|
389
389
|
)
|
390
390
|
end
|
391
|
-
|
392
|
-
# Returns a websocket connection using part of the current transport configuration.
|
393
|
-
# Will use same host and port returned by #server.
|
394
|
-
# @param resource_path [String]
|
395
|
-
# @param query [Hash]
|
396
|
-
# @return [Faye::WebSocket::Client]
|
397
|
-
def build_ws_conn(resource_path, query = {})
|
398
|
-
private_key_file = nil
|
399
|
-
cert_chain_file = nil
|
400
|
-
|
401
|
-
on_open_callbacks = []
|
402
|
-
|
403
|
-
if options[:client_cert] && options[:client_key]
|
404
|
-
private_key_file = options[:client_key]
|
405
|
-
cert_chain_file = options[:client_cert]
|
406
|
-
elsif options[:client_cert_data] && options[:client_key_data]
|
407
|
-
temp_file_path_from_data = lambda do |data|
|
408
|
-
temp_file = Tempfile.new
|
409
|
-
temp_file.write(data)
|
410
|
-
temp_file.close
|
411
|
-
on_open_callbacks << -> { temp_file.unlink }
|
412
|
-
temp_file.path
|
413
|
-
end
|
414
|
-
private_key_file = temp_file_path_from_data.call(options[:client_key_data])
|
415
|
-
cert_chain_file = temp_file_path_from_data.call(options[:client_cert_data])
|
416
|
-
end
|
417
|
-
|
418
|
-
url = server.gsub("http", "ws") +
|
419
|
-
resource_path +
|
420
|
-
Excon::Utils.query_string(query: query)
|
421
|
-
|
422
|
-
ws = Faye::WebSocket::Client.new(
|
423
|
-
url,
|
424
|
-
[],
|
425
|
-
headers: request_options[:headers],
|
426
|
-
tls: {
|
427
|
-
verify_peer: !!options[:ssl_verify_peer],
|
428
|
-
private_key_file: private_key_file,
|
429
|
-
cert_chain_file: cert_chain_file
|
430
|
-
}
|
431
|
-
)
|
432
|
-
|
433
|
-
ws.on(:open) { on_open_callbacks.each(&:call) }
|
434
|
-
ws
|
435
|
-
end
|
436
391
|
end
|
437
392
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k8s-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.17.
|
4
|
+
version: 0.17.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rdx.net
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-04-
|
12
|
+
date: 2025-04-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: excon
|
@@ -157,48 +157,6 @@ dependencies:
|
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
|
-
- !ruby/object:Gem::Dependency
|
161
|
-
name: eventmachine
|
162
|
-
requirement: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - "~>"
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '1.2'
|
167
|
-
type: :runtime
|
168
|
-
prerelease: false
|
169
|
-
version_requirements: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - "~>"
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '1.2'
|
174
|
-
- !ruby/object:Gem::Dependency
|
175
|
-
name: faye-websocket
|
176
|
-
requirement: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - "~>"
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0.11'
|
181
|
-
type: :runtime
|
182
|
-
prerelease: false
|
183
|
-
version_requirements: !ruby/object:Gem::Requirement
|
184
|
-
requirements:
|
185
|
-
- - "~>"
|
186
|
-
- !ruby/object:Gem::Version
|
187
|
-
version: '0.11'
|
188
|
-
- !ruby/object:Gem::Dependency
|
189
|
-
name: ruby-termios
|
190
|
-
requirement: !ruby/object:Gem::Requirement
|
191
|
-
requirements:
|
192
|
-
- - "~>"
|
193
|
-
- !ruby/object:Gem::Version
|
194
|
-
version: '1.1'
|
195
|
-
type: :runtime
|
196
|
-
prerelease: false
|
197
|
-
version_requirements: !ruby/object:Gem::Requirement
|
198
|
-
requirements:
|
199
|
-
- - "~>"
|
200
|
-
- !ruby/object:Gem::Version
|
201
|
-
version: '1.1'
|
202
160
|
- !ruby/object:Gem::Dependency
|
203
161
|
name: bundler
|
204
162
|
requirement: !ruby/object:Gem::Requirement
|
@@ -329,7 +287,6 @@ files:
|
|
329
287
|
- lib/k8s/logging.rb
|
330
288
|
- lib/k8s/resource.rb
|
331
289
|
- lib/k8s/resource_client.rb
|
332
|
-
- lib/k8s/resource_client/exec.rb
|
333
290
|
- lib/k8s/ruby/version.rb
|
334
291
|
- lib/k8s/stack.rb
|
335
292
|
- lib/k8s/transport.rb
|
@@ -353,7 +310,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
353
310
|
- !ruby/object:Gem::Version
|
354
311
|
version: '0'
|
355
312
|
requirements: []
|
356
|
-
rubygems_version: 3.
|
313
|
+
rubygems_version: 3.3.27
|
357
314
|
signing_key:
|
358
315
|
specification_version: 4
|
359
316
|
summary: Kubernetes client library for Ruby
|
@@ -1,110 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module K8s
|
4
|
-
class ResourceClient
|
5
|
-
module Exec
|
6
|
-
def self.included(base)
|
7
|
-
base.include(InstanceMethods)
|
8
|
-
base.include(Logging)
|
9
|
-
end
|
10
|
-
|
11
|
-
module InstanceMethods
|
12
|
-
require "eventmachine"
|
13
|
-
require "faye/websocket"
|
14
|
-
require "termios"
|
15
|
-
require "tempfile"
|
16
|
-
|
17
|
-
# Executes arbitrary commands in a container.
|
18
|
-
#
|
19
|
-
# @param name [String] name of the pod
|
20
|
-
# @param namespace [String]
|
21
|
-
# @param container [String] name of the container to execute the command in
|
22
|
-
# @param command [Array<String>|String] command to execute. It accepts a single string or an array of strings if multiple arguments are needed.
|
23
|
-
# @param stdin [Boolean] whether to stream stdin to the container
|
24
|
-
# @param stdout [Boolean] whether to stream stdout from the container
|
25
|
-
# @param tty [Boolean] whether to allocate a tty for the container
|
26
|
-
# @yield [String] Optional block to yield the output of the command
|
27
|
-
# @return [String, nil] output of the command. It returns nil if a block is given or tty is true.
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# client.api('v1').resource('pods', namespace: 'default').exec(
|
31
|
-
# name: 'test-pod',
|
32
|
-
# container: 'shell',
|
33
|
-
# command: '/bin/sh'
|
34
|
-
# )
|
35
|
-
# @example Open a shell:
|
36
|
-
# exec(name: 'my-pod', container: 'my-container', command: '/bin/sh')
|
37
|
-
# @example Execute single command:
|
38
|
-
# exec(name: 'my-pod', container: 'my-container', command: 'date')
|
39
|
-
# @example Pass multiple arguments:
|
40
|
-
# exec(name: 'my-pod', container: 'my-container', command: ['ls', '-la'])
|
41
|
-
# @example Yield the output of the command:
|
42
|
-
# exec(
|
43
|
-
# name: "test-pod",
|
44
|
-
# container: "shell",
|
45
|
-
# command: [ "watch", "date" ],
|
46
|
-
# ) do |out|
|
47
|
-
# puts "local time #{Time.now}"
|
48
|
-
# puts "server time #{out}"
|
49
|
-
# end
|
50
|
-
def exec(name:, namespace: @namespace, command:, container:, stdin: true, stdout: true, tty: true)
|
51
|
-
query = {
|
52
|
-
command: [command].flatten,
|
53
|
-
container: container,
|
54
|
-
stdin: !!stdin,
|
55
|
-
stdout: !!stdout,
|
56
|
-
tty: !!tty
|
57
|
-
}
|
58
|
-
|
59
|
-
exec_path = path(name, namespace: namespace, subresource: "exec")
|
60
|
-
output = StringIO.new
|
61
|
-
|
62
|
-
EM.run do
|
63
|
-
ws = @transport.build_ws_conn(exec_path, query)
|
64
|
-
|
65
|
-
ws.on :message do |event|
|
66
|
-
out = event.data.pack("C*")
|
67
|
-
|
68
|
-
if block_given?
|
69
|
-
yield(out)
|
70
|
-
elsif tty
|
71
|
-
print out
|
72
|
-
else
|
73
|
-
output.write(out)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
ws.on :error do |event|
|
78
|
-
logger.error(event.message)
|
79
|
-
end
|
80
|
-
|
81
|
-
term_attributes_original = Termios.tcgetattr($stdin)
|
82
|
-
if tty
|
83
|
-
term_attributes = term_attributes_original.dup
|
84
|
-
term_attributes.lflag &= ~Termios::ECHO
|
85
|
-
term_attributes.lflag &= ~Termios::ICANON
|
86
|
-
Termios.tcsetattr($stdin, Termios::TCSANOW, term_attributes)
|
87
|
-
|
88
|
-
EM.open_keyboard(Module.new do
|
89
|
-
define_method(:receive_data) do |input|
|
90
|
-
input = [0] + input.unpack("C*")
|
91
|
-
ws.send(input)
|
92
|
-
end
|
93
|
-
end)
|
94
|
-
end
|
95
|
-
|
96
|
-
ws.on :close do
|
97
|
-
Termios.tcsetattr($stdin, Termios::TCSANOW, term_attributes_original)
|
98
|
-
EM.stop
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
return if tty
|
103
|
-
|
104
|
-
output.rewind
|
105
|
-
output.read
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|