kubernetes-deploy 0.3.2 → 0.3.3

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: a66de972d0f1d21cd2034ef65b2e5e30f2152e91
4
- data.tar.gz: 207ecb8b75891de54c30acba082d55f85a9e3272
3
+ metadata.gz: 37ace35e766d0e991bf224d97c99cbadfde2c623
4
+ data.tar.gz: 3f10fd5a9471ca53135b5f817c2e949091171294
5
5
  SHA512:
6
- metadata.gz: 4294f06b1cc979131b412a7a546aaf36c4793ef2921e641a0760bb93f24caca238781e27ae1d89b8eef47a90977ab2f78ec65cf4310440c023c0249de574cb26
7
- data.tar.gz: 5a58d96ef5154fc75f46ca155aefa55b3b056ff1c51ee153e1e588565c10465d5214ce79b14c6da66d46154a103f9f54196a2a3de4a6ce0b788cb924919b0c51
6
+ metadata.gz: 491a65c67cfbe03eb70996bc3a5d27ac19767f654e896e522f1719930b5df628ec2d498e9a7e30e1b0244df14bac7036bdcc7986c0f256bd1ca2f6f9fc028607
7
+ data.tar.gz: d952118387e0bee804983b5a7e686a16c603f3b3c98ec69a187aa9d0d79f072117429f558d18ca283c77cabe004d1c40f1f8928a6426f593fcb1fa7a0e199e4e
data/.gitignore CHANGED
@@ -7,3 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ # Ignore RuboCop cache
12
+ .rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml
@@ -0,0 +1,5 @@
1
+ inherit_from:
2
+ - http://shopify.github.io/ruby-style-guide/rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.3
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
 
6
6
  gem 'pry'
7
7
  gem 'kubeclient'
8
+ gem 'rubocop'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Kubernetes::Deploy
2
2
 
