train-kubernetes 0.1.6 → 0.1.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: faf420c22d9eb580f5344f04af243d21b734195305b653ac60588a200b986557
4
- data.tar.gz: 631dbf7f1b8006cf0d41b4e11457e7821283b7d96bdecbbfbc1f3b4a2d5128bf
3
+ metadata.gz: 7e4bbb998822377221a31b8839373f73d298d6f2bd4226300ff8428742ca247c
4
+ data.tar.gz: e87a4add57561718dc7780d20aa0741de23e9bc615108dd139609377edb4d05b
5
5
  SHA512:
6
- metadata.gz: 54cefa2bf1f7e85fcd8a018dff9093c1de1a7bb20bceb123c595e439741f969baba9484f735f3bad7d39ad1a3e4d50cef1dea0265d064a257021801d1dc820d4
7
- data.tar.gz: 6b754a9da1e579667ee32b48f0b8a208a4ead1da47c5333e53d2ff95cc929a31792ad13368b27dd3ca170cb3050d11350801c3af196700d15f59425415152ac3
6
+ metadata.gz: dfd9ca8003441da0bb8abd13f6a5ceae755239f406201b76d94ec2088a07ea12cc29e2fbe0a7132e4e6745910752823c9753a3b17585b39de62e1a5527192c6c
7
+ data.tar.gz: c50d9c99fe60b9b51b71b789f7c233815cf0391a89d8ffa6bc2faaae3f5f74e416211400b02e273da1f8c4348f4e749ce368eba5148acefa91faf43a533610fc
data/README.md CHANGED
@@ -62,7 +62,7 @@ If it has the version set to `"= 0.1.3"`, modify it to `"0.1.3"` and save the fi
62
62
  Verify the plugin:
63
63
 
64
64
  ```
65
- inspec plugins list
65
+ inspec plugin list
66
66
  ```
67
67
 
68
68
  ```
@@ -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
@@ -5,6 +5,6 @@
5
5
 
6
6
  module TrainPlugins
7
7
  module TrainKubernetes
8
- VERSION = '0.1.6'.freeze
8
+ VERSION = '0.1.10'.freeze
9
9
  end
10
10
  end
@@ -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
- spec.add_dependency 'k8s-ruby', '~> 0.10'
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.6
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: 2020-12-08 00:00:00.000000000 Z
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: '0.10'
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: '0.10'
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.0.8
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: []