kubernetes-deploy 0.12.8 → 0.12.9

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
  SHA1:
3
- metadata.gz: e88420aeda8ed5a7da13313a73bc90a6a0ca1a88
4
- data.tar.gz: a86e95c5689b0f269662fe82a53871a93100847c
3
+ metadata.gz: 6d865102d9b707cc6ef67eba2609c3eaaa94903a
4
+ data.tar.gz: 6e6f5ec188571c42c5dfd2672f62ccf922eabfb8
5
5
  SHA512:
6
- metadata.gz: 0b6f16ce8c330da35e925a66382fb4d1814136058f53226f51afa740ff76981c9cb2b02165bcbba384d4fac2905893d447279ee7328ea8579e681096e8eb412a
7
- data.tar.gz: 335f3cf2588530d725606fbb3f3927d29d91cf14abe74c6c5aa299a61aaaa4b072cc89f7c273471d52df4622392b5a9d9f0d15e1bca67d855e64dc2c7948ae70
6
+ metadata.gz: e250b6c3f66bd986fa7f2a11cd5779aa96ff05ce4ddb386d21521aa3e14748135894cb6be004e71205fcc28017c5690d452ba72c6b9d4a0cea7c601104a07bb4
7
+ data.tar.gz: e0797decff33ef2c7c4d311d85a5b4a78dd5fcb53ae10c9a76ead741b6a89e1b12fb4db1304fb1ad781255cb63ac92d9c9356d563da2b3daad9f18ec89d726ea
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ### 0.12.9
2
+
3
+ *Bug Fixes*
4
+ - Retry discovering namespace and kubernetes context
5
+ - Expose real error during namespace discovery
6
+
7
+ ### 0.12.8
8
+ *Bug Fixes*
9
+ - Force deployment to use its own hard timeout instead of relying on the replica set
data/README.md CHANGED
@@ -287,10 +287,11 @@ To make StatsD log what it would have emitted, run a test with `STATSD_DEV=1`.
287
287
 
288
288
  ## Releasing a new version (Shopify employees)
289
289
 
