kubernetes-deploy 0.6.6 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/exe/kubernetes-deploy +21 -13
  3. data/exe/kubernetes-restart +7 -4
  4. data/exe/kubernetes-run +14 -10
  5. data/kubernetes-deploy.gemspec +1 -0
  6. data/lib/kubernetes-deploy.rb +3 -2
  7. data/lib/kubernetes-deploy/deferred_summary_logging.rb +87 -0
  8. data/lib/kubernetes-deploy/ejson_secret_provisioner.rb +18 -20
  9. data/lib/kubernetes-deploy/formatted_logger.rb +42 -0
  10. data/lib/kubernetes-deploy/kubectl.rb +21 -8
  11. data/lib/kubernetes-deploy/kubernetes_resource.rb +111 -52
  12. data/lib/kubernetes-deploy/kubernetes_resource/bugsnag.rb +3 -11
  13. data/lib/kubernetes-deploy/kubernetes_resource/cloudsql.rb +7 -14
  14. data/lib/kubernetes-deploy/kubernetes_resource/config_map.rb +5 -9
  15. data/lib/kubernetes-deploy/kubernetes_resource/deployment.rb +31 -14
  16. data/lib/kubernetes-deploy/kubernetes_resource/ingress.rb +1 -13
  17. data/lib/kubernetes-deploy/kubernetes_resource/persistent_volume_claim.rb +2 -9
  18. data/lib/kubernetes-deploy/kubernetes_resource/pod.rb +48 -22
  19. data/lib/kubernetes-deploy/kubernetes_resource/pod_disruption_budget.rb +5 -9
  20. data/lib/kubernetes-deploy/kubernetes_resource/pod_template.rb +5 -9
  21. data/lib/kubernetes-deploy/kubernetes_resource/redis.rb +9 -15
  22. data/lib/kubernetes-deploy/kubernetes_resource/service.rb +9 -10
  23. data/lib/kubernetes-deploy/resource_watcher.rb +22 -10
  24. data/lib/kubernetes-deploy/restart_task.rb +12 -7
  25. data/lib/kubernetes-deploy/runner.rb +163 -110
  26. data/lib/kubernetes-deploy/runner_task.rb +22 -19
  27. data/lib/kubernetes-deploy/version.rb +1 -1
  28. metadata +18 -4
  29. data/lib/kubernetes-deploy/logger.rb +0 -45
  30. data/lib/kubernetes-deploy/ui_helpers.rb +0 -19
@@ -2,14 +2,11 @@
2
2
  require 'tempfile'
3
3
 
4
4
  require 'kubernetes-deploy/kubeclient_builder'
5
- require 'kubernetes-deploy/ui_helpers'
6
5
  require 'kubernetes-deploy/kubectl'
7
6
 
8
7
  module KubernetesDeploy
9
8
  class RunnerTask
10
9
  include KubeclientBuilder
11
- include Kubectl
12
- include UIHelpers
13
10
 
14
11
  class FatalTaskRunError < FatalDeploymentError; end
15
12
  class TaskTemplateMissingError < FatalDeploymentError
@@ -18,27 +15,36 @@ module KubernetesDeploy
18
15
  end
19
16
  end
20
17
 
21
- def initialize(namespace:, context:, logger: KubernetesDeploy.logger)
18
+ def initialize(namespace:, context:, logger:)
22
19
  @logger = logger
23
20
  @namespace = namespace
24
21
  @kubeclient = build_v1_kubeclient(context)
25
22
  @context = context
26
23
  end
27
24
 
28
- def run(task_template:, entrypoint:, args:, env_vars: [])
29
- phase_heading("Validating configuration")
25
+ def run(*args)
26
+ run!(*args)
27
+ true
28
+ rescue FatalDeploymentError => error
29
+ @logger.fatal "#{error.class}: #{error.message}"
30
+ false
31
+ end
32
+
33
+ def run!(task_template:, entrypoint:, args:, env_vars: [])
34
+ @logger.reset
35
+ @logger.phase_heading("Validating configuration")
30
36
  validate_configuration(task_template, args)
31
37
 
32
- phase_heading("Fetching task template")
38
+ @logger.phase_heading("Fetching task template")
33
39
  raw_template = get_template(task_template)
34
40
 
35
- phase_heading("Constructing final pod specification")
41
+ @logger.phase_heading("Constructing final pod specification")
36
42
  rendered_template = build_pod_template(raw_template, entrypoint, args, env_vars)
37
43
 
38
44
  validate_pod_spec(rendered_template)
39
45
 
40
- phase_heading("Creating pod")
41
- KubernetesDeploy.logger.info("Starting task runner pod: '#{rendered_template.metadata.name}'")
46
+ @logger.phase_heading("Creating pod")
47
+ @logger.info("Starting task runner pod: '#{rendered_template.metadata.name}'")
42
48
  @kubeclient.create_pod(rendered_template)
43
49
  end
44
50
 
@@ -60,7 +66,7 @@ module KubernetesDeploy
60
66
  end
61
67
 
62
68
  begin
63
- @kubeclient.get_namespace(@namespace)
69
+ @kubeclient.get_namespace(@namespace) if @namespace.present?
64
70
  rescue KubeException => e
65
71
  errors << if e.error_code == 404
66
72
  "Namespace was not found"
@@ -73,7 +79,7 @@ module KubernetesDeploy
73
79
  end
74
80
 
75
81
  def get_template(template_name)