3
- [![Build status](https://badge.buildkite.com/0f2d4956d49fbc795f9c17b0a741a6aa9ea532738e5f872ac8.svg)](https://buildkite.com/shopify/kubernetes-deploy-gem)
3
+ [![Build status](https://badge.buildkite.com/0f2d4956d49fbc795f9c17b0a741a6aa9ea532738e5f872ac8.svg?branch=master)](https://buildkite.com/shopify/kubernetes-deploy-gem)
4
4
 
5
5
  Deploy script used to manage a Kubernetes application's namespace with [Shipit](https://github.com/Shopify/shipit-engine).
6
6
 
data/bin/ci CHANGED
@@ -1,32 +1,13 @@
1
1
  #!/bin/bash
2
2
  set -eox pipefail
3
3
 
4
- MINIKUBE_VER=0.16.0
5
4
  KUBERNETES_VER=1.5.2
6
- DOCKER_MACHINE_KVM_VER=0.7.0
7
5
 
8
6
  echo "--- Installing dependencies"
9
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/v$MINIKUBE_VER/minikube-linux-amd64
10
- chmod +x minikube
11
- sudo mv minikube /usr/local/bin/
12
-
13
- # minikube requires kubectl
14
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v$KUBERNETES_VER/bin/linux/amd64/kubectl
15
- chmod +x kubectl
16
- sudo mv kubectl /usr/local/bin/
17
-
18
- # KVM support for minikube
19
- curl -Lo docker-machine-driver-kvm https://github.com/dhiltgen/docker-machine-kvm/releases/download/v$DOCKER_MACHINE_KVM_VER/docker-machine-driver-kvm
20
- chmod +x docker-machine-driver-kvm
21
- sudo mv docker-machine-driver-kvm /usr/local/bin/
22
-
23
- minikube config set vm-driver kvm
24
-
25
- gem install bundler --no-ri --no-rdoc
26
7
  bundle install --jobs 4
27
8
 
28
9
  echo "--- Starting minikube"
29
- minikube start --cpus 2 --memory 2048 --disk-size=2gb --kubernetes-version=$KUBERNETES_VER
10
+ minikube start --cpus 2 --memory 2048 --disk-size=2gb --kubernetes-version=$KUBERNETES_VER --logtostderr
30
11
 
31
12
  echo "--- Running tests"
32
13
  bundle exec rake test
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'kubernetes-deploy'
4
5
 
@@ -13,11 +14,12 @@ ARGV.options do |opts|
13
14
  end
14
15
 
15
16
  if !template_dir && ENV.key?("ENVIRONMENT")
16
- template_dir = "config/deploy/#{ENV["ENVIRONMENT"]}"
17
+ template_dir = "config/deploy/#{ENV['ENVIRONMENT']}"
17
18
  end
18
19
 
19
20
  if !template_dir || template_dir.empty?
20
- puts "Template directory is unknown. Either specify --template-dir argument or set $ENVIRONMENT to use config/deploy/$ENVIRONMENT as a default path."
21
+ puts "Template directory is unknown. " \
22
+ "Either specify --template-dir argument or set $ENVIRONMENT to use config/deploy/$ENVIRONMENT as a default path."
21
23
  exit 1
22
24
  end
23
25
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'active_support/core_ext/object/blank'
2
3
  require 'active_support/core_ext/hash/slice'
3
4
  require 'active_support/core_ext/numeric/time'
@@ -9,35 +10,35 @@ require 'kubernetes-deploy/runner'
9
10
  module KubernetesDeploy
10
11
  class FatalDeploymentError < StandardError; end
11
12
 
12
- def self.logger=(value)
13
- @logger = value
14
- end
13
+ class << self
14
+ attr_writer :logger
15
15
 
16
- def self.logger
17
- @logger ||= begin
18
- l = Logger.new($stderr)
19
- l.level = level_from_env
20
- l.formatter = proc do |severity, _datetime, _progname, msg|
21
- case severity
22
- when "FATAL", "ERROR" then "\033[0;31m[#{severity}]\t#{msg}\x1b[0m\n" # red
23
- when "WARN" then "\033[0;33m[#{severity}]\t#{msg}\x1b[0m\n" # yellow
24
- when "INFO" then "\033[0;36m#{msg}\x1b[0m\n" # blue
25
- else "[#{severity}]\t#{msg}\n"
16
+ def logger
17
+ @logger ||= begin
18
+ l = Logger.new($stderr)
19
+ l.level = level_from_env
20
+ l.formatter = proc do |severity, _datetime, _progname, msg|
21
+ case severity
22
+ when "FATAL", "ERROR" then "\033[0;31m[#{severity}]\t#{msg}\x1b[0m\n" # red
23
+ when "WARN" then "\033[0;33m[#{severity}]\t#{msg}\x1b[0m\n" # yellow
24
+ when "INFO" then "\033[0;36m#{msg}\x1b[0m\n" # blue
25
+ else "[#{severity}]\t#{msg}\n"
26
+ end
26
27
  end
28
+ l
27
29
  end
28
- l
29
30
  end
30
- end
31
31
 
32
- private
32
+ private
33
33
 
34
- def self.level_from_env
35
- return Logger::DEBUG if ENV["DEBUG"]
34
+ def level_from_env
35
+ return Logger::DEBUG if ENV["DEBUG"]
36
36
 
37
- if ENV["LEVEL"]
38
- Logger.const_get(ENV["LEVEL"].upcase)
39
- else
40
- Logger::INFO
37
+ if ENV["LEVEL"]
38
+ Logger.const_get(ENV["LEVEL"].upcase)
39
+ else
40
+ Logger::INFO
41
+ end
41
42
  end
42
43
  end
43
44
  end
@@ -1,6 +1,6 @@
1
1
  module KubernetesDeploy
2
2
  class Deployment < KubernetesResource
3
- TIMEOUT = 15.minutes
3
+ TIMEOUT = 5.minutes
4
4
 
5
5
  def initialize(name, namespace, context, file)
6
6
  @name, @namespace, @context, @file = name, namespace, context, file
@@ -1,6 +1,6 @@
1
1
  module KubernetesDeploy
2
2
  class Pod < KubernetesResource
3
- TIMEOUT = 15.minutes
3
+ TIMEOUT = 10.minutes
4
4
  SUSPICIOUS_CONTAINER_STATES = %w(ImagePullBackOff RunContainerError).freeze
5
5
 
6
6
  def initialize(name, namespace, context, file, parent: nil)
@@ -1,6 +1,6 @@
1
1
  module KubernetesDeploy
2
2
  class Service < KubernetesResource
3
- TIMEOUT = 15.minutes
3
+ TIMEOUT = 5.minutes
4
4
 
5
5
  def initialize(name, namespace, context, file)
6
6
  @name, @namespace, @context, @file = name, namespace, context, file
@@ -112,6 +112,24 @@ MSG
112
112
 
113
113
  private
114
114
 
115
+ # Inspect the file referenced in the kubectl stderr
116
+ # to make it easier for developer to understand what's going on
117
+ def inspect_kubectl_out_for_files(stderr)
118
+ # Output example:
119
+ # error: unable to decode "/tmp/path/to/file": [pos 96]: json: expect char '"' but got char '{'
120
+ match = stderr.match(/error: unable to decode "(?<path>\S+)":/)
121
+ return unless match
122
+
123
+ path = match[:path]
124
+ if path.present? && File.file?(path)
125
+ suspicious_file = File.read(path)
126
+ KubernetesDeploy.logger.warn("Inspecting the file mentioned in the error message (#{path})")
127
+ KubernetesDeploy.logger.warn(suspicious_file)
128
+ else
129
+ KubernetesDeploy.logger.warn("Detected a file (#{path.inspect}) referenced in the kubectl stderr but was unable to inspect it")
130
+ end
131
+ end
132
+
115
133
  def predeploy_priority_resources(resource_list)
116
134
  PREDEPLOY_SEQUENCE.each do |resource_type|
117
135
  matching_resources = resource_list.select { |r| r.type == resource_type }
@@ -269,7 +287,14 @@ MSG
269
287
  PRUNE_WHITELIST.each { |type| command.push("--prune-whitelist=#{type}") }
270
288
  end
271
289
 
272
- run_kubectl(*command)
290
+ _, err, st = run_kubectl(*command)
291
+ unless st.success?
292
+ inspect_kubectl_out_for_files(err)
293
+ raise FatalDeploymentError, <<-MSG
294
+ "The following command failed: #{Shellwords.join(command)}"
295
+ #{err}
296
+ MSG
297
+ end
273
298
  end
274
299
 
275
300
  def confirm_context_exists
@@ -1,3 +1,3 @@
1
1
  module KubernetesDeploy
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
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.3.2
4
+ version: 0.3.3
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-02-24 00:00:00.000000000 Z
13
+ date: 2017-03-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -77,6 +77,7 @@ extensions: []
77
77
  extra_rdoc_files: []
78
78
  files:
79
79
  - ".gitignore"
80
+ - ".rubocop.yml"
80
81
  - Gemfile
81
82
  - LICENSE.txt
82
83
  - README.md