kubernetes-deploy 0.30.0 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +15 -0
- data/CONTRIBUTING.md +2 -2
- data/README.md +1 -1
- data/dev.yml +1 -1
- data/dev/flamegraph-from-tests +1 -1
- data/exe/kubernetes-deploy +11 -9
- data/exe/kubernetes-render +9 -7
- data/exe/kubernetes-restart +3 -3
- data/exe/kubernetes-run +1 -1
- data/kubernetes-deploy.gemspec +3 -3
- data/lib/krane.rb +5 -3
- data/lib/{kubernetes-deploy → krane}/bindings_parser.rb +1 -1
- data/lib/krane/cli/deploy_command.rb +14 -11
- data/lib/krane/cli/global_deploy_command.rb +47 -0
- data/lib/krane/cli/krane.rb +12 -3
- data/lib/krane/cli/render_command.rb +11 -9
- data/lib/krane/cli/restart_command.rb +4 -4
- data/lib/krane/cli/run_command.rb +3 -3
- data/lib/krane/cli/version_command.rb +1 -1
- data/lib/krane/cluster_resource_discovery.rb +102 -0
- data/lib/{kubernetes-deploy → krane}/common.rb +8 -9
- data/lib/krane/concerns/template_reporting.rb +29 -0
- data/lib/{kubernetes-deploy → krane}/concurrency.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/container_logs.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/deferred_summary_logging.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/delayed_exceptions.rb +0 -0
- data/lib/krane/deploy_task.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/deploy_task_config_validator.rb +1 -1
- data/lib/krane/deprecated_deploy_task.rb +404 -0
- data/lib/{kubernetes-deploy → krane}/duration_parser.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/ejson_secret_provisioner.rb +3 -3
- data/lib/krane/errors.rb +28 -0
- data/lib/{kubernetes-deploy → krane}/formatted_logger.rb +2 -2
- data/lib/krane/global_deploy_task.rb +210 -0
- data/lib/krane/global_deploy_task_config_validator.rb +12 -0
- data/lib/{kubernetes-deploy → krane}/kubeclient_builder.rb +11 -3
- data/lib/{kubernetes-deploy → krane}/kubectl.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource.rb +54 -22
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/cloudsql.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/config_map.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/cron_job.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/custom_resource.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/custom_resource_definition.rb +1 -5
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/daemon_set.rb +7 -4
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/deployment.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/horizontal_pod_autoscaler.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/ingress.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/job.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/network_policy.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/persistent_volume_claim.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/pod.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/pod_disruption_budget.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/pod_set_base.rb +3 -3
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/pod_template.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/replica_set.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/resource_quota.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/role.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/role_binding.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/secret.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/service.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/service_account.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/kubernetes_resource/stateful_set.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/label_selector.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/oj.rb +0 -0
- data/lib/{kubernetes-deploy → krane}/options_helper.rb +2 -2
- data/lib/{kubernetes-deploy → krane}/remote_logs.rb +2 -2
- data/lib/krane/render_task.rb +149 -0
- data/lib/{kubernetes-deploy → krane}/renderer.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/resource_cache.rb +4 -3
- data/lib/krane/resource_deployer.rb +265 -0
- data/lib/{kubernetes-deploy → krane}/resource_watcher.rb +6 -6
- data/lib/krane/restart_task.rb +224 -0
- data/lib/{kubernetes-deploy → krane}/rollout_conditions.rb +1 -1
- data/lib/krane/runner_task.rb +212 -0
- data/lib/{kubernetes-deploy → krane}/runner_task_config_validator.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/statsd.rb +13 -27
- data/lib/krane/task_config.rb +19 -0
- data/lib/{kubernetes-deploy → krane}/task_config_validator.rb +1 -1
- data/lib/{kubernetes-deploy → krane}/template_sets.rb +5 -5
- data/lib/krane/version.rb +4 -0
- data/lib/kubernetes-deploy/deploy_task.rb +6 -603
- data/lib/kubernetes-deploy/errors.rb +1 -26
- data/lib/kubernetes-deploy/render_task.rb +5 -139
- data/lib/kubernetes-deploy/rescue_krane_exceptions.rb +18 -0
- data/lib/kubernetes-deploy/restart_task.rb +6 -215
- data/lib/kubernetes-deploy/runner_task.rb +6 -203
- metadata +75 -58
- data/lib/kubernetes-deploy/cluster_resource_discovery.rb +0 -57
- data/lib/kubernetes-deploy/task_config.rb +0 -16
- data/lib/kubernetes-deploy/version.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f9a199d384a4137903191ff608290e6ff0c22423f8c783e866160fc546f7d00
|
4
|
+
data.tar.gz: 8936ac0d23a1cb1534df26b3e1a5e78ca75006ed929bd00fb6bc70877b3342c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37add457c1cb9e1deb7691a73318b413407dbe58c7326eff5769cd88afebc56cee6b53fa8c399cd0a44c1b89078d5cb32fa50492c18e5963fa9a776967979ffd
|
7
|
+
data.tar.gz: f16bf5443c6eb37a187e0bfbb82d21222d83dbaa4387a7958041d46dfef39086fbcc398c09acc1ab998a17e9031ddd0d7866e48dee318ef0b8cf3fc01e874f91
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,21 @@
|
|
3
3
|
*Important!*
|
4
4
|
- The next release will be 1.0.0, which means that master will contain breaking changes.
|
5
5
|
|
6
|
+
## 0.31
|
7
|
+
|
8
|
+
*Enhancements*
|
9
|
+
- (alpha) Add a new krane global-deploy task for deploying global resources. Note that global pruning is turned on by default ([#602](https://github.com/Shopify/kubernetes-deploy/pull/602) and [#612](https://github.com/Shopify/kubernetes-deploy/pull/612))
|
10
|
+
- Add support for deploying resources that use `generateName` ([#608](https://github.com/Shopify/kubernetes-deploy/pull/608))
|
11
|
+
- ENV["REVISION"] is not transparently passed into krane. Instead, you must now use the `--current-sha` flag to set the `current_sha` ERB binding in your templates. Note that kubernetes-deploy, _but not krane_, can still use ENV["REVISION"] as a fallback if `--current-sha` is not provided. ([#613](https://github.com/Shopify/kubernetes-deploy/pull/613))
|
12
|
+
|
13
|
+
*Bug Fixes*
|
14
|
+
- `krane deploy` can accept multiple filenames with `-f` flag ([#606](https://github.com/Shopify/kubernetes-deploy/pull/606))
|
15
|
+
- Ensure DaemonSet status has converged with pod statuses before reporting rollout success ([#617](https://github.com/Shopify/kubernetes-deploy/pull/617))
|
16
|
+
|
17
|
+
*Other*
|
18
|
+
- Update references from using `kubernetes-deploy` to `krane` in preparation for 1.0 release ([#585](https://github.com/Shopify/kubernetes-deploy/pull/585))
|
19
|
+
- Refactor StatsD usage so we can depend on the latest version again. ([#594](https://github.com/Shopify/kubernetes-deploy/pull/594))
|
20
|
+
|
6
21
|
## 0.30.0
|
7
22
|
|
8
23
|
*Enhancements*
|
data/CONTRIBUTING.md
CHANGED
@@ -141,9 +141,9 @@ Using another local cluster:
|
|
141
141
|
2. Put the name of the context you want to use in a file named `.local-context` in the root of this project. For example: `echo "dind" > .local-context`.
|
142
142
|
3. Run `bundle exec rake test` (or `dev test` if you work for Shopify).
|
143
143
|
|
144
|
-
To make StatsD log what it would have emitted, run a test with `
|
144
|
+
To make StatsD log what it would have emitted, run a test with `STATSD_ENV=development`.
|
145
145
|
|
146
|
-
To see the full-color output of a specific integration test, you can use `PRINT_LOGS=1`. For example: `PRINT_LOGS=1 bundle exec ruby -I test test/integration/
|
146
|
+
To see the full-color output of a specific integration test, you can use `PRINT_LOGS=1`. For example: `PRINT_LOGS=1 bundle exec ruby -I test test/integration/krane_deploy_test.rb -n/test_name/`.
|
147
147
|
|
148
148
|
|
149
149
|
![test-output](screenshots/test-output.png)
|
data/README.md
CHANGED
@@ -268,7 +268,7 @@ To run a task in your cluster at the beginning of every deploy, simply include a
|
|
268
268
|
* The pod's `spec.restartPolicy` must be set to `Never` so that it will be run exactly once. We'll fail the deploy if that run exits with a non-zero status.
|
269
269
|
* The pod's `spec.activeDeadlineSeconds` should be set to a reasonable value for the performed task (not required, but highly recommended)
|
270
270
|
|
271
|
-
A simple example can be found in the test fixtures: test/fixtures/hello-cloud/unmanaged-pod.yml.erb.
|
271
|
+
A simple example can be found in the test fixtures: [test/fixtures/hello-cloud/unmanaged-pod-1.yml.erb](test/fixtures/hello-cloud/unmanaged-pod-1.yml.erb).
|
272
272
|
|
273
273
|
The logs of all pods run in this way will be printed inline. If there is only one pod, the logs will be streamed in real-time. If there are multiple, they will be fetched when the pod terminates.
|
274
274
|
|
data/dev.yml
CHANGED
@@ -19,7 +19,7 @@ commands:
|
|
19
19
|
test:
|
20
20
|
run: bin/test
|
21
21
|
tophat:
|
22
|
-
run: PRINT_LOGS=1 bundle exec ruby -I test test/integration/
|
22
|
+
run: PRINT_LOGS=1 bundle exec ruby -I test test/integration/krane_deploy_test.rb -n/${1}/
|
23
23
|
desc: Tophat a change by running a test scenario with logging output enabled.
|
24
24
|
syntax:
|
25
25
|
optional:
|
data/dev/flamegraph-from-tests
CHANGED
@@ -22,7 +22,7 @@ if [[ -f $PROFILE_FILENAME ]]; then
|
|
22
22
|
fi
|
23
23
|
|
24
24
|
echo "Running test(s) with profiling"
|
25
|
-
PROFILE=1 bundle exec ruby -I test test/integration/
|
25
|
+
PROFILE=1 bundle exec ruby -I test test/integration/krane_deploy_test.rb -n /$1/ > /dev/null
|
26
26
|
|
27
27
|
echo "Processing profile"
|
28
28
|
cat $PROFILE_FILENAME | perl -w $FLAMEGRAPH_PL --countname=ms --width=1500 --title=$1 > $SVG_FILENAME
|
data/exe/kubernetes-deploy
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'kubernetes-deploy/deploy_task'
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
5
|
+
require 'krane/options_helper'
|
6
|
+
require 'krane/bindings_parser'
|
7
|
+
require 'krane/label_selector'
|
8
8
|
|
9
9
|
require 'optparse'
|
10
10
|
|
@@ -17,9 +17,10 @@ bindings = {}
|
|
17
17
|
verbose_log_prefix = false
|
18
18
|
max_watch_seconds = nil
|
19
19
|
selector = nil
|
20
|
+
current_sha = ENV["REVISION"]
|
20
21
|
|
21
22
|
ARGV.options do |opts|
|
22
|
-
parser =
|
23
|
+
parser = Krane::BindingsParser.new
|
23
24
|
opts.on("--bindings=BINDINGS", "Expose additional variables to ERB templates " \
|
24
25
|
"(format: k1=v1,k2=v2, JSON string or file (JSON or YAML) path prefixed by '@')") { |b| parser.add(b) }
|
25
26
|
|
@@ -41,7 +42,7 @@ ARGV.options do |opts|
|
|
41
42
|
end
|
42
43
|
opts.on("--selector=SELECTOR", "Ensure that all resources in your template dir match the given selector, " \
|
43
44
|
"and restrict pruning to deployed resources it selects. (format: k1=v1,k2=v2)") do |s|
|
44
|
-
selector =
|
45
|
+
selector = Krane::LabelSelector.parse(s)
|
45
46
|
end
|
46
47
|
|
47
48
|
opts.on_tail("-h", "--help", "Print this help") do
|
@@ -49,16 +50,17 @@ ARGV.options do |opts|
|
|
49
50
|
exit
|
50
51
|
end
|
51
52
|
opts.on_tail("-v", "--version", "Show version") do
|
52
|
-
puts "v#{
|
53
|
+
puts "v#{Krane::VERSION}"
|
53
54
|
exit
|
54
55
|
end
|
56
|
+
opts.on("--current-sha=CURRENT_SHA", "Expose SHA `current_sha` in ERB bindings") { |r| current_sha = r }
|
55
57
|
opts.parse!
|
56
58
|
bindings = parser.parse
|
57
59
|
end
|
58
60
|
|
59
61
|
namespace = ARGV[0]
|
60
62
|
context = ARGV[1]
|
61
|
-
logger =
|
63
|
+
logger = Krane::FormattedLogger.build(namespace, context, verbose_prefix: verbose_log_prefix)
|
62
64
|
|
63
65
|
# Deprecation path: this can be removed when --template-dir is fully replaced by -f
|
64
66
|
if template_dir && !template_paths.empty?
|
@@ -68,11 +70,11 @@ end
|
|
68
70
|
template_paths = [template_dir] if template_paths.empty? && template_dir
|
69
71
|
|
70
72
|
begin
|
71
|
-
|
73
|
+
Krane::OptionsHelper.with_processed_template_paths(template_paths) do |paths|
|
72
74
|
runner = KubernetesDeploy::DeployTask.new(
|
73
75
|
namespace: namespace,
|
74
76
|
context: context,
|
75
|
-
current_sha:
|
77
|
+
current_sha: current_sha,
|
76
78
|
template_paths: paths,
|
77
79
|
bindings: bindings,
|
78
80
|
logger: logger,
|
data/exe/kubernetes-render
CHANGED
@@ -2,32 +2,34 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'kubernetes-deploy/render_task'
|
5
|
-
require '
|
6
|
-
require '
|
5
|
+
require 'krane/options_helper'
|
6
|
+
require 'krane/bindings_parser'
|
7
7
|
|
8
8
|
require 'optparse'
|
9
9
|
|
10
10
|
template_dir = []
|
11
11
|
bindings = {}
|
12
|
+
current_sha = ENV["REVISION"]
|
12
13
|
|
13
14
|
ARGV.options do |opts|
|
14
|
-
parser =
|
15
|
+
parser = Krane::BindingsParser.new
|
15
16
|
opts.on("--bindings=BINDINGS", "Expose additional variables to ERB templates " \
|
16
17
|
"(format: k1=v1,k2=v2, JSON string or file (JSON or YAML) path prefixed by '@')") { |b| parser.add(b) }
|
17
18
|
opts.on("--template-dir=DIR", "Set the template dir (default: config/deploy/$ENVIRONMENT).") do |d|
|
18
19
|
template_dir = [d]
|
19
20
|
end
|
21
|
+
opts.on("--current-sha=CURRENT_SHA", "Expose SHA `current_sha` in ERB bindings") { |r| current_sha = r }
|
20
22
|
opts.parse!
|
21
23
|
bindings = parser.parse
|
22
24
|
end
|
23
25
|
|
24
26
|
templates = ARGV
|
25
|
-
logger =
|
27
|
+
logger = Krane::FormattedLogger.build(verbose_prefix: false)
|
26
28
|
|
27
29
|
begin
|
28
|
-
|
30
|
+
Krane::OptionsHelper.with_processed_template_paths(template_dir) do |dir|
|
29
31
|
runner = KubernetesDeploy::RenderTask.new(
|
30
|
-
current_sha:
|
32
|
+
current_sha: current_sha,
|
31
33
|
template_dir: dir.first,
|
32
34
|
bindings: bindings,
|
33
35
|
)
|
@@ -35,7 +37,7 @@ begin
|
|
35
37
|
success = runner.run(STDOUT, templates)
|
36
38
|
exit(1) unless success
|
37
39
|
end
|
38
|
-
rescue
|
40
|
+
rescue Krane::OptionsHelper::OptionsError => e
|
39
41
|
logger.error(e.message)
|
40
42
|
exit(1)
|
41
43
|
end
|
data/exe/kubernetes-restart
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
require 'optparse'
|
5
5
|
|
6
6
|
require 'kubernetes-deploy/restart_task'
|
7
|
-
require '
|
8
|
-
require '
|
7
|
+
require 'krane/options_helper'
|
8
|
+
require 'krane/label_selector'
|
9
9
|
|
10
10
|
raw_deployments = nil
|
11
11
|
max_watch_seconds = nil
|
@@ -14,7 +14,7 @@ ARGV.options do |opts|
|
|
14
14
|
opts.on("--deployments=LIST") { |v| raw_deployments = v.split(",") }
|
15
15
|
opts.on("--max-watch-seconds=seconds") { |t| max_watch_seconds = t.to_i }
|
16
16
|
opts.on("--selector=SELECTOR", "Restarts deployments matching selector (format: k1=v1,k2=v2)") do |s|
|
17
|
-
selector =
|
17
|
+
selector = Krane::LabelSelector.parse(s)
|
18
18
|
end
|
19
19
|
opts.parse!
|
20
20
|
end
|
data/exe/kubernetes-run
CHANGED
data/kubernetes-deploy.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
lib = File.expand_path('../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require '
|
5
|
+
require 'krane/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = "kubernetes-deploy"
|
9
|
-
spec.version =
|
9
|
+
spec.version = Krane::VERSION
|
10
10
|
spec.authors = ["Katrina Verey", "Kir Shatrov"]
|
11
11
|
spec.email = ["ops-accounts+shipit@shopify.com"]
|
12
12
|
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_dependency("googleauth", "~> 0.8.0")
|
29
29
|
spec.add_dependency("ejson", "~> 1.0")
|
30
30
|
spec.add_dependency("colorize", "~> 0.8")
|
31
|
-
spec.add_dependency("statsd-instrument", '
|
31
|
+
spec.add_dependency("statsd-instrument", ['>= 2.8', "< 3.1"])
|
32
32
|
spec.add_dependency("oj", "~> 3.0")
|
33
33
|
spec.add_dependency("concurrent-ruby", "~> 1.1")
|
34
34
|
spec.add_dependency("jsonpath", "~> 0.9.6")
|
data/lib/krane.rb
CHANGED
@@ -13,8 +13,9 @@ module Krane
|
|
13
13
|
"bindings" => { type: :array, banner: "foo=bar abc=def",
|
14
14
|
desc: "Expose additional variables to ERB templates (format: k1=v1 k2=v2, JSON string or file "\
|
15
15
|
"(JSON or YAML) path prefixed by '@')" },
|
16
|
-
"filenames" => { type: :
|
17
|
-
|
16
|
+
"filenames" => { type: :array, banner: 'config/deploy/production config/deploy/my-extra-resource.yml',
|
17
|
+
aliases: :f, required: true,
|
18
|
+
desc: "Directories and files that contains the configuration to apply" },
|
18
19
|
"global-timeout" => { type: :string, banner: "duration", default: DEFAULT_DEPLOY_TIMEOUT,
|
19
20
|
desc: "Max duration to monitor workloads correctly deployed" },
|
20
21
|
"protected-namespaces" => { type: :array, banner: "namespace1 namespace2 namespaceN",
|
@@ -30,20 +31,22 @@ module Krane
|
|
30
31
|
default: true },
|
31
32
|
"verify-result" => { type: :boolean, default: true,
|
32
33
|
desc: "Verify workloads correctly deployed" },
|
34
|
+
"current-sha" => { type: :string, banner: "SHA", desc: "Expose SHA `current_sha` in ERB bindings" },
|
35
|
+
|
33
36
|
}
|
34
37
|
|
35
38
|
def self.from_options(namespace, context, options)
|
36
39
|
require 'krane/deploy_task'
|
37
|
-
require '
|
38
|
-
require '
|
39
|
-
require '
|
40
|
+
require 'krane/options_helper'
|
41
|
+
require 'krane/bindings_parser'
|
42
|
+
require 'krane/label_selector'
|
40
43
|
|
41
|
-
bindings_parser =
|
44
|
+
bindings_parser = ::Krane::BindingsParser.new
|
42
45
|
options[:bindings]&.each { |binding_pair| bindings_parser.add(binding_pair) }
|
43
46
|
|
44
|
-
selector =
|
47
|
+
selector = ::Krane::LabelSelector.parse(options[:selector]) if options[:selector]
|
45
48
|
|
46
|
-
logger =
|
49
|
+
logger = ::Krane::FormattedLogger.build(namespace, context,
|
47
50
|
verbose_prefix: options['verbose-log-prefix'])
|
48
51
|
|
49
52
|
protected_namespaces = options['protected-namespaces']
|
@@ -51,16 +54,16 @@ module Krane
|
|
51
54
|
protected_namespaces = []
|
52
55
|
end
|
53
56
|
|
54
|
-
|
57
|
+
::Krane::OptionsHelper.with_processed_template_paths(options[:filenames],
|
55
58
|
require_explicit_path: true) do |paths|
|
56
59
|
deploy = ::Krane::DeployTask.new(
|
57
60
|
namespace: namespace,
|
58
61
|
context: context,
|
59
|
-
current_sha:
|
62
|
+
current_sha: options['current-sha'],
|
60
63
|
template_paths: paths,
|
61
64
|
bindings: bindings_parser.parse,
|
62
65
|
logger: logger,
|
63
|
-
max_watch_seconds:
|
66
|
+
max_watch_seconds: ::Krane::DurationParser.new(options["global-timeout"]).parse!.to_i,
|
64
67
|
selector: selector,
|
65
68
|
protected_namespaces: protected_namespaces,
|
66
69
|
)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Krane
|
4
|
+
module CLI
|
5
|
+
class GlobalDeployCommand
|
6
|
+
DEFAULT_DEPLOY_TIMEOUT = '300s'
|
7
|
+
OPTIONS = {
|
8
|
+
"filenames" => { type: :array, banner: 'config/deploy/production config/deploy/my-extra-resource.yml',
|
9
|
+
aliases: :f, required: true,
|
10
|
+
desc: "Directories and files that contains the configuration to apply" },
|
11
|
+
"global-timeout" => { type: :string, banner: "duration", default: DEFAULT_DEPLOY_TIMEOUT,
|
12
|
+
desc: "Max duration to monitor workloads correctly deployed" },
|
13
|
+
"verify-result" => { type: :boolean, default: true,
|
14
|
+
desc: "Verify workloads correctly deployed" },
|
15
|
+
"selector" => { type: :string, banner: "'label=value'", required: true,
|
16
|
+
desc: "Select workloads owned by selector(s)" },
|
17
|
+
"prune" => { type: :boolean, desc: "Enable deletion of resources that match"\
|
18
|
+
" the provided selector and do not appear in the provided templates",
|
19
|
+
default: true },
|
20
|
+
}
|
21
|
+
|
22
|
+
def self.from_options(context, options)
|
23
|
+
require 'krane/global_deploy_task'
|
24
|
+
require 'krane/options_helper'
|
25
|
+
require 'krane/label_selector'
|
26
|
+
require 'krane/duration_parser'
|
27
|
+
|
28
|
+
selector = ::Krane::LabelSelector.parse(options[:selector])
|
29
|
+
|
30
|
+
::Krane::OptionsHelper.with_processed_template_paths(options[:filenames],
|
31
|
+
require_explicit_path: true) do |paths|
|
32
|
+
deploy = ::Krane::GlobalDeployTask.new(
|
33
|
+
context: context,
|
34
|
+
filenames: paths,
|
35
|
+
global_timeout: ::Krane::DurationParser.new(options["global-timeout"]).parse!.to_i,
|
36
|
+
selector: selector,
|
37
|
+
)
|
38
|
+
|
39
|
+
deploy.run!(
|
40
|
+
verify_result: options["verify-result"],
|
41
|
+
prune: options[:prune],
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/krane/cli/krane.rb
CHANGED
@@ -7,6 +7,7 @@ require 'krane/cli/restart_command'
|
|
7
7
|
require 'krane/cli/run_command'
|
8
8
|
require 'krane/cli/render_command'
|
9
9
|
require 'krane/cli/deploy_command'
|
10
|
+
require 'krane/cli/global_deploy_command'
|
10
11
|
|
11
12
|
module Krane
|
12
13
|
module CLI
|
@@ -58,6 +59,14 @@ module Krane
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
62
|
+
desc("global-deploy CONTEXT", "Ship non-namespaced resources to a cluster")
|
63
|
+
expand_options(GlobalDeployCommand::OPTIONS)
|
64
|
+
def global_deploy(context)
|
65
|
+
rescue_and_exit do
|
66
|
+
GlobalDeployCommand.from_options(context, options)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
61
70
|
def self.exit_on_failure?
|
62
71
|
true
|
63
72
|
end
|
@@ -66,11 +75,11 @@ module Krane
|
|
66
75
|
|
67
76
|
def rescue_and_exit
|
68
77
|
yield
|
69
|
-
rescue
|
78
|
+
rescue ::Krane::DeploymentTimeoutError
|
70
79
|
exit(TIMEOUT_EXIT_CODE)
|
71
|
-
rescue
|
80
|
+
rescue ::Krane::FatalDeploymentError
|
72
81
|
exit(FAILURE_EXIT_CODE)
|
73
|
-
rescue
|
82
|
+
rescue ::Krane::DurationParser::ParsingError => e
|
74
83
|
STDERR.puts(<<~ERROR_MESSAGE)
|
75
84
|
Error parsing duration
|
76
85
|
#{e.message}. Duration must be a full ISO8601 duration or time value (e.g. 300s, 10m, 1h)
|
@@ -4,21 +4,23 @@ module Krane
|
|
4
4
|
module CLI
|
5
5
|
class RenderCommand
|
6
6
|
OPTIONS = {
|
7
|
-
bindings: { type: :array, desc: 'Bindings for erb' },
|
8
|
-
filenames: { type: :array,
|
7
|
+
bindings: { type: :array, banner: "foo=bar abc=def", desc: 'Bindings for erb' },
|
8
|
+
filenames: { type: :array, banner: 'config/deploy/production config/deploy/my-extra-resource.yml',
|
9
|
+
required: true, aliases: 'f', desc: 'Directories and files to render' },
|
10
|
+
'current-sha': { type: :string, banner: "SHA", desc: "Expose SHA `current_sha` in ERB bindings" },
|
9
11
|
}
|
10
12
|
|
11
13
|
def self.from_options(options)
|
12
|
-
require '
|
13
|
-
require '
|
14
|
-
require '
|
14
|
+
require 'krane/render_task'
|
15
|
+
require 'krane/bindings_parser'
|
16
|
+
require 'krane/options_helper'
|
15
17
|
|
16
|
-
bindings_parser =
|
18
|
+
bindings_parser = ::Krane::BindingsParser.new
|
17
19
|
options[:bindings]&.each { |b| bindings_parser.add(b) }
|
18
20
|
|
19
|
-
|
20
|
-
runner =
|
21
|
-
current_sha:
|
21
|
+
::Krane::OptionsHelper.with_processed_template_paths(options[:filenames]) do |paths|
|
22
|
+
runner = ::Krane::RenderTask.new(
|
23
|
+
current_sha: options['current-sha'],
|
22
24
|
template_paths: paths,
|
23
25
|
bindings: bindings_parser.parse,
|
24
26
|
)
|