kubernetes-deploy 0.9.4 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 861c1898e40c08f1120bc55896920e0359f3f674
4
- data.tar.gz: 6c34e454e654acfba418245f3b2a2896272885cb
3
+ metadata.gz: 13bfb87f3f0cd5b833cb6146f91d7ccdfcf50725
4
+ data.tar.gz: 3c6cb3d5acf0c405a14759c01444e11244124509
5
5
  SHA512:
6
- metadata.gz: 4fc044006b4330a42b2d7b60e4b45c67b5be86ffd1c2e4017be9042f21d38a9d695058413ce78a9112406b0c8abf8e3c15bcf04f331f7ccf196cdcff6e62b387
7
- data.tar.gz: 61e7d6cd0d6c706fb1db1a601708f781005db36b3e932e8c22a18463580c4b8c551bfdac2db2df0b0ebef1b75258e2e1ae81044595cf7345c4fced52c4f97b6c
6
+ metadata.gz: 3d101d13086cf414cfc08989c9db9f7858dea14ab523c0424bf871a82ca98babc851ff7aea0be04db984e5aba689e5a2ecc5cc80750d2df4525573e5475f74a7
7
+ data.tar.gz: f7b35147c24d8dad169c850de62fe0b8108ec538c5626741404e70bdce86860ce04c4ac332b8fc9561598eabbaa81794af64f16c9978c5ee08b4a6e1fd078d7e
@@ -2,7 +2,4 @@ inherit_from:
2
2
  - http://shopify.github.io/ruby-style-guide/rubocop.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.1
