train-kubernetes 0.1.12 → 0.3.1

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: fcca2f4cc7de5b099cb5a3ee64e8ec7e935fdb986234d4ca9a3659d73efa874e
4
- data.tar.gz: 15006a25d2cc0a823e21025d0b9f02cdd75bcefcac6965a28b17735147c1a4df
3
+ metadata.gz: 5d870645522d279417d494da837ce3cd98d606ceab682d975c287c91a5ea1f95
4
+ data.tar.gz: c704898863a9bc0599efef8e19b7dba031a4c12a92d2f6346c68e33f5982eca3
5
5
  SHA512:
6
- metadata.gz: 17df60f7afdf0948ea15ce899b97b3aa33ba2173e87715c2b736783644a48aae037112188c570aab65f2cc3f40978e16c43c716c489623a7f556757b9204bfa6
7
- data.tar.gz: 47f38cc6b1b41873f411da7a6fc3be723d2ead3cf5a0b225367a5bd6bfe518a57eb06f1805e1557d708d8e3c161881a4b4dbc6747aaaf0e760573795c5a43f38
6
+ metadata.gz: f1ca28a6b208f9998018f69516fcc71d6551295cc28ad99e94193556123833758b3d3ea2c0f276f79520586f2cbf140eedd1dbd387049ecbb69230a8e63e73b6
7
+ data.tar.gz: ee7fc4808bcb55449fa73c5213624c5ac322774f0728abef2bbd2c0160a04c02c25880ac7b54b1d1c15cef7731bc88118a1dab7c01d6343846b8baf57595dd1d
data/Gemfile CHANGED
@@ -1,13 +1,19 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
5
  # Remaining group is only used for development.
6
6
  group :development do
7
- gem 'bundler'
8
- gem 'byebug'
9
- gem 'inspec', '>= 3.7.11' # We need InSpec for the test harness while developing.
10
- gem 'minitest'
11
- gem 'rake'
12
- gem 'rubocop', '~> 0.59'
7
+ gem "bundler"
8
+ gem "byebug"
9
+ gem "inspec", ">= 5.22.72" # We need InSpec for the test harness while developing.
10
+ gem "minitest"
11
+ gem "mocha"
12
+ gem "rake"
13
+ gem "m"
14
+ gem "rubocop"
15
+ gem "chefstyle"
16
+ gem "simplecov"
17
+ gem "simplecov_json_formatter"
18
+ gem "github_changelog_generator"
13
19
  end
data/README.md CHANGED
@@ -4,7 +4,7 @@ This plugin allows applications that rely on Train to communicate with the Kuber
4
4
 
5
5
  ## Usage
6
6
 
