kubernetes-deploy 0.29.0 → 1.0.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.buildkite/pipeline.nightly.yml +7 -0
  3. data/.rubocop.yml +0 -12
  4. data/.shopify-build/{kubernetes-deploy.yml → krane.yml} +8 -2
  5. data/1.0-Upgrade.md +109 -0
  6. data/CHANGELOG.md +60 -0
  7. data/CONTRIBUTING.md +2 -2
  8. data/Gemfile +1 -0
  9. data/README.md +86 -2
  10. data/dev.yml +3 -1
  11. data/dev/flamegraph-from-tests +1 -1
  12. data/exe/kubernetes-deploy +12 -9
  13. data/exe/kubernetes-render +9 -7
  14. data/exe/kubernetes-restart +3 -3
  15. data/exe/kubernetes-run +1 -1
  16. data/kubernetes-deploy.gemspec +5 -5
  17. data/lib/krane.rb +5 -3
  18. data/lib/{kubernetes-deploy → krane}/bindings_parser.rb +1 -1
  19. data/lib/krane/cli/deploy_command.rb +25 -13
  20. data/lib/krane/cli/global_deploy_command.rb +55 -0
  21. data/lib/krane/cli/krane.rb +12 -3
  22. data/lib/krane/cli/render_command.rb +19 -9
  23. data/lib/krane/cli/restart_command.rb +4 -4
  24. data/lib/krane/cli/run_command.rb +4 -4
  25. data/lib/krane/cli/version_command.rb +1 -1
  26. data/lib/krane/cluster_resource_discovery.rb +113 -0
  27. data/lib/{kubernetes-deploy → krane}/common.rb +8 -9
  28. data/lib/krane/concerns/template_reporting.rb +29 -0
  29. data/lib/{kubernetes-deploy → krane}/concurrency.rb +1 -1
  30. data/lib/{kubernetes-deploy → krane}/container_logs.rb +3 -2
  31. data/lib/{kubernetes-deploy → krane}/deferred_summary_logging.rb +2 -2
  32. data/lib/{kubernetes-deploy → krane}/delayed_exceptions.rb +0 -0
  33. data/lib/krane/deploy_task.rb +16 -0
  34. data/lib/krane/deploy_task_config_validator.rb +29 -0
  35. data/lib/krane/deprecated_deploy_task.rb +404 -0
  36. data/lib/{kubernetes-deploy → krane}/duration_parser.rb +1 -3
  37. data/lib/{kubernetes-deploy → krane}/ejson_secret_provisioner.rb +10 -13
  38. data/lib/krane/errors.rb +28 -0
  39. data/lib/{kubernetes-deploy → krane}/formatted_logger.rb +2 -2
  40. data/lib/krane/global_deploy_task.rb +210 -0
  41. data/lib/krane/global_deploy_task_config_validator.rb +12 -0
  42. data/lib/{kubernetes-deploy → krane}/kubeclient_builder.rb +13 -5
  43. data/lib/{kubernetes-deploy → krane}/kubectl.rb +14 -16
  44. data/lib/{kubernetes-deploy → krane}/kubernetes_resource.rb +110 -27
  45. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/cloudsql.rb +1 -1
  46. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/config_map.rb +1 -1
  47. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/cron_job.rb +1 -1
  48. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/custom_resource.rb +2 -2
  49. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/custom_resource_definition.rb +1 -5
  50. data/lib/krane/kubernetes_resource/daemon_set.rb +90 -0
  51. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/deployment.rb +2 -2
  52. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/horizontal_pod_autoscaler.rb +1 -1
  53. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/ingress.rb +1 -1
  54. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/job.rb +1 -1
  55. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/network_policy.rb +1 -1
  56. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/persistent_volume_claim.rb +1 -1
  57. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/pod.rb +6 -2
  58. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/pod_disruption_budget.rb +2 -2
  59. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/pod_set_base.rb +3 -3
  60. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/pod_template.rb +1 -1
  61. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/replica_set.rb +2 -2
  62. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/resource_quota.rb +1 -1
  63. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/role.rb +1 -1
  64. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/role_binding.rb +1 -1
  65. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/secret.rb +1 -1
  66. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/service.rb +2 -2
  67. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/service_account.rb +1 -1
  68. data/lib/{kubernetes-deploy → krane}/kubernetes_resource/stateful_set.rb +2 -2
  69. data/lib/{kubernetes-deploy → krane}/label_selector.rb +1 -1
  70. data/lib/{kubernetes-deploy → krane}/oj.rb +0 -0
  71. data/lib/{kubernetes-deploy → krane}/options_helper.rb +2 -2
  72. data/lib/{kubernetes-deploy → krane}/remote_logs.rb +2 -2
  73. data/lib/krane/render_task.rb +149 -0
  74. data/lib/{kubernetes-deploy → krane}/renderer.rb +1 -1
  75. data/lib/{kubernetes-deploy → krane}/resource_cache.rb +10 -9
  76. data/lib/krane/resource_deployer.rb +265 -0
  77. data/lib/{kubernetes-deploy → krane}/resource_watcher.rb +24 -25
  78. data/lib/krane/restart_task.rb +228 -0
  79. data/lib/{kubernetes-deploy → krane}/rollout_conditions.rb +1 -1
  80. data/lib/krane/runner_task.rb +212 -0
  81. data/lib/{kubernetes-deploy → krane}/runner_task_config_validator.rb +1 -1
  82. data/lib/{kubernetes-deploy → krane}/statsd.rb +13 -27
  83. data/lib/krane/task_config.rb +22 -0
  84. data/lib/{kubernetes-deploy → krane}/task_config_validator.rb +1 -1
  85. data/lib/{kubernetes-deploy → krane}/template_sets.rb +5 -5
  86. data/lib/krane/version.rb +4 -0
  87. data/lib/kubernetes-deploy/deploy_task.rb +6 -608
  88. data/lib/kubernetes-deploy/errors.rb +1 -26
  89. data/lib/kubernetes-deploy/render_task.rb +5 -122
  90. data/lib/kubernetes-deploy/rescue_krane_exceptions.rb +18 -0
  91. data/lib/kubernetes-deploy/restart_task.rb +6 -198
  92. data/lib/kubernetes-deploy/runner_task.rb +6 -184
  93. metadata +96 -70
  94. data/lib/kubernetes-deploy/cluster_resource_discovery.rb +0 -34
  95. data/lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb +0 -54
  96. data/lib/kubernetes-deploy/task_config.rb +0 -16
  97. data/lib/kubernetes-deploy/version.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0641a291f2f01c007051cf5001bc97ecb9216b55e7204d954c920083e0d303a