6
-
7
- Layout/IndentHeredoc:
8
- EnforcedStyle: active_support
5
+ TargetRubyVersion: 2.3
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  # Specify your gem's dependencies in kubernetes-deploy.gemspec
data/README.md CHANGED
@@ -67,6 +67,7 @@ This repo also includes related tools for [running tasks](#kubernetes-run) and [
67
67
 
68
68
  ## Prerequisites
69
69
 
70
+ * Ruby 2.3+
70
71
  * Your cluster must be running Kubernetes v1.6.0 or higher
71
72
  * Each app must have a deploy directory containing its Kubernetes templates (see [Templates](#templates))
72
73
  * You must remove the` kubectl.kubernetes.io/last-applied-configuration` annotation from any resources in the namespace that are not included in your deploy directory. This annotation is added automatically when you create resources with `kubectl apply`. `kubernetes-deploy` will prune any resources that have this annotation and are not in the deploy directory.**
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "bundler/gem_tasks"
2
3
  require "rake/testtask"
3
4
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'kubernetes-deploy/version'
@@ -20,6 +21,8 @@ Gem::Specification.new do |spec|
20
21
  spec.bindir = "exe"
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
23
  spec.require_paths = ["lib"]
24
+
25
+ spec.required_ruby_version = '>= 2.3.0'
23
26
  spec.add_dependency "activesupport", ">= 4.2"
24
27
  spec.add_dependency "kubeclient", "~> 2.3"
25
28
  spec.add_dependency "googleauth", ">= 0.5"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module KubernetesDeploy
2
3
  # Adds the methods kubernetes-deploy requires to your logger class.
3
4
  # These methods include helpers for logging consistent headings, as well as facilities for
@@ -116,7 +116,7 @@ module KubernetesDeploy
116
116
  @logger.debug(out)
117
117
  raise EjsonSecretError, err unless st.success?
118
118
  ensure
119
- file.unlink if file
119
+ file&.unlink
120
120
  end
121
121
 
122
122
  def generate_secret_yaml(secret_name, secret_type, data)
@@ -5,7 +5,7 @@ module KubernetesDeploy
5
5
  module KubeclientBuilder
6
6
  class GoogleFriendlyConfig < Kubeclient::Config
7
7
  def fetch_user_auth_options(user)
8
- if user['auth-provider'] && (user['auth-provider']['name'] == 'gcp')
8
+ if user.dig('auth-provider', 'name') == 'gcp'
9
9
  { bearer_token: new_token }
10
10
  else
11
11
  super
@@ -13,11 +13,11 @@ module KubernetesDeploy
13
13
  LOG_LINE_COUNT = 250
14
14
 
15
15
  DEBUG_RESOURCE_NOT_FOUND_MESSAGE = "None found. Please check your usual logging service (e.g. Splunk)."
16
- UNUSUAL_FAILURE_MESSAGE = <<-MSG.strip_heredoc
16
+ UNUSUAL_FAILURE_MESSAGE = <<~MSG
17
17
  It is very unusual for this resource type to fail to deploy. Please try the deploy again.
18
18
  If that new deploy also fails, contact your cluster administrator.
19
19
  MSG
20
- STANDARD_TIMEOUT_MESSAGE = <<-MSG.strip_heredoc
20
+ STANDARD_TIMEOUT_MESSAGE = <<~MSG
21
21
  Kubernetes will continue to attempt to deploy this resource in the cluster, but at this point it is considered unlikely that it will succeed.
22
22
  If you have reason to believe it will succeed, retry the deploy to continue to monitor the rollout.
23
23
  MSG
@@ -44,7 +44,7 @@ module KubernetesDeploy
44
44
 
45
45
  def initialize(namespace:, context:, definition:, logger:)
46
46
  # subclasses must also set these if they define their own initializer
47
- @name = definition.fetch("metadata", {})["name"]
47
+ @name = definition.dig("metadata", "name")
48
48
  unless @name.present?
49
49
  logger.summary.add_paragraph("Rendered template content:\n#{definition.to_yaml}")
50
50
  raise FatalDeploymentError, "Template is missing required field metadata.name"
@@ -268,7 +268,7 @@ module KubernetesDeploy
268
268
  file.write(YAML.dump(@definition))
269
269
  file
270
270
  ensure
271
- file.close if file
271
+ file&.close
272
272
  end
273
273
 
274
274
  def statsd_tags
@@ -54,7 +54,7 @@ module KubernetesDeploy
54
54
  if st.success?
55
55
  parsed = JSON.parse(service)
56
56
 
57
- if parsed.fetch("spec", {}).fetch("clusterIP", "") != ""
57
+ if parsed.dig("spec", "clusterIP").present?
58
58
  # the service has an assigned cluster IP and is therefore functioning
59
59
  return true
60
60
  end
@@ -70,7 +70,7 @@ module KubernetesDeploy
70
70
  if st.success?
71
71
  parsed = JSON.parse(redis)
72
72
 
73
- @cloudsql_resource_uuid = parsed.fetch("metadata", {}).fetch("uid", nil)
73
+ @cloudsql_resource_uuid = parsed.dig("metadata", "uid")
74
74
  end
75
75
  end
76
76
  end
@@ -47,15 +47,15 @@ module KubernetesDeploy
47
47
  end
48
48
 
49
49
  def failure_message
50
- @latest_rs.failure_message
50
+ @latest_rs&.failure_message
51
51
  end
52
52
 
53
53
  def timeout_message
54
54
  progress_seconds = @definition['spec']['progressDeadlineSeconds']
55
55
  if progress_seconds
56
- "Deploy timed out due to progressDeadlineSeconds of #{progress_seconds} seconds. #{@latest_rs.timeout_message}"
56
+ "Deploy timed out due to progressDeadlineSeconds of #{progress_seconds} seconds. #{@latest_rs&.timeout_message}"
57
57
  else
58
- @latest_rs.timeout_message
58
+ @latest_rs&.timeout_message
59
59
  end
60
60
  end
61
61
 
@@ -162,25 +162,14 @@ module KubernetesDeploy
162
162
  end
163
163
 
164
164
  class Container
165
- STATUS_SCAFFOLD = {
166
- "state" => {
167
- "running" => {},
168
- "waiting" => {},
169
- "terminated" => {},
170
- },
171
- "lastState" => {
172
- "terminated" => {}
173
- }
174
- }.freeze
175
-
176
165
  attr_reader :name, :probe_location
177
166
 
178
167
  def initialize(definition, init_container: false)
179
168
  @init_container = init_container
180
169
  @name = definition["name"]
181
170
  @image = definition["image"]
182
- @probe_location = definition.fetch("readinessProbe", {}).fetch("httpGet", {})["path"]
183
- @status = STATUS_SCAFFOLD.dup
171
+ @probe_location = definition.dig("readinessProbe", "httpGet", "path")
172
+ @status = {}
184
173
  end
185
174
 
186
175
  def doomed?
@@ -188,14 +177,14 @@ module KubernetesDeploy
188
177
  end
189
178
 
190
179
  def doom_reason
191
- exit_code = @status['lastState']['terminated']['exitCode']
192
- last_terminated_reason = @status["lastState"]["terminated"]["reason"]
193
- limbo_reason = @status["state"]["waiting"]["reason"]
194
- limbo_message = @status["state"]["waiting"]["message"]
180
+ exit_code = @status.dig('lastState', 'terminated', 'exitCode')
181
+ last_terminated_reason = @status.dig("lastState", "terminated", "reason")
182
+ limbo_reason = @status.dig("state", "waiting", "reason")
183
+ limbo_message = @status.dig("state", "waiting", "message")
195
184
 
196
185
  if last_terminated_reason == "ContainerCannotRun"
197
186
  # ref: https://github.com/kubernetes/kubernetes/blob/562e721ece8a16e05c7e7d6bdd6334c910733ab2/pkg/kubelet/dockershim/docker_container.go#L353
198
- "Failed to start (exit #{exit_code}): #{@status['lastState']['terminated']['message']}"
187
+ "Failed to start (exit #{exit_code}): #{@status.dig('lastState', 'terminated', 'message')}"
199
188
  elsif limbo_reason == "CrashLoopBackOff"
200
189
  "Crashing repeatedly (exit #{exit_code}). See logs for more information."
201
190
  elsif %w(ImagePullBackOff ErrImagePull).include?(limbo_reason) &&
@@ -218,11 +207,11 @@ module KubernetesDeploy
218
207
  end
219
208
 
220
209
  def update_status(data)
221
- @status = STATUS_SCAFFOLD.deep_merge(data || {})
210
+ @status = data || {}
222
211
  end
223
212
 
224
213
  def reset_status
225
- @status = STATUS_SCAFFOLD.dup
214
+ @status = {}
226
215
  end
227
216
  end
228
217
  end
@@ -56,7 +56,7 @@ module KubernetesDeploy
56
56
  if st.success?
57
57
  parsed = JSON.parse(service)
58
58
 
59
- if parsed.fetch("spec", {}).fetch("clusterIP", "") != ""
59
+ if parsed.dig("spec", "clusterIP").present?
60
60
  return true
61
61
  end
62
62
  end
@@ -71,7 +71,7 @@ module KubernetesDeploy
71
71
  if st.success?
72
72
  parsed = JSON.parse(redis)
73
73
 
74
- @redis_resource_uuid = parsed.fetch("metadata", {}).fetch("uid", nil)
74
+ @redis_resource_uuid = parsed.dig("metadata", "uid")
75
75
  end
76
76
  end
77
77
  end
@@ -86,7 +86,7 @@ module KubernetesDeploy
86
86
 
87
87
  def container_names
88
88
  regular_containers = @definition["spec"]["template"]["spec"]["containers"].map { |c| c["name"] }
89
- init_containers = @definition["spec"]["template"]["spec"].fetch("initContainers", {}).map { |c| c["name"] }
89
+ init_containers = @definition["spec"]["template"]["spec"].fetch("initContainers", []).map { |c| c["name"] }
90
90
  regular_containers + init_containers
91
91
  end
92
92
 
@@ -3,7 +3,7 @@ module KubernetesDeploy
3
3
  class ResourceWatcher
4
4
  def initialize(resources, logger:, deploy_started_at: Time.now.utc)
5
5
  unless resources.is_a?(Enumerable)
6
- raise ArgumentError, <<-MSG.strip_heredoc
6
+ raise ArgumentError, <<~MSG
7
7
  ResourceWatcher expects Enumerable collection, got `#{resources.class}` instead
8
8
  MSG
9
9
  end
@@ -125,7 +125,7 @@ module KubernetesDeploy
125
125
  else
126
126
  deploy_resources(resources, prune: prune, verify: false)
127
127
  @logger.summary.add_action("deployed #{resources.length} #{'resource'.pluralize(resources.length)}")
128
- warning = <<-MSG.strip_heredoc
128
+ warning = <<~MSG
129
129
  Deploy result verification is disabled for this deploy.
130
130
  This means the desired changes were communicated to Kubernetes, but the deploy did not make sure they actually succeeded.
131
131
  MSG
@@ -245,7 +245,7 @@ module KubernetesDeploy
245
245
  yield doc unless doc.blank?
246
246
  end
247
247
  rescue Psych::SyntaxError => e
248
- debug_msg = <<-INFO.strip_heredoc
248
+ debug_msg = <<~INFO
249
249
  Error message: #{e}
250
250
 
251
251
  Template content:
@@ -372,7 +372,7 @@ module KubernetesDeploy
372
372
  _, err, create_st = kubectl.run("create", "-f", r.file_path, log_failure: false)
373
373
 
374
374
  next if create_st.success?
375
- raise FatalDeploymentError, <<-MSG.strip_heredoc
375
+ raise FatalDeploymentError, <<~MSG
376
376
  Failed to replace or create resource: #{r.id}
377
377
  #{err}
378
378
  MSG
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module KubernetesDeploy
2
- VERSION = "0.9.4"
3
+ VERSION = "0.10.0"
3
4
  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.9.4
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Verey
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-07-24 00:00:00.000000000 Z
12
+ date: 2017-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -246,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
246
  requirements:
247
247
  - - ">="
248
248
  - !ruby/object:Gem::Version
249
- version: '0'
249
+ version: 2.3.0
250
250
  required_rubygems_version: !ruby/object:Gem::Requirement
251
251
  requirements:
252
252
  - - ">="