7
- When used in combination with the [InSpec Kubernetes Resource Pack](https://github.com/bgeesaman/inspec-k8s) you can validate the spec of any Kubernetes resource you have access to:
7
+ When used in combination with the [InSpec Kubernetes Resource Pack](https://github.com/inspec/inspec-k8s) you can validate the spec of any Kubernetes resource you have access to:
8
8
 
9
9
  ```ruby
10
10
  describe k8sobjects(api: 'v1', type: 'pods', namespace: 'default', labelSelector: 'run=nginx') do
@@ -41,9 +41,10 @@ Currently it supports only Linux based containers
41
41
  - Ruby 2.4+
42
42
  - You have set the env var KUBECONFIG or have a valid ~/.kube/config
43
43
 
44
-
45
44
  ## Installation
46
45
 
46
+ **_NOTE:_** **_The train-kubernetes plugin now comes included with InSpec 5.22.0 and later, and does not require installation separately._**
47
+
47
48
  Train plugins are distributed as gems. You may choose to manage the gem yourself, but if you are an InSpec user, InSPec can handle it for you.
48
49
 
49
50
  First, run:
@@ -82,18 +83,18 @@ Families: cloud, api
82
83
  Release: 0.1.3
83
84
  ```
84
85
 
85
- ## Troubleshooting
86
+ ## Troubleshooting (Only applicable for InSpec version 5.21.* and earlier)
86
87
 
87
88
  If you run into issues installing via `inspec plugin install train-kubernetes`, try:
88
89
 
89
90
  * Try running `gem install train-kubernetes` before `inspec plugin install train-kubernetes`.
90
- * Ensure the `~/.inspec/plugins.json` has `"0.1.3"` and not `"= 0.1.3"` for the `version` value. Modify it by hand if needed.
91
+ * Ensure the `~/.inspec/plugins.json` has `"0.1.3"` and not `"= 0.1.3"` for the `version` value. Modify it by hand if needed.
91
92
  * Ensure you can cleanly install the `k8s-ruby` gem version `0.10.4` or greater. e.g. `gem install k8s-ruby -v 0.10.4`
92
93
  * Ensure that only one version of the `excon` gem is installed. e.g. `gem list | grep excon`. If you see two versions, `gem uninstall excon` and remove the older version.
93
94
 
94
95
  ## Reporting Issues
95
96
 
96
- Bugs, typos, limitations, and frustrations are welcome to be reported through the [GitHub issues page for the train-kubernetes project](https://github.com/bgeesaman/train-kubernetes/issues).
97
+ Bugs, typos, limitations, and frustrations are welcome to be reported through the [GitHub issues page for the train-kubernetes project](https://github.com/inspec/train-kubernetes/issues).
97
98
 
98
99
  You may also ask questions in the #inspec channel of the Chef Community Slack team. However, for an issue to get traction, please report it as a github issue.
99
100
 
@@ -1,7 +1,7 @@
1
- require 'train'
2
- require 'k8s-ruby'
3
- require 'train-kubernetes/platform'
4
- require 'train-kubernetes/kubectl_client'
1
+ require "train"
2
+ require "k8s-ruby"
3
+ require "train-kubernetes/platform"
4
+ require "train-kubernetes/kubectl_client"
5
5
 
6
6
  module TrainPlugins
7
7
  module TrainKubernetes
@@ -10,7 +10,7 @@ module TrainPlugins
10
10
 
11
11
  def initialize(options)
12
12
  super(options)
13
- @pod = options[:pod] || options[:path]&.gsub('/', '')
13
+ @pod = options[:pod] || options[:path]&.gsub("/", "")
14
14
  @container = options[:container]
15
15
  @namespace = options[:namespace] || options[:host]
16
16
  parse_kubeconfig
@@ -31,7 +31,7 @@ module TrainPlugins
31
31
  end
32
32
 
33
33
  def unique_identifier
34
- @client.transport.server.gsub(%r{(http|https)\:\/\/}, '') || 'default'
34
+ @client.transport.server.gsub(%r{(http|https)\:\/\/}, "") || "default"
35
35
  end
36
36
 
37
37
  def parse_kubeconfig
@@ -47,7 +47,7 @@ module TrainPlugins
47
47
  KubectlClient.new(pod: opts[:pod] || pod,
48
48
  container: opts[:container] || container,
49
49
  namespace: opts[:namespace] || namespace)
50
- .execute(cmd)
50
+ .execute(cmd)
51
51
  end
52
52
 
53
53
  def file_via_connection(path, **args)
@@ -1,13 +1,13 @@
1
- require 'train/file/remote/linux'
2
- require 'train/extras/stat'
1
+ require "train/file/remote/linux"
2
+ require "train/extras/stat"
3
3
 
4
4
  module TrainPlugins
5
5
  module TrainKubernetes
6
6
  module File
7
7
  class Linux < ::Train::File::Remote::Linux
8
- def initialize(backend, path, follow_symlink = true, pod:, **args)
8
+ def initialize(backend, path, pod:, follow_symlink: true, **args)
9
9
  @backend = backend
10
- @path = path || ''
10
+ @path = path || ""
11
11
  @follow_symlink = follow_symlink
12
12
  @pod = pod
13
13
  @container = args[:container]
@@ -22,7 +22,7 @@ module TrainPlugins
22
22
 
23
23
  @content = @backend.run_command("cat #{@spath} || echo -n",
24
24
  { pod: pod, namespace: namespace, container: container })
25
- .stdout
25
+ .stdout
26
26
  return @content unless @content.empty?
27
27
 
28
28
  @content = nil if directory? || size.nil? || (size > 0)
@@ -30,7 +30,7 @@ module TrainPlugins
30
30
  end
31
31
 
32
32
  def content=(new_content)
33
- execute_result = @backend.run_command('base64 --help', { pod: pod, namespace: namespace, container: container })
33
+ execute_result = @backend.run_command("base64 --help", { pod: pod, namespace: namespace, container: container })
34
34
  if execute_result.exit_status != 0
35
35
  raise TransportError, "#{self.class} found no base64 binary for file writes"
36
36
  end
@@ -46,10 +46,10 @@ module TrainPlugins
46
46
 
47
47
  def exist?
48
48
  @exist ||= begin
49
- f = @follow_symlink ? '' : " || test -L #{@spath}"
49
+ f = @follow_symlink ? "" : " || test -L #{@spath}"
50
50
  @backend.run_command("test -e #{@spath}" + f,
51
51
  { pod: pod, namespace: namespace, container: container })
52
- .exit_status == 0
52
+ .exit_status == 0
53
53
  end
54
54
  end
55
55
 
@@ -70,8 +70,8 @@ module TrainPlugins
70
70
 
71
71
  @shallow_link_path ||=
72
72
  @backend.run_command("readlink #{@spath}", { pod: pod, namespace: namespace, container: container })
73
- .stdout
74
- .chomp
73
+ .stdout
74
+ .chomp
75
75
  end
76
76
 
77
77
  def stat
@@ -79,8 +79,8 @@ module TrainPlugins
79
79
  shell_escaped_path = @spath
80
80
  backend = @backend
81
81
  follow_symlink = @follow_symlink
82
- lstat = follow_symlink ? ' -L' : ''
83
- format = '--printf'
82
+ lstat = follow_symlink ? " -L" : ""
83
+ format = "--printf"
84
84
  res = backend.run_command("stat#{lstat} #{shell_escaped_path} 2>/dev/null #{format} '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'",
85
85
  { pod: pod, namespace: namespace, container: container })
86
86
  # ignore the exit_code: it is != 0 if selinux labels are not supported
@@ -92,7 +92,7 @@ module TrainPlugins
92
92
  tmask = fields[1].to_i(16)
93
93
  selinux = fields[8]
94
94
  ## selinux security context string not available on esxi
95
- selinux = nil if (selinux == '?') || (selinux == '(null)') || (selinux == 'C')
95
+ selinux = nil if (selinux == "?") || (selinux == "(null)") || (selinux == "C")
96
96
  {
97
97
  type: Train::Extras::Stat.find_type(tmask),
98
98
  mode: tmask & 07777,
@@ -102,7 +102,7 @@ module TrainPlugins
102
102
  gid: fields[5].to_i,
103
103
  mtime: fields[7].to_i,
104
104
  size: fields[0].to_i,
105
- selinux_label: selinux
105
+ selinux_label: selinux,
106
106
  }
107
107
  end
108
108
  end
@@ -118,13 +118,13 @@ module TrainPlugins
118
118
  def user_permissions
119
119
  return {} unless exist?
120
120
 
121
- skip_reource '`user_permissions` is not supported on your Linux Containers yet.'
121
+ skip_reource "`user_permissions` is not supported on your Linux Containers yet."
122
122
  end
123
123
 
124
124
  def inherited?
125
125
  return false unless exist?
126
126
 
127
- skip_resource '`inherited?` is not supported on your Linux Containers yet.'
127
+ skip_resource "`inherited?` is not supported on your Linux Containers yet."
128
128
  end
129
129
 
130
130
  private
@@ -133,10 +133,10 @@ module TrainPlugins
133
133
  def read_target_path
134
134
  full_path = @backend.run_command("readlink -n #{@spath} -f",
135
135
  { pod: pod, namespace: namespace, container: container })
136
- .stdout
136
+ .stdout
137
137
  # Needed for some OSes like OSX that returns relative path
138
138
  # when the link and target are in the same directory
139
- if !full_path.start_with?('/') && full_path != ''
139
+ if !full_path.start_with?("/") && full_path != ""
140
140
  full_path = ::File.expand_path("../#{full_path}", @spath)
141
141
  end
142
142
  full_path
@@ -1,5 +1,5 @@
1
- require 'inspec/resources/file'
2
- require 'inspec/exceptions'
1
+ require "inspec/resources/file"
2
+ require "inspec/exceptions"
3
3
 
4
4
  module TrainPlugins
5
5
  module TrainKubernetes
@@ -15,8 +15,8 @@ module TrainPlugins
15
15
  def find_utility_or_error(utility_name)
16
16
  %W(/usr/sbin/#{utility_name} /sbin/#{utility_name} /usr/bin/#{utility_name} /bin/#{utility_name} #{utility_name}).each do |cmd|
17
17
  if inspec.backend
18
- .run_command("sh -c 'type \"#{cmd}\"'", { pod: pod, container: container, namespace: namespace })
19
- .exit_status.to_i == 0
18
+ .run_command("sh -c 'type \"#{cmd}\"'", { pod: pod, container: container, namespace: namespace })
19
+ .exit_status.to_i == 0
20
20
  return cmd
21
21
  end
22
22
  end
@@ -27,7 +27,7 @@ module TrainPlugins
27
27
  def is_immutable?
28
28
  # Check if lsattr is available. In general, all linux system has lsattr & chattr
29
29
  # This logic check is valid for immutable flag set with chattr
30
- utility = find_utility_or_error('lsattr')
30
+ utility = find_utility_or_error("lsattr")
31
31
 
32
32
  utility_cmd = inspec.backend.run_command("#{utility} #{file_path}",
33
33
  { pod: pod, container: container, namespace: namespace })
@@ -37,7 +37,7 @@ module TrainPlugins
37
37
  # General output for lsattr file_name is:
38
38
  # ----i---------e----- file_name
39
39
  # The fifth char resembles the immutable flag. Total 20 flags are allowed.
40
- lsattr_info = utility_cmd.stdout.strip.squeeze(' ')
40
+ lsattr_info = utility_cmd.stdout.strip.squeeze(" ")
41
41
  lsattr_info =~ /^.{4}i.{15} .*/
42
42
  end
43
43
 
@@ -1,12 +1,12 @@
1
- require 'mixlib/shellout'
2
- require 'train/extras'
1
+ require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
2
+ require "train/extras"
3
3
 
4
4
  module TrainPlugins
5
5
  module TrainKubernetes
6
6
  class KubectlClient
7
7
  attr_reader :pod, :container, :namespace
8
8
 
9
- DEFAULT_NAMESPACE = 'default'.freeze
9
+ DEFAULT_NAMESPACE = "default".freeze
10
10
 
11
11
  def initialize(pod:, namespace: nil, container: nil)
12
12
  @pod = pod
@@ -20,7 +20,7 @@ module TrainPlugins
20
20
  res = shell.run_command
21
21
  Train::Extras::CommandResult.new(res.stdout, res.stderr, res.exitstatus)
22
22
  rescue Errno::ENOENT => _e
23
- Train::Extras::CommandResult.new('', '', 1)
23
+ Train::Extras::CommandResult.new("", "", 1)
24
24
  end
25
25
 
26
26
  private
@@ -30,12 +30,12 @@ module TrainPlugins
30
30
  end
31
31
 
32
32
  def build_instruction(command, stdin, _tty)
33
- ['kubectl exec'].tap do |arr|
34
- arr << '--stdin' if stdin
33
+ ["kubectl exec"].tap do |arr|
34
+ arr << "--stdin" if stdin
35
35
  arr << pod if pod
36
- arr << '-n'
36
+ arr << "-n"
37
37
  arr << namespace
38
- arr << '--'
38
+ arr << "--"
39
39
  arr << command
40
40
  end.join("\s")
41
41
  end
@@ -2,8 +2,8 @@ module TrainPlugins
2
2
  module TrainKubernetes
3
3
  module Platform
4
4
  def platform
5
- Train::Platforms.name('k8s').in_family('cloud')
6
- force_platform!('k8s', release: TrainPlugins::TrainKubernetes::VERSION)
5
+ Train::Platforms.name("k8s").in_family("cloud")
6
+ force_platform!("k8s", release: TrainPlugins::TrainKubernetes::VERSION)
7
7
  end
8
8
  end
9
9
  end
@@ -1,10 +1,10 @@
1
- require 'train-kubernetes/connection'
1
+ require "train-kubernetes/connection"
2
2
 
3
3
  module TrainPlugins
4
4
  module TrainKubernetes
5
5
  class Transport < Train.plugin(1)
6
- name 'k8s'
7
- option :kubeconfig, default: ENV['KUBECONFIG'] || '~/.kube/config'
6
+ name "k8s"
7
+ option :kubeconfig, default: ENV["KUBECONFIG"] || "~/.kube/config"
8
8
  option :pod, default: nil
9
9
  option :container, default: nil
10
10
  option :namespace, default: nil
@@ -5,6 +5,6 @@
5
5
 
6
6
  module TrainPlugins
7
7
  module TrainKubernetes
8
- VERSION = '0.1.12'.freeze
8
+ VERSION = "0.3.1".freeze
9
9
  end
10
10
  end
@@ -12,10 +12,10 @@ libdir = File.dirname(__FILE__)
12
12
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
13
13
 
14
14
  # It's traditional to keep your gem version in a separate file, so CI can find it easier.
15
- require 'train-kubernetes/version'
15
+ require "train-kubernetes/version"
16
16
 
17
17
  # A train plugin has three components: Transport, Connection, and Platform.
18
18
  # Transport acts as the glue.
19
- require 'train-kubernetes/transport'
20
- require 'train-kubernetes/platform'
21
- require 'train-kubernetes/file/linux'
19
+ require "train-kubernetes/transport"
20
+ require "train-kubernetes/platform"
21
+ require "train-kubernetes/file/linux"
@@ -5,24 +5,24 @@
5
5
  # It is traditional in a gemspec to dynamically load the current version
6
6
  # from a file in the source tree. The next three lines make that happen.
7
7
  # lib = File.expand_path('../lib', __FILE__)
8
- lib = File.expand_path('lib', __dir__)
8
+ lib = File.expand_path("lib", __dir__)
9
9
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
10
- require 'train-kubernetes/version'
10
+ require "train-kubernetes/version"
11
11
 
12
12
  Gem::Specification.new do |spec|
13
13
  # Importantly, all Train plugins must be prefixed with `train-`
14
- spec.name = 'train-kubernetes'
14
+ spec.name = "train-kubernetes"
15
15
 
16
16
  # It is polite to namespace your plugin under TrainPlugins::YourPluginInCamelCase
17
17
  spec.version = TrainPlugins::TrainKubernetes::VERSION
18
- spec.authors = ['Brad Geesaman']
19
- spec.email = ['bradgeesaman@gmail.com']
20
- spec.summary = 'Train Kubernetes'
18
+ spec.authors = ["Brad Geesaman"]
19
+ spec.email = ["bradgeesaman@gmail.com"]
20
+ spec.summary = "Train Kubernetes"
21
21
  spec.description = 'A Train "transport" plugin for Chef Inspec that allows testing of all Kubernetes API resources'
22
- spec.homepage = 'https://github.com/bgeesaman/train-kubernetes'
23
- spec.license = 'Apache-2.0'
22
+ spec.homepage = "https://github.com/inspec/train-kubernetes"
23
+ spec.license = "Apache-2.0"
24
24
 
25
- spec.required_ruby_version = '>= 2.4'
25
+ spec.required_ruby_version = ">= 3.1"
26
26
 
27
27
  # Though complicated-looking, this is pretty standard for a gemspec.
28
28
  # It just filters what will actually be packaged in the gem (leaving
@@ -30,9 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.files = %w{
31
31
  README.md train-kubernetes.gemspec Gemfile
32
32
  } + Dir.glob(
33
- 'lib/**/*', File::FNM_DOTMATCH
33
+ "lib/**/*", File::FNM_DOTMATCH
34
34
  ).reject { |f| File.directory?(f) }
35
- spec.require_paths = ['lib']
35
+ spec.require_paths = ["lib"]
36
36
 
37
37
  # If you rely on any other gems, list them here with any constraints.
38
38
  # This is how `inspec plugin install` is able to manage your dependencies.
@@ -44,7 +44,9 @@ 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
- # pinning k8s-ruby to 0.10.5 to avoid broken dry-type gem upgrades from k8s-ruby
48
- spec.add_dependency 'k8s-ruby', '~> 0.14.0'
49
- spec.add_dependency 'train', '~> 3.0'
47
+ # pinning k8s-ruby to greater than 0.17.0 since it has support for Ruby version 3.4
48
+ # pinning k8s-ruby to be greater than 0.17.2 since it removes the breaking change for
49
+ # windows builds introduced in 0.17.1
50
+ spec.add_dependency "k8s-ruby", ">= 0.17.2"
51
+ spec.add_dependency "train", "~> 3.0"
50
52
  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.12
4
+ version: 0.3.1
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: 2023-04-14 00:00:00.000000000 Z
11
+ date: 2025-04-10 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.14.0
19
+ version: 0.17.2
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.14.0
26
+ version: 0.17.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: train
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,11 +58,11 @@ files:
58
58
  - lib/train-kubernetes/transport.rb
59
59
  - lib/train-kubernetes/version.rb
60
60
  - train-kubernetes.gemspec
61
- homepage: https://github.com/bgeesaman/train-kubernetes
61
+ homepage: https://github.com/inspec/train-kubernetes
62
62
  licenses:
63
63
  - Apache-2.0
64
64
  metadata: {}
65
- post_install_message:
65
+ post_install_message:
66
66
  rdoc_options: []
67
67
  require_paths:
68
68
  - lib
@@ -70,15 +70,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: '2.4'
73
+ version: '3.1'
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.3.7
81
- signing_key:
80
+ rubygems_version: 3.3.27
81
+ signing_key:
82
82
  specification_version: 4
83
83
  summary: Train Kubernetes
84
84
  test_files: []