kubernetes-deploy 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +28 -5
- data/bin/ci +32 -0
- data/bin/setup +10 -2
- data/exe/kubernetes-deploy +6 -11
- data/lib/kubernetes-deploy/kubernetes_resource.rb +9 -1
- data/lib/kubernetes-deploy/kubernetes_resource/deployment.rb +2 -2
- data/lib/kubernetes-deploy/runner.rb +2 -1
- data/lib/kubernetes-deploy/version.rb +1 -1
- metadata +3 -3
- data/bin/console +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 821c10919c954524f0e04068a6335ca187e83282
|
4
|
+
data.tar.gz: 0e63e63103fd2a0c5e8725553649b710670401bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0981745c90e24271e2c95ee825a62c57bb86823d3de470109151187f0adc085f6812402a1cbf50df751e43083cce5f5de9883f1147f2aab53296e93647ce5da0
|
7
|
+
data.tar.gz: d608ff476b6e72ec54b5501ef3ff31a3f20218295623a72b3dde8ae2a15f81a1ccd073e6026de120ab84e8a28663039033494f78f1e40d53dde9963eea70d732
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Kubernetes::Deploy
|
2
2
|
|
3
|
-
|
3
|
+
[![Build status](https://badge.buildkite.com/0f2d4956d49fbc795f9c17b0a741a6aa9ea532738e5f872ac8.svg)](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
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,14 +22,38 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
`kubernetes-deploy <app's namespace> <kube context> --template-dir=DIR`
|
26
|
+
|
27
|
+
Requirements:
|
28
|
+
|
29
|
+
- kubectl 1.5.1+ binary must be available in your path
|
30
|
+
- `ENV['KUBECONFIG']` must point to a valid kubeconfig file that includes the context you want to deploy to
|
31
|
+
- The target namespace must already exist in the target context
|
32
|
+
- `ENV['GOOGLE_APPLICATION_CREDENTIALS']` must point to the credentials for an authenticated service account if your user's auth provider is gcp
|
33
|
+
- `ENV['ENVIRONMENT']` must be set to use the default template path (`config/deploy/$ENVIRONMENT`) in the absence of the `--template-dir=DIR` option
|
34
|
+
|
26
35
|
|
27
36
|
## Development
|
28
37
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. You currently need to [manually install kubectl version 1.5.1 or higher](https://kubernetes.io/docs/user-guide/prereqs/) as well if you don't already have it.
|
39
|
+
|
40
|
+
To run the tests:
|
41
|
+
|
42
|
+
* [Install minikube](https://kubernetes.io/docs/getting-started-guides/minikube/#installation)
|
43
|
+
* Start minikube (`minikube start [options]`)
|
44
|
+
* Make sure you have a context named "minikube" in your kubeconfig. Minikube adds this context for you when you run `minikube start`; please do not rename it. You can check for it using `kubectl config get-contexts`.
|
45
|
+
* Run `bundle exec rake test`
|
30
46
|
|
31
47
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
48
|
|
49
|
+
## CI
|
50
|
+
|
51
|
+
Buildkite will build branches as you're working on them, but as soon as you create a PR it will stop building new commits from that branch because we disabled PR builds for security reasons.
|
52
|
+
As a Shopify employee, you can manually trigger the PR build from the Buildkite UI (just specify the branch, SHA is not required):
|
53
|
+
|
54
|
+
<img width="464" alt="screen shot 2017-02-21 at 10 55 33" src="https://cloud.githubusercontent.com/assets/522155/23172610/52771a3a-f824-11e6-8c8e-3d59c45e7ff8.png">
|
55
|
+
|
56
|
+
|
33
57
|
## Contributing
|
34
58
|
|
35
59
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kubernetes-deploy.
|
@@ -38,4 +62,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
38
62
|
## License
|
39
63
|
|
40
64
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/bin/ci
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
set -eox pipefail
|
3
|
+
|
4
|
+
MINIKUBE_VER=0.16.0
|
5
|
+
KUBERNETES_VER=1.5.2
|
6
|
+
DOCKER_MACHINE_KVM_VER=0.7.0
|
7
|
+
|
8
|
+
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
|
+
bundle install --jobs 4
|
27
|
+
|
28
|
+
echo "--- Starting minikube"
|
29
|
+
minikube start --cpus 2 --memory 2048 --disk-size=2gb --kubernetes-version=$KUBERNETES_VER
|
30
|
+
|
31
|
+
echo "--- Running tests"
|
32
|
+
bundle exec rake test
|
data/bin/setup
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
set -euo pipefail
|
3
3
|
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
4
|
|
6
5
|
bundle install
|
7
6
|
|
8
|
-
|
7
|
+
if [ ! -x "$(which minikube)" ]; then
|
8
|
+
echo -e "\n\033[0;33mIf you're going to run the tests, please follow the minikube setup instructions for your operating system:\nhttps://kubernetes.io/docs/getting-started-guides/minikube/#installation\033[0m"
|
9
|
+
fi
|
10
|
+
|
11
|
+
if [ ! -x "$(which kubectl)" ]; then
|
12
|
+
echo -e "\n\033[0;33mPlease install kubectl version 1.5.1 or higher:\nhttps://kubernetes.io/docs/user-guide/prereqs/\033[0m"
|
13
|
+
else
|
14
|
+
KUBECTL_VERSION=$(kubectl version --short --client | grep -oe "v[[:digit:]\.]\+")
|
15
|
+
echo -e "\n\033[0;32mKubectl version $KUBECTL_VERSION is already installed. This gem requires version v1.5.1 or greater.\033[0m"
|
16
|
+
fi
|
data/exe/kubernetes-deploy
CHANGED
@@ -1,15 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# Usage: kubernetes-deploy <app's namespace> <kube context>
|
4
|
-
|
5
|
-
# Prerequisites:
|
6
|
-
# - kubectl 1.5.1+ binary must be available in the shipit machine's path
|
7
|
-
# - ENV['KUBECONFIG'] must point to a valid kubeconfig file that includes all the contexts you want to deploy to
|
8
|
-
# - ENV['GOOGLE_APPLICATION_CREDENTIALS'] must point to the credentials for an authenticated service account if your user's auth provider is gcp
|
9
|
-
|
10
|
-
# Optionally, the following variables can be used to override script defaults:
|
11
|
-
# - ENV['K8S_TEMPLATE_FOLDER']: Location of Kubernetes files to deploy. Default is config/deploy/#{environment}.
|
12
|
-
|
13
3
|
require 'kubernetes-deploy'
|
14
4
|
|
15
5
|
require 'optparse'
|
@@ -31,11 +21,16 @@ if !template_dir || template_dir.empty?
|
|
31
21
|
exit 1
|
32
22
|
end
|
33
23
|
|
24
|
+
revision = ENV.fetch('REVISION') do
|
25
|
+
puts "ENV['REVISION'] is missing. Please specify the commit SHA"
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
|
34
29
|
KubernetesDeploy::Runner.with_friendly_errors do
|
35
30
|
runner = KubernetesDeploy::Runner.new(
|
36
31
|
namespace: ARGV[0],
|
37
32
|
context: ARGV[1],
|
38
|
-
current_sha:
|
33
|
+
current_sha: revision,
|
39
34
|
template_dir: template_dir,
|
40
35
|
wait_for_completion: !skip_wait,
|
41
36
|
)
|
@@ -24,6 +24,14 @@ module KubernetesDeploy
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def self.timeout
|
28
|
+
self::TIMEOUT
|
29
|
+
end
|
30
|
+
|
31
|
+
def timeout
|
32
|
+
self.class.timeout
|
33
|
+
end
|
34
|
+
|
27
35
|
def initialize(name, namespace, context, file)
|
28
36
|
# subclasses must also set these
|
29
37
|
@name, @namespace, @context, @file = name, namespace, context, file
|
@@ -68,7 +76,7 @@ module KubernetesDeploy
|
|
68
76
|
|
69
77
|
def deploy_timed_out?
|
70
78
|
return false unless @deploy_started
|
71
|
-
!deploy_succeeded? && !deploy_failed? && (Time.now.utc - @deploy_started >
|
79
|
+
!deploy_succeeded? && !deploy_failed? && (Time.now.utc - @deploy_started > timeout)
|
72
80
|
end
|
73
81
|
|
74
82
|
def tpr?
|
@@ -37,8 +37,8 @@ module KubernetesDeploy
|
|
37
37
|
def deploy_succeeded?
|
38
38
|
return false unless @rollout_data.key?("availableReplicas")
|
39
39
|
# TODO: this should look at the current replica set's pods too
|
40
|
-
@rollout_data["
|
41
|
-
@rollout_data.
|
40
|
+
@rollout_data["updatedReplicas"].to_i == @rollout_data["replicas"].to_i &&
|
41
|
+
@rollout_data["updatedReplicas"].to_i == @rollout_data["availableReplicas"].to_i
|
42
42
|
end
|
43
43
|
|
44
44
|
def deploy_failed?
|
@@ -174,7 +174,8 @@ MSG
|
|
174
174
|
delay_sync_until = Time.now.utc
|
175
175
|
started_at = delay_sync_until
|
176
176
|
human_resources = watched_resources.map(&:id).join(", ")
|
177
|
-
|
177
|
+
max_wait_time = watched_resources.map(&:timeout).max
|
178
|
+
KubernetesDeploy.logger.info("Waiting for #{human_resources} with #{max_wait_time}s timeout")
|
178
179
|
while watched_resources.present?
|
179
180
|
if Time.now.utc < delay_sync_until
|
180
181
|
sleep (delay_sync_until - Time.now.utc)
|
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.
|
4
|
+
version: 0.3.1
|
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-
|
13
|
+
date: 2017-02-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -81,7 +81,7 @@ files:
|
|
81
81
|
- LICENSE.txt
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
|
-
- bin/
|
84
|
+
- bin/ci
|
85
85
|
- bin/setup
|
86
86
|
- exe/kubernetes-deploy
|
87
87
|
- kubernetes-deploy.gemspec
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "kubernetes/deploy"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|