train-kubernetes 0.1.6 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/train-kubernetes/connection.rb +15 -1
- data/lib/train-kubernetes/kubectl_client.rb +39 -0
- data/lib/train-kubernetes/transport.rb +3 -0
- data/lib/train-kubernetes/version.rb +1 -1
- data/train-kubernetes.gemspec +2 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e4bbb998822377221a31b8839373f73d298d6f2bd4226300ff8428742ca247c
|
4
|
+
data.tar.gz: e87a4add57561718dc7780d20aa0741de23e9bc615108dd139609377edb4d05b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfd9ca8003441da0bb8abd13f6a5ceae755239f406201b76d94ec2088a07ea12cc29e2fbe0a7132e4e6745910752823c9753a3b17585b39de62e1a5527192c6c
|
7
|
+
data.tar.gz: c50d9c99fe60b9b51b71b789f7c233815cf0391a89d8ffa6bc2faaae3f5f74e416211400b02e273da1f8c4348f4e749ce368eba5148acefa91faf43a533610fc
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'train'
|
2
2
|
require 'k8s-ruby'
|
3
3
|
require 'train-kubernetes/platform'
|
4
|
+
require 'train-kubernetes/kubectl_client'
|
4
5
|
|
5
6
|
module TrainPlugins
|
6
7
|
module TrainKubernetes
|
@@ -9,7 +10,9 @@ module TrainPlugins
|
|
9
10
|
|
10
11
|
def initialize(options)
|
11
12
|
super(options)
|
12
|
-
|
13
|
+
@pod = options[:pod] || options[:path]&.gsub('/', '')
|
14
|
+
@container = options[:container]
|
15
|
+
@namespace = options[:namespace] || options[:host]
|
13
16
|
parse_kubeconfig
|
14
17
|
connect
|
15
18
|
end
|
@@ -35,6 +38,17 @@ module TrainPlugins
|
|
35
38
|
kubeconfig_file = @options[:kubeconfig] if @options[:kubeconfig]
|
36
39
|
@client = K8s::Client.config(K8s::Config.load_file(File.expand_path(kubeconfig_file)))
|
37
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
attr_reader :pod, :container, :namespace
|
45
|
+
|
46
|
+
def run_command_via_connection(cmd, opts = {}, &_data_handler)
|
47
|
+
KubectlClient.new(pod: opts[:pod] || pod,
|
48
|
+
container: opts[:container] || container,
|
49
|
+
namespace: opts[:namespace] || namespace)
|
50
|
+
.execute(cmd)
|
51
|
+
end
|
38
52
|
end
|
39
53
|
end
|
40
54
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'mixlib/shellout'
|
2
|
+
|
3
|
+
module TrainPlugins
|
4
|
+
module TrainKubernetes
|
5
|
+
class KubectlClient
|
6
|
+
attr_reader :pod, :container, :namespace
|
7
|
+
DEFAULT_NAMESPACE = 'default'.freeze
|
8
|
+
|
9
|
+
def initialize(pod:, namespace: nil, container: nil)
|
10
|
+
@pod = pod
|
11
|
+
@container = container
|
12
|
+
@namespace = namespace || DEFAULT_NAMESPACE
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute(command, stdin: true, tty: true)
|
16
|
+
instruction = build_instruction(command, stdin, tty)
|
17
|
+
shell = Mixlib::ShellOut.new(instruction)
|
18
|
+
shell.run_command
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def shell
|
24
|
+
@shell ||= Mixlib::ShellOut.new(instruction)
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_instruction(command, stdin, tty)
|
28
|
+
['kubectl exec'].tap do |arr|
|
29
|
+
arr << '--stdin' if stdin
|
30
|
+
arr << pod if pod
|
31
|
+
arr << '-n'
|
32
|
+
arr << namespace
|
33
|
+
arr << '--'
|
34
|
+
arr << command
|
35
|
+
end.join("\s")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -5,6 +5,9 @@ module TrainPlugins
|
|
5
5
|
class Transport < Train.plugin(1)
|
6
6
|
name 'k8s'
|
7
7
|
option :kubeconfig, default: ENV['KUBECONFIG'] || '~/.kube/config'
|
8
|
+
option :pod, default: nil
|
9
|
+
option :container, default: nil
|
10
|
+
option :namespace, default: nil
|
8
11
|
def connection(_instance_opts = nil)
|
9
12
|
@connection ||= TrainPlugins::TrainKubernetes::Connection.new(@options)
|
10
13
|
end
|
data/train-kubernetes.gemspec
CHANGED
@@ -44,6 +44,7 @@ Gem::Specification.new do |spec|
|
|
44
44
|
# Do not list inspec as a dependency of the train plugin.
|
45
45
|
|
46
46
|
# All plugins should mention train, > 1.4
|
47
|
-
|
47
|
+
# pinning k8s-ruby to 0.10.5 to avoid broken dry-type gem upgrades from k8s-ruby
|
48
|
+
spec.add_dependency 'k8s-ruby', '0.10.5'
|
48
49
|
spec.add_dependency 'train', '~> 3.0'
|
49
50
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: train-kubernetes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Geesaman
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: k8s-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.10.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.10.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: train
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- README.md
|
51
51
|
- lib/train-kubernetes.rb
|
52
52
|
- lib/train-kubernetes/connection.rb
|
53
|
+
- lib/train-kubernetes/kubectl_client.rb
|
53
54
|
- lib/train-kubernetes/platform.rb
|
54
55
|
- lib/train-kubernetes/transport.rb
|
55
56
|
- lib/train-kubernetes/version.rb
|
@@ -58,7 +59,7 @@ homepage: https://github.com/bgeesaman/train-kubernetes
|
|
58
59
|
licenses:
|
59
60
|
- Apache-2.0
|
60
61
|
metadata: {}
|
61
|
-
post_install_message:
|
62
|
+
post_install_message:
|
62
63
|
rdoc_options: []
|
63
64
|
require_paths:
|
64
65
|
- lib
|
@@ -73,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
74
|
- !ruby/object:Gem::Version
|
74
75
|
version: '0'
|
75
76
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
77
|
-
signing_key:
|
77
|
+
rubygems_version: 3.1.4
|
78
|
+
signing_key:
|
78
79
|
specification_version: 4
|
79
80
|
summary: Train Kubernetes
|
80
81
|
test_files: []
|