train-kubernetes 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +13 -0
- data/README.md +72 -0
- data/lib/train-kubernetes.rb +20 -0
- data/lib/train-kubernetes/connection.rb +39 -0
- data/lib/train-kubernetes/platform.rb +10 -0
- data/lib/train-kubernetes/transport.rb +13 -0
- data/lib/train-kubernetes/version.rb +10 -0
- data/train-kubernetes.gemspec +47 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d1bc478e5fb94a9b61701a3b318d9a423c9ae75c
|
4
|
+
data.tar.gz: f6361651906de111c3e3c889f80580ab83050a3e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3dc40490949058296af30fd97f749122d84a81d37603d033a6a350365ccab54054197c1abcae745bf3bbc58574d302fca1b3f6333f20c179145ff8631b32923c
|
7
|
+
data.tar.gz: 70fba3d1ffe3eb045a5c322089bd679612b88df3df147779530a9afda249da5178890e71f0d6a89c6b5f385ea3d50b4b00b07ed1f17989b4ea6c209ceb9d8309
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
# Remaining group is only used for development.
|
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'
|
13
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Kubernetes transport plugin for Chef Inspec Train
|
2
|
+
|
3
|
+
This plugin allows applications that rely on Train to communicate with the Kubernetes API. For example, InSpec uses this to perform compliance checks against any resource in the Kubernetes API. Train plugins are managed by InSpec CLI.
|
4
|
+
|
5
|
+
## Usage
|
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:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
describe k8sobjects(api: 'v1', type: 'pods', namespace: 'default', labelSelector: 'run=nginx') do
|
11
|
+
it { should exist }
|
12
|
+
...
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
describe k8sobjects(api: 'v1', type: 'namespaces', labelSelector: 'myns=prod') do
|
18
|
+
it { should exist }
|
19
|
+
...
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
describe k8sobject(api: 'v1', type: 'pod', namespace: 'default', name: 'my-pod') do
|
25
|
+
it { should exist }
|
26
|
+
its('name') { should eq 'my-pod' }
|
27
|
+
...
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Preconditions
|
32
|
+
|
33
|
+
- InSpec 3 or later.
|
34
|
+
- Ruby 2.4+
|
35
|
+
- You have set the env var KUBECONFIG or have a valid ~/.kube/config
|
36
|
+
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
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.
|
41
|
+
|
42
|
+
Simply run:
|
43
|
+
|
44
|
+
```
|
45
|
+
$ inspec plugin install train-kubernetes
|
46
|
+
```
|
47
|
+
|
48
|
+
Verify the plugin
|
49
|
+
|
50
|
+
```
|
51
|
+
$ inspec detect -t k8s://
|
52
|
+
|
53
|
+
== Platform Details
|
54
|
+
|
55
|
+
Name: k8s
|
56
|
+
Families: cloud, api
|
57
|
+
Release: 0.1.0
|
58
|
+
```
|
59
|
+
|
60
|
+
## Reporting Issues
|
61
|
+
|
62
|
+
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).
|
63
|
+
|
64
|
+
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.
|
65
|
+
|
66
|
+
### Development Process
|
67
|
+
|
68
|
+
If you wish to contribute to this plugin, please use the usual fork-branch-push-PR cycle. All functional changes need new tests, and bugfixes are expected to include a new test that demonstrates the bug.
|
69
|
+
|
70
|
+
### Reference Information
|
71
|
+
|
72
|
+
[Plugin Development](https://github.com/inspec/train/blob/master/docs/dev/plugins.md) is documented on the `train` project on GitHub.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file is known as the "entry point."
|
2
|
+
# This is the file Train will try to load if it
|
3
|
+
# thinks your plugin is needed.
|
4
|
+
|
5
|
+
# The *only* thing this file should do is setup the
|
6
|
+
# load path, then load plugin files.
|
7
|
+
|
8
|
+
# Next two lines simply add the path of the gem to the load path.
|
9
|
+
# This is not needed when being loaded as a gem; but when doing
|
10
|
+
# plugin development, you may need it. Either way, it's harmless.
|
11
|
+
libdir = File.dirname(__FILE__)
|
12
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
13
|
+
|
14
|
+
# It's traditional to keep your gem version in a separate file, so CI can find it easier.
|
15
|
+
require 'train-kubernetes/version'
|
16
|
+
|
17
|
+
# A train plugin has three components: Transport, Connection, and Platform.
|
18
|
+
# Transport acts as the glue.
|
19
|
+
require 'train-kubernetes/transport'
|
20
|
+
require 'train-kubernetes/platform'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'k8s-client'
|
2
|
+
require 'train-kubernetes/platform'
|
3
|
+
|
4
|
+
module TrainPlugins
|
5
|
+
module TrainKubernetes
|
6
|
+
class Connection < Train::Plugins::Transport::BaseConnection
|
7
|
+
include TrainPlugins::TrainKubernetes::Platform
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
super(options)
|
11
|
+
|
12
|
+
parse_kubeconfig
|
13
|
+
connect
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_accessor :client
|
17
|
+
|
18
|
+
def connect
|
19
|
+
@client.apis(prefetch_resources: true)
|
20
|
+
rescue Excon::Error::Socket => e
|
21
|
+
logger.error e.message
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
def uri
|
26
|
+
"kubernetes://#{unique_identifier}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def unique_identifier
|
30
|
+
@client.transport.server.gsub(%r{(http|https)\:\/\/}, '') || 'default'
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_kubeconfig
|
34
|
+
kubeconfig_file = @options[:kubeconfig] if @options[:kubeconfig]
|
35
|
+
@client = K8s::Client.config(K8s::Config.load_file(File.expand_path(kubeconfig_file)))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'train-kubernetes/connection'
|
2
|
+
|
3
|
+
module TrainPlugins
|
4
|
+
module TrainKubernetes
|
5
|
+
class Transport < Train.plugin(1)
|
6
|
+
name 'k8s'
|
7
|
+
option :kubeconfig, default: ENV['KUBECONFIG'] || '~/.kube/config'
|
8
|
+
def connection(_instance_opts = nil)
|
9
|
+
@connection ||= TrainPlugins::TrainKubernetes::Connection.new(@options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# This file exists simply to record the version number of the plugin.
|
2
|
+
# It is kept in a separate file, so that your gemspec can load it and
|
3
|
+
# learn the current version without loading the whole plugin. Also,
|
4
|
+
# many CI servers can update this file when "version bumping".
|
5
|
+
|
6
|
+
module TrainPlugins
|
7
|
+
module TrainKubernetes
|
8
|
+
VERSION = '0.1.1'.freeze
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# As plugins are usually packaged and distributed as a RubyGem,
|
2
|
+
# we have to provide a .gemspec file, which controls the gembuild
|
3
|
+
# and publish process. This is a fairly generic gemspec.
|
4
|
+
|
5
|
+
# It is traditional in a gemspec to dynamically load the current version
|
6
|
+
# from a file in the source tree. The next three lines make that happen.
|
7
|
+
# lib = File.expand_path('../lib', __FILE__)
|
8
|
+
lib = File.expand_path('lib', __dir__)
|
9
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
10
|
+
require 'train-kubernetes/version'
|
11
|
+
|
12
|
+
Gem::Specification.new do |spec|
|
13
|
+
# Importantly, all Train plugins must be prefixed with `train-`
|
14
|
+
spec.name = 'train-kubernetes'
|
15
|
+
|
16
|
+
# It is polite to namespace your plugin under TrainPlugins::YourPluginInCamelCase
|
17
|
+
spec.version = TrainPlugins::TrainKubernetes::VERSION
|
18
|
+
spec.authors = ['Brad Geesaman']
|
19
|
+
spec.email = ['bradgeesaman@gmail.com']
|
20
|
+
spec.summary = 'Train Kubernetes'
|
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'
|
24
|
+
|
25
|
+
# Though complicated-looking, this is pretty standard for a gemspec.
|
26
|
+
# It just filters what will actually be packaged in the gem (leaving
|
27
|
+
# out tests, etc)
|
28
|
+
spec.files = %w{
|
29
|
+
README.md train-kubernetes.gemspec Gemfile
|
30
|
+
} + Dir.glob(
|
31
|
+
'lib/**/*', File::FNM_DOTMATCH
|
32
|
+
).reject { |f| File.directory?(f) }
|
33
|
+
spec.require_paths = ['lib']
|
34
|
+
|
35
|
+
# If you rely on any other gems, list them here with any constraints.
|
36
|
+
# This is how `inspec plugin install` is able to manage your dependencies.
|
37
|
+
# For example, perhaps you are writing a thing that talks to AWS, and you
|
38
|
+
# want to ensure you have `aws-sdk` in a certain version.
|
39
|
+
|
40
|
+
# If you only need certain gems during development or testing, list
|
41
|
+
# them in Gemfile, not here.
|
42
|
+
# Do not list inspec as a dependency of the train plugin.
|
43
|
+
|
44
|
+
# All plugins should mention train, > 1.4
|
45
|
+
spec.add_dependency 'k8s-client', '0.10.0'
|
46
|
+
spec.add_dependency 'train', '~> 1.4'
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: train-kubernetes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brad Geesaman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: k8s-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: train
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
description: A Train "transport" plugin for Chef Inspec that allows testing of all
|
42
|
+
Kubernetes API resources
|
43
|
+
email:
|
44
|
+
- bradgeesaman@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- lib/train-kubernetes.rb
|
52
|
+
- lib/train-kubernetes/connection.rb
|
53
|
+
- lib/train-kubernetes/platform.rb
|
54
|
+
- lib/train-kubernetes/transport.rb
|
55
|
+
- lib/train-kubernetes/version.rb
|
56
|
+
- train-kubernetes.gemspec
|
57
|
+
homepage: https://github.com/bgeesaman/train-kubernetes
|
58
|
+
licenses:
|
59
|
+
- Apache-2.0
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.5.2.3
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Train Kubernetes
|
81
|
+
test_files: []
|