kubert 0.1.1 → 0.1.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/README.md +12 -6
- data/lib/kubert.rb +30 -19
- data/lib/kubert/cli.rb +33 -22
- data/lib/kubert/deployment.rb +27 -7
- data/lib/kubert/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11a4977bc3bcc125b5c7d631fde64ad7d4bcd857
|
4
|
+
data.tar.gz: 257585ae70feb31f2896193dab4ac09041100a95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0401b4d08e0b7cfb568368a8779c810e20fe466163a394a485afed04327b5855eed089769e997ae5573facce97531ac9bd4dec474b69f6d5c083a9d8e376a9db
|
7
|
+
data.tar.gz: 7f9705992329e778645ea4b0df82db81389b321bf7d3b81a018c81b786b44ea398ae904f84431fbab8f6e7bbfbe19d518013237462f3daab88e40fa6289e42cc
|
data/README.md
CHANGED
@@ -6,20 +6,23 @@
|
|
6
6
|
|
7
7
|
Kubert assumes your kubernetes config file lives in `~/.kube/config` and reads that to talk to the cluster.
|
8
8
|
|
9
|
-
|
9
|
+
Compile and Rollback actions are only available if using ky for generating your deployment yml. Kubert checks the ky config for several values (procfile_path, deployment and image at present) to determine if ky is active and only defines compile/rollback commands if they are all configured.
|
10
|
+
|
11
|
+
ky manages the scope of a deployment as a group of related, seperate kubernetes deployments. Typing `ky example` at the console will import example ky configuration, including kubert configuration. You may ignore/delete most of this if not using ky itself, and focus primarily on the kubert section of the yml for a few pieces of kubert configuration... the important ones are these:
|
10
12
|
|
11
13
|
```
|
12
14
|
project_name: "my-project"
|
13
15
|
kubert:
|
14
16
|
contexts:
|
15
|
-
staging: staging.example.com
|
17
|
+
staging: staging.example.com # as many values here as you have distinct clusters in kubeconfig
|
16
18
|
prod: production.example.com
|
17
|
-
excluded_deployments: [sanitize, migration]
|
19
|
+
excluded_deployments: [sanitize, migration] # optional/possibly uncommon use case, see below
|
18
20
|
default_environment: stg
|
19
|
-
default_namespace: default
|
21
|
+
default_namespace: default # defaults to same as default_environment, specify if different
|
20
22
|
task_pod: console
|
21
|
-
console_command: rails c
|
22
|
-
command_prefix: bundle exec
|
23
|
+
console_command: rails c # optional, but no console command unless present
|
24
|
+
command_prefix: bundle exec # optional
|
25
|
+
kube_config_path: ~/.kube/config # No need to specify unless you store file elsewhere
|
23
26
|
```
|
24
27
|
|
25
28
|
The project name is used by ky and assumes a metadata namespace for your app deployments in the format of `{{project_name}}-{{deployment_name}}`, so as long as your deployments obey this pattern it should be usable for you without ky.
|
@@ -33,6 +36,8 @@ Task pod is what is used for running consoles and executing tasks. If not defin
|
|
33
36
|
|
34
37
|
console_command and console_prefix are for opening a REPL and for prefixing all task commands with a common prefix
|
35
38
|
|
39
|
+
kube_config_path is probably not needed unless your kubernetes config is located elsewhere
|
40
|
+
|
36
41
|
###Example usage
|
37
42
|
```
|
38
43
|
$ kubert console # open a console on a task_pod
|
@@ -43,6 +48,7 @@ $ kubert context # print current kubectl context/cluster
|
|
43
48
|
$ kubert deploy -e prd # perform a production deployment
|
44
49
|
$ kubert rollback -e prd # rollback a production deployment
|
45
50
|
$ kubert deploy # perform a deployment to the default environment
|
51
|
+
$ kubert logs web # tail the logs from all web pods and interleave together
|
46
52
|
```
|
47
53
|
|
48
54
|
A valid url may also be used in place of a file path for input.
|
data/lib/kubert.rb
CHANGED
@@ -6,50 +6,61 @@ require_relative "kubert/pods"
|
|
6
6
|
require_relative "kubert/deployment"
|
7
7
|
|
8
8
|
module Kubert
|
9
|
-
|
10
|
-
|
9
|
+
extend self
|
10
|
+
DEFAULT_KUBE_CONFIG_PATH = '~/.kube/config'
|
11
|
+
def kube_config
|
12
|
+
@kube_config ||= Kubeclient::Config.read(File.expand_path(kube_config_path))
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
15
|
+
def kube_config_path
|
16
|
+
configuration[:kube_config_path] || DEFAULT_KUBE_CONFIG_PATH
|
17
|
+
end
|
18
|
+
|
19
|
+
def contexts
|
14
20
|
configuration[:contexts] || []
|
15
21
|
end
|
16
22
|
|
17
|
-
def
|
23
|
+
def task_pod
|
18
24
|
configuration[:task_pod] || random_pod_type
|
19
25
|
end
|
20
26
|
|
21
|
-
def
|
27
|
+
def default_environment
|
22
28
|
configuration[:default_environment]
|
23
29
|
end
|
24
30
|
|
25
|
-
def
|
31
|
+
def default_namespace
|
26
32
|
configuration[:default_namespace] || configuration[:default_environment]
|
27
33
|
end
|
28
34
|
|
29
|
-
def
|
35
|
+
def context
|
30
36
|
kube_config.contexts.select {|c| kube_config.context.api_endpoint.match(c) }
|
31
37
|
end
|
32
38
|
|
33
|
-
def
|
39
|
+
def console_command
|
34
40
|
Array(configuration[:console_command] && configuration[:console_command].split(" "))
|
35
41
|
end
|
36
42
|
|
37
|
-
def
|
43
|
+
def command_prefix
|
38
44
|
configuration[:command_prefix]
|
39
45
|
end
|
40
46
|
|
41
|
-
def
|
47
|
+
def excluded_deployments
|
42
48
|
configuration[:excluded_deployments] || []
|
43
49
|
end
|
44
50
|
|
45
|
-
def
|
46
|
-
@
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
def ky_configuration
|
52
|
+
@ky_configuration ||= KY::Configuration.new
|
53
|
+
end
|
54
|
+
|
55
|
+
def ky_active?
|
56
|
+
ky_configuration[:image] && ky_configuration[:deployment] && ky_configuration[:procfile_path]
|
57
|
+
end
|
58
|
+
|
59
|
+
def configuration
|
60
|
+
@config ||= (ky_configuration[:kubert] || {}).merge(project_name: ky_configuration[:project_name])
|
50
61
|
end
|
51
62
|
|
52
|
-
def
|
63
|
+
def client
|
53
64
|
@client ||= begin
|
54
65
|
Kubeclient::Client.new(
|
55
66
|
kube_config.context.api_endpoint,
|
@@ -64,7 +75,7 @@ module Kubert
|
|
64
75
|
|
65
76
|
private
|
66
77
|
|
67
|
-
def
|
78
|
+
def random_pod_type
|
68
79
|
Kubert.client.get_pods(namespace: current_namespace)
|
69
80
|
.sample
|
70
81
|
.metadata
|
@@ -73,8 +84,8 @@ module Kubert
|
|
73
84
|
.first
|
74
85
|
end
|
75
86
|
|
76
|
-
def
|
77
|
-
|
87
|
+
def current_namespace
|
88
|
+
ky_configuration[:namespace] ||
|
78
89
|
default_namespace ||
|
79
90
|
(raise "MUST DEFINE A NAMESPACE FOR POD OPERATIONS, ky namespace, default_namespace or default_environment")
|
80
91
|
end
|
data/lib/kubert/cli.rb
CHANGED
@@ -3,6 +3,12 @@ require 'thor'
|
|
3
3
|
module Kubert
|
4
4
|
class Cli < Thor
|
5
5
|
|
6
|
+
`hash kubectl 2>/dev/null;`
|
7
|
+
unless $?.success?
|
8
|
+
puts "Please install kubectl prior to kubert usage"
|
9
|
+
exit $?.to_i
|
10
|
+
end
|
11
|
+
|
6
12
|
desc "list pod_type", "Display a list of one type of Pod, only Running by default"
|
7
13
|
def list(pod_type, status=:running)
|
8
14
|
puts Pods.list(pod_type, status)
|
@@ -20,9 +26,11 @@ module Kubert
|
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
if Kubert.console_command.any?
|
30
|
+
desc "console", "Connect to a console on a task pod"
|
31
|
+
def console
|
32
|
+
execute(*Kubert.console_command)
|
33
|
+
end
|
26
34
|
end
|
27
35
|
|
28
36
|
desc "execute command", "Connect to a task pod and run the specified command (with #{Kubert.command_prefix} prefix)"
|
@@ -35,26 +43,29 @@ module Kubert
|
|
35
43
|
Pods.logs(pod_type, status)
|
36
44
|
end
|
37
45
|
|
38
|
-
desc "deploy", "Perform a deployment"
|
39
|
-
method_option :namespace, type: :string, aliases: "-n"
|
40
|
-
method_option :environment, type: :string, aliases: "-e"
|
41
|
-
method_option :image_tag, type: :string, aliases: "-t"
|
42
|
-
method_option :configmap_path, type: :string, aliases: "-c"
|
43
|
-
method_option :secrets_path, type: :string, aliases: "-s"
|
44
|
-
method_option :output_dir, type: :string, aliases: "-o"
|
45
|
-
def deploy
|
46
|
-
Deployment.perform(options)
|
47
|
-
end
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
47
|
+
if Kubert.ky_active?
|
48
|
+
desc "deploy", "Perform a deployment"
|
49
|
+
method_option :namespace, type: :string, aliases: "-n"
|
50
|
+
method_option :environment, type: :string, aliases: "-e"
|
51
|
+
method_option :image_tag, type: :string, aliases: "-t"
|
52
|
+
method_option :configmap_path, type: :string, aliases: "-c"
|
53
|
+
method_option :secrets_path, type: :string, aliases: "-s"
|
54
|
+
method_option :output_dir, type: :string, aliases: "-o"
|
55
|
+
def deploy
|
56
|
+
Deployment.perform(options)
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "rollback", "Rollback a deployment, reverse of a kubert deploy command with same flags"
|
60
|
+
method_option :namespace, type: :string, aliases: "-n"
|
61
|
+
method_option :environment, type: :string, aliases: "-e"
|
62
|
+
method_option :image_tag, type: :string, aliases: "-t"
|
63
|
+
method_option :configmap_path, type: :string, aliases: "-c"
|
64
|
+
method_option :secrets_path, type: :string, aliases: "-s"
|
65
|
+
method_option :output_dir, type: :string, aliases: "-o"
|
66
|
+
def rollback
|
67
|
+
Deployment.rollback(options)
|
68
|
+
end
|
58
69
|
end
|
59
70
|
|
60
71
|
Kubert.contexts.each do |context_name, context_endpoint|
|
data/lib/kubert/deployment.rb
CHANGED
@@ -8,7 +8,7 @@ module Kubert
|
|
8
8
|
new(options).rollback
|
9
9
|
end
|
10
10
|
|
11
|
-
attr_reader :project_name, :deployments, :options
|
11
|
+
attr_reader :project_name, :deployments, :options, :operation_statuses
|
12
12
|
def initialize(options, project_name= Kubert.configuration[:project_name])
|
13
13
|
@project_name = project_name
|
14
14
|
@deployments = []
|
@@ -16,18 +16,22 @@ module Kubert
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def rollback
|
19
|
-
confirm
|
19
|
+
confirm :rollback do
|
20
20
|
compilation.deploy_generation.proc_commands.keys.each do |deployment_name|
|
21
|
-
`kubectl rollout status deployment/#{deployment_name} #{namespace_flag}` unless excluded?(deployment_name)
|
21
|
+
perform_with_status { `kubectl rollout status deployment/#{deployment_name} #{namespace_flag}` } unless excluded?(deployment_name)
|
22
22
|
end
|
23
|
+
report_status(:rollback)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def perform
|
27
|
-
confirm
|
28
|
+
confirm :deploy do
|
29
|
+
perform_with_status { `kubectl apply -f #{output_dir}/#{Kubert.configuration[:project_name]}#{KY::Manipulation::CONFIG_SUFFIX}` }
|
30
|
+
perform_with_status {`kubectl apply -f #{output_dir}/#{Kubert.configuration[:project_name]}#{KY::Manipulation::SECRET_SUFFIX}` }
|
28
31
|
compilation.deploy_generation.to_h.each do |deployment_file, _template_hash|
|
29
|
-
`kubectl apply -f #{deployment_file}` unless excluded?(deployment_file)
|
32
|
+
perform_with_status { `kubectl apply -f #{deployment_file}` unless excluded?(deployment_file) }
|
30
33
|
end
|
34
|
+
report_status(:deploy)
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
@@ -39,16 +43,28 @@ module Kubert
|
|
39
43
|
|
40
44
|
def confirm(action)
|
41
45
|
unless ENV['SKIP_CONFIRMATION']
|
42
|
-
puts "Press any key to confirm, ctl-c to abort: #{action.upcase} on #{Kubert.context}"
|
43
|
-
|
46
|
+
puts "Press any key to confirm, ctl-c to abort: #{action.to_s.upcase} on #{Kubert.context}"
|
47
|
+
$stdin.gets
|
44
48
|
end
|
45
49
|
yield
|
46
50
|
end
|
47
51
|
|
52
|
+
def report_status(action)
|
53
|
+
puts "All #{action} steps ran successfully"
|
54
|
+
end
|
55
|
+
|
56
|
+
def perform_with_status
|
57
|
+
output = yield
|
58
|
+
abort(output) unless $?.success?
|
59
|
+
end
|
60
|
+
|
48
61
|
def options_with_defaults
|
49
62
|
(options[:environment] ? options : options.merge(environment: Kubert.default_environment)).with_indifferent_access
|
50
63
|
end
|
51
64
|
|
65
|
+
def ky_configuration
|
66
|
+
@ky_configuration ||= compilation.deploy_generation.configuration.configuration.with_indifferent_access
|
67
|
+
end
|
52
68
|
|
53
69
|
def namespace_flag
|
54
70
|
return unless compilation.configuration[:environment]
|
@@ -58,5 +74,9 @@ module Kubert
|
|
58
74
|
def excluded?(deployment_info)
|
59
75
|
Kubert.excluded_deployments.any? {|deploy| deployment_info.match(deploy) }
|
60
76
|
end
|
77
|
+
|
78
|
+
def output_dir
|
79
|
+
compilation.deploy_generation.full_output_dir
|
80
|
+
end
|
61
81
|
end
|
62
82
|
end
|
data/lib/kubert/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Glusman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|