4
- data.tar.gz: 2c2415cfd94a63f046b94e90c943a7f9e01a46207833c1d5d2a498ceeb1ff333
3
+ metadata.gz: 5f64c627d9b1e7c3c2ba432e334dd7c9df8f9ee9e9d313be3ea1172a24262d45
4
+ data.tar.gz: e0de3c34b36943fce44584081c41eb7eb9fbaacb6d30395e851b6f2074c7e8bf
5
5
  SHA512:
6
- metadata.gz: 18a4e86f4f144dfa23ebc191b7d06382605ada3b050e8e1c9e717cbc9db981f16b419fb27a342f4e1267663f8f82fb12bcebfe0697c9ac4ac40c15108ab73072
7
- data.tar.gz: 314bdadd3d8f864895c13e81193845f4632fa46dc23550f12955a5ffe7a7b15ed3df1e12d769d5aefdb8ee4b7e5c3e3e13d5f8378f5c828a2e4bf3c04db8c56c
6
+ metadata.gz: 4c8406aabda6be3be66c254c01024e4ced5d2fb068755baa342a6152426d312fdd21d379e858bc52a5dd609fd2788074cdb46e3d23210b06457c779101a4a85d
7
+ data.tar.gz: f8ebafe3d74f8467369cba698b0efd8e833596a420a27dd576f16fe8b990a9232c56cc29579e212879d738da4a8b1c30b6f1a14cd8cd7f2390d1a968dd7de775
@@ -1,4 +1,11 @@
1
1
  steps:
2
+ - name: 'Run Test Suite (:kubernetes: 1.16-latest)'
3
+ command: bin/ci
4
+ agents:
5
+ queue: k8s-ci
6
+ env:
7
+ LOGGING_LEVEL: 4
8
+ KUBERNETES_VERSION: v1.16-latest
2
9
  - name: 'Run Test Suite (:kubernetes: 1.15-latest)'
3
10
  command: bin/ci
4
11
  agents:
@@ -3,15 +3,3 @@ inherit_from:
3
3
 
4
4
  AllCops:
5
5
  TargetRubyVersion: 2.4
6
-
7
- Naming/FileName:
8
- Enabled: true
9
- Exclude:
10
- - lib/kubernetes-deploy.rb
11
-
12
- Sorbet/ConstantsFromStrings:
13
- Enabled: false
14
-
15
- Layout/Tab:
16
- Exclude:
17
- - test/integration/kubernetes_deploy_test.rb
@@ -6,9 +6,15 @@ steps:
6
6
  - label: Lint
7
7
  timeout: 5m
8
8
  run:
9
+ - bundle: ~
9
10
  - bundle exec rubocop
10
- dependencies:
11
- - bundler
11
+ - label: 'Run Test Suite (:kubernetes: 1.16.12)'
12
+ command: bin/ci
13
+ agents:
14
+ queue: k8s-ci
15
+ env:
16
+ LOGGING_LEVEL: "4"
17
+ KUBERNETES_VERSION: v1.16.12
12
18
  - label: 'Run Test Suite (:kubernetes: 1.15-latest)'
13
19
  command: bin/ci
14
20
  agents:
@@ -0,0 +1,109 @@
1
+ # kubernetes-deploy 0.31.1 -> krane 1.0.0 migration guide
2
+
3
+ **THIS MIGRATION GUIDE IS A WORK IN PROGRESS. THINGS CAN STILL CHANGE BEFORE 1.0.0**
4
+
5
+ `kubernetes-deploy` was renamed `krane` when version 1.0.0 was released. Version 1.0.0 introduced [new features and breaking changes](CHANGELOG.md). This guide will help you transition to version 1.0.0 as smoothly as possible.
6
+
7
+ **TL;DR**:
8
+ * The command-line interface was redesigned; alongside the name change there are breaking changes in several flags.
9
+ * There are breaking changes in the public API (such as the renaming of the `KubernetesDeploy` namespace to `Krane`, and the change in default values for different arguments of the public interface).
10
+ * StatsD metrics will now be generated with the `krane` prefix.
11
+ * `krane deploy` now considers all namespaced resources eligible for pruning, including
12
+ custom resources. See [blacklist](https://github.com/Shopify/kubernetes-deploy/blob/master/lib/krane/cluster_resource_discovery.rb#L20) for exceptions.
13
+ * `kubernetes-deploy` (now `krane deploy`) / `DeployTask` can no longer deploy global (non-namespaced) resources. A new command called `krane global-deploy` and a related class called `GlobalDeployTask` were added to replace that feature.
14
+ * If you attempt to install two gems that have conflicting executables, `gem install` will warn you but the most recently installed one will win.
15
+
16
+ ## Public API changes
17
+
18
+ The only breaking change in the public API (so far) is the renaming of the `KubernetesDeploy` namespace to `Krane`. Otherwise, the APIs of the major public classes (`DeployTask`, `RenderTask`, `RunnerTask`, and `RestartTask`) have not changed between 0.31.1 and 1.0.0. If you're curious about this API, check the comment-based docs on these classes or the [rendered documentation at RubyGems.org](https://www.rubydoc.info/gems/kubernetes-deploy/1.0.0/KubernetesDeploy/DeployTask).
19
+
20
+ ## Command-line interface changes
21
+
22
+ Old command | New command
23
+ --- | ---
24
+ `kubernetes-deploy` | `krane deploy`
25
+ `kubernetes-deploy -v` | `krane version`
26
+ `kubernetes-render` | `krane render`
27
+ `kubernetes-run` | `krane run`
28
+ `kubernetes-restart` | `krane restart`
29
+ `[kubernetes-deploy with global resources in templates]` | `krane global-deploy`
30
+
31
+ ### Flag changes
32
+
33
+ The following tables provide a mapping of the flags previously supported in `kubernetes-deploy` and their new version in `krane` (if applicable).
34
+
35
+ Important: you can't repeat flags. If you need to provide multiple arguments for a flag, use a space-separated list (e.g. `-f file1.yml file2.yml`) unless specified otherwise.
36
+
37
+ #### krane deploy
38
+
39
+ Old flag | New flag | Comments
40
+ --- | --- | ---
41
+ --bindings=BINDINGS | --bindings=BINDINGS |
42
+ --skip-wait | --verify-result=true |
43
+ --allow-protected-ns | --protected-namespaces=default,kube-system,kube-public | Added the ability to specify which namespaces are protected
44
+ --no-prune | --prune=true |
45
+ --template-dir | -f, --filename | Makes all krane commands accept this argument, which is now required for the deploy task
46
+ --verbose-log-prefix | --verbose-log-prefix |
47
+ --max-watch-seconds=seconds | --global-timeout=300s | Changed flag name and default value to be a duration (expressed using strings like "300s" or "1h")
48
+ --selector | --selector |
49
+ -h, --help | -h, --help |
50
+ -v, --version | [none] | Replaced with `krane version`
51
+ $ENVIRONMENT | [none] | Dropped in favour of `-f`
52
+ $REVISION | --current-sha | The environment variable REVISION was dropped in favour of an explicit flag
53
+ [none] | --render-erb | **Important:** the new CLI doesn't render ERB by default
54
+ [none] | --stdin | Allow template filenames given from stdin stream
55
+
56
+ #### krane restart
57
+
58
+ Old flag | New flag | Comments
59
+ --- | --- | ---
60
+ --deployments=LIST | --deployments=LIST |
61
+ --max-watch-seconds=seconds | --global-timeout=300s | Changed flag name and default value to be a duration (expressed using strings like "300s" or "1h")
62
+ [none] | --verify-result=true | Defines whether it should wait for results or exit immediately after validation
63
+
64
+ #### krane run
65
+
66
+ Old flag | New flag | Comments
67
+ --- | --- | ---
68
+ --skip-wait | --verify-result=true |
69
+ --max-watch-seconds=seconds | --global-timeout=300s | Changed flag name and default value to be a duration (expressed using strings like "300s" or "1h")
70
+ --entrypoint | --command | Changed flag name to make its purpose clearer
71
+ --template | --template | Changed to be required
72
+ [it is positional now] | --arguments | Optional flag, as `command` or the template might already specify the required arguments
73
+ --env-vars=ENV_VARS | --env-vars=ENV_VARS |
74
+
75
+ #### krane render
76
+
77
+ Old flag | New flag | Comments
78
+ --- | --- | ---
79
+ --bindings=BINDINGS | --bindings=BINDINGS |
80
+ --template-dir | -f, --filename | Changed to be more aligned with `kubectl apply` and other krane tasks
81
+ $REVISION | --current-sha | The environment variable REVISION was dropped in favour of an explicit flag
82
+ [none] | --stdin | Allow template filenames given from stdin stream
83
+
84
+ ## Running `kubernetes-deploy` and `krane` side by side
85
+
86
+ If you attempt to install two gems that have conflicting executables (as is the case here), `gem install` will warn you but the most recently installed one will win. This means that you can run both `kubernetes-deploy` 0.31.1 and `krane` 1.0.0 side by side by doing:
87
+
88
+ ```bash
89
+ gem install kubernetes-deploy -v 0.31.1
90
+ gem install -f krane -v 1.0.0
91
+ ```
92
+
93
+ This can help you incrementally port scripts that use the old CLI to the new one.
94
+
95
+ ## New task: `krane global-deploy`
96
+
97
+ `krane global-deploy` (accessible through the Ruby API as `Krane::GlobalDeployTask`) can deploy global (non-namespaced) resources such as `PersistentVolume`, `Namespace`, and `CustomResourceDefinition`. Its interface is very similar to `krane deploy`. Example usage:
98
+
99
+ ```bash
100
+ $ cat my-template.yml
101
+ apiVersion: storage.k8s.io/v1
102
+ kind: StorageClass
103
+ metadata:
104
+ name: testing-storage-class
105
+ labels:
106
+ app: krane
107
+ provisioner: kubernetes.io/no-provisioner
108
+ $ krane global-deploy my-k8s-context -f my-template.yml --selector app=krane
109
+ ```
@@ -3,11 +3,71 @@
3
3
  *Important!*
4
4
  - The next release will be 1.0.0, which means that master will contain breaking changes.
5
5
 
6
+ ## 1.0.0.pre.2
7
+
8
+ *Enhancements*
9
+ - Relax thor version requirement. ([#731](https://github.com/Shopify/krane/pull/731))
10
+ - Relax googleauth restriction. ([#731](https://github.com/Shopify/krane/pull/731))
11
+
12
+ ## 1.0.0.pre.1
13
+
14
+ *Important!*
15
+
16
+ - This is the final release of KubernetesDeploy. Version 1.0.0 will be released
17
+ under the name `Krane`. We've added a migration guide to help make it easier to migrate.
18
+ ([#607](https://github.com/Shopify/kubernetes-deploy/pull/607))
19
+
20
+ *Enhancements*
21
+ - (beta) `krane deploy` will now consider all namespaced resources eligible for pruning
22
+ and does not respect the `krane.shopify.io/prunable` annotation. This adds 5 additional
23
+ types: Endpoints, Event, LimitRange, ReplicationController, and Lease.
24
+ ([#616](https://github.com/Shopify/kubernetes-deploy/pull/616)
25
+
26
+ - (beta) Added the `--stdin` flag to `krane deploy|global-deploy|render` to read resources from stdin. ([#630](https://github.com/Shopify/kubernetes-deploy/pull/630))
27
+
28
+ ## 0.31.1
29
+
30
+ *Bug Fixes*
31
+ - Fix a scoping issue of ClusterResourceDiscovery where it was not visible to kubernetes-run, causing a crash. ([#624](https://github.com/Shopify/kubernetes-deploy/pull/624))
32
+
33
+ ## 0.31.0
34
+
35
+ *Enhancements*
36
+ - (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))
37
+ - Add support for deploying resources that use `generateName` ([#608](https://github.com/Shopify/kubernetes-deploy/pull/608))
38
+ - 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))
39
+
40
+ *Bug Fixes*
41
+ - `krane deploy` can accept multiple filenames with `-f` flag ([#606](https://github.com/Shopify/kubernetes-deploy/pull/606))
42
+ - Ensure DaemonSet status has converged with pod statuses before reporting rollout success ([#617](https://github.com/Shopify/kubernetes-deploy/pull/617))
43
+
44
+ *Other*
45
+ - Update references from using `kubernetes-deploy` to `krane` in preparation for 1.0 release ([#585](https://github.com/Shopify/kubernetes-deploy/pull/585))
46
+ - Refactor StatsD usage so we can depend on the latest version again. ([#594](https://github.com/Shopify/kubernetes-deploy/pull/594))
47
+
48
+ ## 0.30.0
49
+
50
+ *Enhancements*
51
+ - **[Breaking change]** Added PersistentVolumeClaim to the prune whitelist. ([#573](https://github.com/Shopify/kubernetes-deploy/pull/573))
52
+ * To see what resources may be affected, run `kubectl get pvc -o jsonpath='{ range .items[*] }{.metadata.namespace}{ "\t" }{.metadata.name}{ "\t" }{.metadata.annotations}{ "\n" }{ end }' --all-namespaces | grep "last-applied"`
53
+ * To exclude a resource from kubernetes-deploy (and kubectl apply) management, remove the last-applied annotation `kubectl annotate pvc $PVC_NAME kubectl.kubernetes.io/last-applied-configuration-`.
54
+ - Deploying global resources directly from `KubernetesDeploy::DeployTask` is disabled by default. You can use `allow_globals: true` to enable the old behavior. This will be disabled in the Krane version of the task, and a separate purpose-built task will be provided. [#567](https://github.com/Shopify/kubernetes-deploy/pull/567)
55
+ - Deployments to daemonsets now better tolerate autoscaling: nodes that appear mid-deploy aren't required for convergence. [#580](https://github.com/Shopify/kubernetes-deploy/pull/580)
56
+
57
+ ## 0.29.0
58
+
59
+ *Enhancements*
60
+ - The KubernetesDeploy::RenderTask now supports a template_paths argument. ([#555](https://github.com/Shopify/kubernetes-deploy/pull/546))
61
+ - We no longer hide errors from apply if all sensitive resources have passed server-dry-run validation. ([#570](https://github.com/Shopify/kubernetes-deploy/pull/570))
62
+
63
+
6
64
  *Bug Fixes*
7
65
  - Handle improper duration values more elegantly with better messaging
8
66
 
67
+
9
68
  *Other*
10
69
  - We now require Ruby 2.4.x since Ruby 2.3 is past EoL.
70
+ - Lock statsd-instrument to 2.3.X due to breaking changes in 2.5.0
11
71
 
12
72
  ## 0.28.0
13
73
 
@@ -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 `STATSD_DEV=1`.
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/kubernetes_deploy_test.rb -n/test_name/`.
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/Gemfile CHANGED
@@ -13,3 +13,4 @@ gem 'codecov', require: false
13
13
  gem 'ruby-prof', require: false
14
14
  gem 'ruby-prof-flamegraph', require: false
15
15
  gem 'minitest-reporters'
16
+ gem 'yard', require: false
data/README.md CHANGED
@@ -47,6 +47,7 @@ This repo also includes related tools for [running tasks](#kubernetes-run) and [
47
47
  * [Running tasks at the beginning of a deploy](#running-tasks-at-the-beginning-of-a-deploy)
48
48
  * [Deploying Kubernetes secrets (from EJSON)](#deploying-kubernetes-secrets-from-ejson)
49
49
  * [Deploying custom resources](#deploying-custom-resources)
50
+ * [Walk through the steps of a deployment](#deploy-walkthrough)
50
51
 
51
52
  **KUBERNETES-RESTART**
52
53
  * [Usage](#usage-1)
@@ -267,7 +268,7 @@ To run a task in your cluster at the beginning of every deploy, simply include a
267
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.
268
269
  * The pod's `spec.activeDeadlineSeconds` should be set to a reasonable value for the performed task (not required, but highly recommended)
269
270
 
270
- 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).
271
272
 
272
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.
273
274
 
@@ -420,6 +421,89 @@ status:
420
421
  - `$.status.conditions[?(@.type == "Failed")].status == "True"` means that a failure condition has been fulfilled and the resource is considered failed.
421
422
  - Since `error_msg_path` is specified, kubernetes-deploy will log the contents of `$.status.conditions[?(@.type == "Failed")].message`, which in this case is: `resource is failed`.
422
423
 
424
+ ### Deploy walkthrough
425
+
426
+ Let's walk through what happens when you run the `deploy` task with [this directory of templates](https://github.com/Shopify/kubernetes-deploy/tree/master/test/fixtures/hello-cloud). You can see this for yourself by running the following command:
427
+
428
+ ```bash
429
+ krane deploy my-namespace my-k8s-cluster -f test/fixtures/hello-cloud --render-erb
430
+ ```
431
+
432
+ As soon as you run this, you'll start seeing some output being streamed to STDERR.
433
+
434
+ #### Phase 1: Initializing deploy
435
+
436
+ In this phase, we:
437
+
438
+ - Perform basic validation to ensure we can proceed with the deploy. This includes checking if we can reach the context, if the context is valid, if the namespace exists within the context, and more. We try to validate as much as we can before trying to ship something because we want to avoid having an incomplete deploy in case of a failure (this is especially important because there's no rollback support).
439
+ - List out all the resources we want to deploy (as described in the template files we used).
440
+ - Render ERB templates and apply partials, if enabled (which is the case for this example). If enabled, we also perform basic validation on the parsed templates.
441
+
442
+ #### Phase 2: Checking initial resource statuses
443
+
444
+ In this phase, we check resource statuses. For each resource listed in the previous step, we check Kubernetes for their status; in the first deploy this might show a bunch of items as "Not Found", but for the deploy of a new version, this is an example of what it could look like:
445
+
446
+ ```
447
+ Certificate/services-foo-tls Exists
448
+ Cloudsql/foo-production Provisioned
449
+ Deployment/jobs 3 replicas, 3 updatedReplicas, 3 availableReplicas
450
+ Deployment/web 3 replicas, 3 updatedReplicas, 3 availableReplicas
451
+ Ingress/web Created
452
+ Memcached/foo-production Healthy
453
+ Pod/db-migrate-856359 Unknown
454
+ Pod/upload-assets-856359 Unknown
455
+ Redis/foo-production Healthy
456
+ Service/web Selects at least 1 pod
457
+ ```
458
+
459
+ The next phase might be either "Predeploying priority resources" (if there's any) or "Deploying all resources". In this example we'll go through the former, as we do have predeployable resources.
460
+
461
+ #### Phase 3: Predeploying priority resources
462
+
463
+ This is the first phase that could modify the cluster.
464
+
465
+ In this phase we predeploy certain types of resources (e.g. `ConfigMap`, `PersistentVolumeClaim`, `Secret`, ...) to make sure the latest version will be available when resources that might consume them (e.g. `Deployment`) are deployed. This phase will be skipped if the templates don't include any resources that would need to be predeployed.
466
+
467
+ When this runs, we essentially run `kubectl apply` on those templates and periodically check the cluster for the current status of each resource so we can display error or success information. This will look different depending on the type of resource. If you're running the command described above, you should see something like this in the output:
468
+
469
+ ```
470
+ Deploying ConfigMap/hello-cloud-configmap-data (timeout: 30s)
471
+ Successfully deployed in 0.2s: ConfigMap/hello-cloud-configmap-data
472
+
473
+ Deploying PersistentVolumeClaim/hello-cloud-redis (timeout: 300s)
474
+ Successfully deployed in 3.3s: PersistentVolumeClaim/hello-cloud-redis
475
+
476
+ Deploying Role/role (timeout: 300s)
477
+ Don't know how to monitor resources of type Role. Assuming Role/role deployed successfully.
478
+ Successfully deployed in 0.2s: Role/role
479
+ ```
480
+
481
+ As you can see, different types of resources might have different timeout values and different success criteria; in some specific cases (such as with Role) we might not know how to confirm success or failure, so we use a higher timeout value and assume it did work.
482
+
483
+ #### Phase 4: Deploying all resources
484
+
485
+ In this phase, we:
486
+
487
+ - Deploy all resources found in the templates, including resources that were predeployed in the previous step (which should be treated as a no-op by Kubernetes). We deploy everything so the pruning logic (described below) doesn't remove any predeployed resources.
488
+ - Prune resources not found in the templates (you can disable this by using `--no-prune`).
489
+
490
+ Just like in the previous phase, we essentially run `kubectl apply` on those templates and periodically check the cluster for the current status of each resource so we can display error or success information.
491
+
492
+ If pruning is enabled (which, again, is the default), any [resource which type is listed in `DeployTask.prune_whitelist`](https://github.com/Shopify/kubernetes-deploy/blob/ac42ad7c8c4f6f6b27e706d6642ebe002ca1f683/lib/kubernetes-deploy/deploy_task.rb#L80-L104) that we can find in the namespace but not in the templates will be removed. A particular message about pruning will be printed in the next phase if any resource matches this criteria.
493
+
494
+ #### Result
495
+
496
+ The result section will show:
497
+ - A global status: if **all** resources were deployed successfully, this will show up as "SUCCESS"; if at least one resource failed to deploy (due to an error or timeout), this will show up as "FAILURE".
498
+ - A list of resources and their individual status: this will show up as something like "Available", "Created", and "1 replica, 1 availableReplica, 1 readyReplica".
499
+
500
+ At this point the command also returns a status code:
501
+ - If it was a success, `0`
502
+ - If there was a timeout, `70`
503
+ - If any other failure happened, `1`
504
+
505
+ **On timeouts**: It's important to notice that a single resource timeout or a global deploy timeout doesn't necessarily mean that the operation failed. Since Kubernetes updates are asynchronous, maybe something was just too slow to return in the configured time; in those cases, usually running the deploy again might work (that should be a no-op for most - if not all - resources).
506
+
423
507
  # kubernetes-restart
424
508
 
425
509
  `kubernetes-restart` is a tool for restarting all of the pods in one or more deployments. It triggers the restart by touching the `RESTARTED_AT` environment variable in the deployment's podSpec. The rollout strategy defined for each deployment will be respected by the restart.
@@ -440,7 +524,7 @@ The following command will restart all pods in the `web` and `jobs` deployments:
440
524
  Add the annotation `shipit.shopify.io/restart` to all the deployments you want to target, like this:
441
525
 
442
526
  ```yaml
443
- apiVersion: apps/v1beta1
527
+ apiVersion: apps/v1
444
528
  kind: Deployment
445
529
  metadata:
446
530
  name: web
data/dev.yml CHANGED
@@ -19,8 +19,10 @@ commands:
19
19
  test:
20
20
  run: bin/test
21
21
  tophat:
22
- run: PRINT_LOGS=1 bundle exec ruby -I test test/integration/kubernetes_deploy_test.rb -n/${1}/
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:
26
26
  argument: TEST_REGEX
27
+ doc:
28
+ run: bundle exec yard doc
@@ -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/kubernetes_deploy_test.rb -n /$1/ > /dev/null
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
@@ -2,9 +2,9 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'kubernetes-deploy/deploy_task'
5
- require 'kubernetes-deploy/options_helper'
6
- require 'kubernetes-deploy/bindings_parser'
7
- require 'kubernetes-deploy/label_selector'
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 = KubernetesDeploy::BindingsParser.new
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 = KubernetesDeploy::LabelSelector.parse(s)
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#{KubernetesDeploy::VERSION}"
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 = KubernetesDeploy::FormattedLogger.build(namespace, context, verbose_prefix: verbose_log_prefix)
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,16 +70,17 @@ end
68
70
  template_paths = [template_dir] if template_paths.empty? && template_dir
69
71
 
70
72
  begin
71
- KubernetesDeploy::OptionsHelper.with_processed_template_paths(template_paths) do |paths|
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: ENV["REVISION"],
77
+ current_sha: current_sha,
76
78
  template_paths: paths,
77
79
  bindings: bindings,
78
80
  logger: logger,
79
81
  max_watch_seconds: max_watch_seconds,
80
82
  selector: selector,
83
+ allow_globals: true
81
84
  )
82
85
 
83
86
  runner.run!(