76
- KubernetesDeploy.logger.info(
82
+ @logger.info(
77
83
  "Fetching task runner pod template: '#{template_name}' in namespace: '#{@namespace}'"
78
84
  )
79
85
 
@@ -89,7 +95,7 @@ module KubernetesDeploy
89
95
  end
90
96
 
91
97
  def build_pod_template(base_template, entrypoint, args, env_vars)
92
- KubernetesDeploy.logger.info("Rendering template for task runner pod")
98
+ @logger.info("Rendering template for task runner pod")
93
99
 
94
100
  rendered_template = base_template.dup
95
101
  rendered_template.kind = 'Pod'
@@ -112,7 +118,7 @@ module KubernetesDeploy
112
118
 
113
119
  unique_name = rendered_template.metadata.name + "-" + SecureRandom.hex(8)
114
120
 
115
- KubernetesDeploy.logger.warn("Name is too long, using '#{unique_name[0..62]}'") if unique_name.length > 63
121
+ @logger.warn("Name is too long, using '#{unique_name[0..62]}'") if unique_name.length > 63
116
122
  rendered_template.metadata.name = unique_name[0..62]
117
123
  rendered_template.metadata.namespace = @namespace
118
124
 
@@ -124,11 +130,8 @@ module KubernetesDeploy
124
130
  f.write recursive_to_h(pod).to_json
125
131
  f.close
126
132
 
127
- _out, err, status = Kubectl.run_kubectl(
128
- "apply", "--dry-run", "-f", f.path,
129
- namespace: @namespace,
130
- context: @context
131
- )
133
+ kubectl = Kubectl.new(namespace: @namespace, context: @context, logger: @logger, log_failure_by_default: true)
134
+ _out, err, status = kubectl.run("apply", "--dry-run", "-f", f.path)
132
135
 
133
136
  unless status.success?
134
137
  raise FatalTaskRunError, "Invalid pod spec: #{err}"
@@ -1,3 +1,3 @@
1
1
  module KubernetesDeploy
2
- VERSION = "0.6.6"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubernetes-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kir Shatrov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-05-25 00:00:00.000000000 Z
13
+ date: 2017-06-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -68,6 +68,20 @@ dependencies:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
70
  version: 1.0.1
71
+ - !ruby/object:Gem::Dependency
72
+ name: colorize
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '0.8'
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '0.8'
71
85
  - !ruby/object:Gem::Dependency
72
86
  name: bundler
73
87
  requirement: !ruby/object:Gem::Requirement
@@ -175,8 +189,10 @@ files:
175
189
  - exe/kubernetes-run
176
190
  - kubernetes-deploy.gemspec
177
191
  - lib/kubernetes-deploy.rb
192
+ - lib/kubernetes-deploy/deferred_summary_logging.rb
178
193
  - lib/kubernetes-deploy/ejson_secret_provisioner.rb
179
194
  - lib/kubernetes-deploy/errors.rb
195
+ - lib/kubernetes-deploy/formatted_logger.rb
180
196
  - lib/kubernetes-deploy/kubeclient_builder.rb
181
197
  - lib/kubernetes-deploy/kubeclient_builder/google_friendly_config.rb
182
198
  - lib/kubernetes-deploy/kubectl.rb
@@ -192,12 +208,10 @@ files:
192
208
  - lib/kubernetes-deploy/kubernetes_resource/pod_template.rb
193
209
  - lib/kubernetes-deploy/kubernetes_resource/redis.rb
194
210
  - lib/kubernetes-deploy/kubernetes_resource/service.rb
195
- - lib/kubernetes-deploy/logger.rb
196
211
  - lib/kubernetes-deploy/resource_watcher.rb
197
212
  - lib/kubernetes-deploy/restart_task.rb
198
213
  - lib/kubernetes-deploy/runner.rb
199
214
  - lib/kubernetes-deploy/runner_task.rb
200
- - lib/kubernetes-deploy/ui_helpers.rb
201
215
  - lib/kubernetes-deploy/version.rb
202
216
  homepage: https://github.com/Shopify/kubernetes-deploy
203
217
  licenses:
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'logger'
3
-
4
- module KubernetesDeploy
5
- module Logger
6
- def self.included(base)
7
- base.extend(ClassMethods)
8
- end
9
-
10
- module ClassMethods
11
- def logger=(other)
12
- @logger = other
13
- end
14
-
15
- def logger
16
- @logger ||= begin
17
- l = ::Logger.new($stderr)
18
- l.level = level_from_env
19
- l.formatter = proc do |severity, datetime, _progname, msg|
20
- log_text = "[#{severity}][#{datetime}]\t#{msg}"
21
- case severity
22
- when "FATAL" then "\033[0;31m#{log_text}\x1b[0m\n" # red
23
- when "ERROR", "WARN" then "\033[0;33m#{log_text}\x1b[0m\n" # yellow
24
- when "INFO" then "\033[0;36m#{log_text}\x1b[0m\n" # blue
25
- else "#{log_text}\n"
26
- end
27
- end
28
- l
29
- end
30
- end
31
-
32
- private
33
-
34
- def level_from_env
35
- return ::Logger::DEBUG if ENV["DEBUG"]
36
-
37
- if ENV["LEVEL"]
38
- ::Logger.const_get(ENV["LEVEL"].upcase)
39
- else
40
- ::Logger::INFO
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
- module KubernetesDeploy
3
- module UIHelpers
4
- private
5
-
6
- def phase_heading(phase_name)
7
- @current_phase ||= 0
8
- @current_phase += 1
9
- heading = "Phase #{@current_phase}: #{phase_name}"
10
- padding = (100.0 - heading.length) / 2
11
- KubernetesDeploy.logger.info("")
12
- KubernetesDeploy.logger.info("#{'-' * padding.floor}#{heading}#{'-' * padding.ceil}")
13
- end
14
-
15
- def log_green(msg)
16
- KubernetesDeploy.logger.info("\033[0;32m#{msg}\x1b[0m")
17
- end
18
- end
19
- end