290
- 1. Update the version number in `version.rb` and commit that change with message "Version x.y.z". Don't push yet or you'll confuse Shipit.
291
- 2. Tag the version with `git tag vx.y.z -a -m "Version x.y.z"`
292
- 3. Push both your bump commit and its tag simultaneously with `git push origin master --follow-tags` (note that you can set `git config --global push.followTags true` to turn this flag on by default)
293
- 4. Use the [Shipit Stack](https://shipit.shopify.io/shopify/kubernetes-deploy/rubygems) to build the `.gem` file and upload to [rubygems.org](https://rubygems.org/gems/kubernetes-deploy).
290
+ 1. Make sure all merged PRs are reflected in the changelog before creating the commit for the new version.
291
+ 2. Update the version number in `version.rb` and commit that change with message "Version x.y.z". Don't push yet or you'll confuse Shipit.
292
+ 3. Tag the version with `git tag vx.y.z -a -m "Version x.y.z"`
293
+ 4. Push both your bump commit and its tag simultaneously with `git push origin master --follow-tags` (note that you can set `git config --global push.followTags true` to turn this flag on by default)
294
+ 5. Use the [Shipit Stack](https://shipit.shopify.io/shopify/kubernetes-deploy/rubygems) to build the `.gem` file and upload to [rubygems.org](https://rubygems.org/gems/kubernetes-deploy).
294
295
 
295
296
  If you push your commit and the tag separately, Shipit usually fails with `You need to create the v0.7.9 tag first.`. To make it find your tag, go to `Settings` > `Resynchronize this stack` > `Clear git cache`.
296
297
 
@@ -2,11 +2,12 @@
2
2
 
3
3
  module KubernetesDeploy
4
4
  class Kubectl
5
- def initialize(namespace:, context:, logger:, log_failure_by_default:)
5
+ def initialize(namespace:, context:, logger:, log_failure_by_default:, default_timeout: '30s')
6
6
  @namespace = namespace
7
7
  @context = context
8
8
  @logger = logger
9
9
  @log_failure_by_default = log_failure_by_default
10
+ @default_timeout = default_timeout
10
11
 
11
12
  raise ArgumentError, "namespace is required" if namespace.blank?
12
13
  raise ArgumentError, "context is required" if context.blank?
@@ -18,6 +19,7 @@ module KubernetesDeploy
18
19
  args = args.unshift("kubectl")
19
20
  args.push("--namespace=#{@namespace}") if use_namespace
20
21
  args.push("--context=#{@context}") if use_context
22
+ args.push("--request-timeout=#{@default_timeout}") if @default_timeout
21
23
 
22
24
  @logger.debug Shellwords.join(args)
23
25
  out, err, st = Open3.capture3(*args)
@@ -72,12 +72,15 @@ module KubernetesDeploy
72
72
  autoscaling/v1/HorizontalPodAutoscaler
73
73
  ).freeze
74
74
 
75
- def initialize(namespace:, context:, current_sha:, template_dir:, logger:, bindings: {})
75
+ NOT_FOUND_ERROR = 'NotFound'
76
+
77
+ def initialize(namespace:, context:, current_sha:, template_dir:, logger:, kubectl_instance: nil, bindings: {})
76
78
  @namespace = namespace
77
79
  @context = context
78
80
  @current_sha = current_sha
79
81
  @template_dir = File.expand_path(template_dir)
80
82
  @logger = logger
83
+ @kubectl = kubectl_instance
81
84
  @bindings = bindings
82
85
  # Max length of podname is only 63chars so try to save some room by truncating sha to 8 chars
83
86
  @id = current_sha[0...8] + "-#{SecureRandom.hex(4)}" if current_sha
@@ -401,12 +404,27 @@ module KubernetesDeploy
401
404
  elsif !available_contexts.include?(@context)
402
405
  raise FatalDeploymentError, "Context #{@context} is not available. Valid contexts: #{available_contexts}"
403
406
  end
407
+ confirm_cluster_reachable
404
408
  @logger.info("Context #{@context} found")
405
409
  end
406
410
 
411
+ def confirm_cluster_reachable
412
+ success = false
413
+ with_retries(2) do
414
+ _, _, st = kubectl.run("version", use_namespace: false, log_failure: true)
415
+ success = st.success?
416
+ end
417
+
418
+ raise FatalDeploymentError, "Failed to reach server for #{@context}" unless success
419
+ end
420
+
407
421
  def confirm_namespace_exists
408
- _, _, st = kubectl.run("get", "namespace", @namespace, use_namespace: false, log_failure: false)
409
- raise FatalDeploymentError, "Namespace #{@namespace} not found" unless st.success?
422
+ st, err = nil
423
+ with_retries(2) do
424
+ _, err, st = kubectl.run("get", "namespace", @namespace, use_namespace: false, log_failure: true)
425
+ st.success? || err.include?(NOT_FOUND_ERROR)
426
+ end
427
+ raise FatalDeploymentError, "Failed to find namespace. #{err}" unless st.success?
410
428
  @logger.info("Namespace #{@namespace} found")
411
429
  end
412
430
 
@@ -417,5 +435,14 @@ module KubernetesDeploy
417
435
  def statsd_tags
418
436
  %W(namespace:#{@namespace} sha:#{@current_sha} context:#{@context})
419
437
  end
438
+
439
+ def with_retries(limit)
440
+ retried = 0
441
+ while retried <= limit
442
+ success = yield
443
+ break if success
444
+ retried += 1
445
+ end
446
+ end
420
447
  end
421
448
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module KubernetesDeploy
3
- VERSION = "0.12.8"
3
+ VERSION = "0.12.9"
4
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.12.8
4
+ version: 0.12.9
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-10-26 00:00:00.000000000 Z
12
+ date: 2017-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -192,6 +192,7 @@ files:
192
192
  - ".buildkite/pipeline.yml"
193
193
  - ".gitignore"
194
194
  - ".rubocop.yml"
195
+ - CHANGELOG.md
195
196
  - Gemfile
196
197
  - LICENSE.txt
197
198
  - NO-BINAUTH