kubes 0.3.5 → 0.4.0

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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +6 -5
  4. data/docs/_docs/config/args.md +10 -0
  5. data/docs/_docs/config/args/docker.md +19 -0
  6. data/docs/_docs/config/{kubectl/args.md → args/kubectl.md} +2 -0
  7. data/docs/_docs/config/docker.md +4 -40
  8. data/docs/_docs/config/hooks.md +10 -0
  9. data/docs/_docs/config/hooks/docker.md +70 -0
  10. data/docs/_docs/config/hooks/kubectl.md +83 -0
  11. data/docs/_docs/config/hooks/kubes.md +67 -0
  12. data/docs/_docs/config/hooks/ruby.md +74 -0
  13. data/docs/_docs/config/kubectl.md +2 -2
  14. data/docs/_docs/config/reference.md +20 -0
  15. data/docs/_docs/config/skip.md +58 -0
  16. data/docs/_docs/dsl/resources.md +1 -1
  17. data/docs/_docs/intro.md +3 -1
  18. data/docs/_docs/patterns/migrations.md +121 -0
  19. data/docs/_includes/config/hooks/options.md +20 -0
  20. data/docs/_includes/sidebar.html +25 -12
  21. data/docs/_sass/theme.scss +25 -1
  22. data/lib/kubes/cli.rb +20 -5
  23. data/lib/kubes/cli/apply.rb +2 -1
  24. data/lib/kubes/cli/base.rb +11 -0
  25. data/lib/kubes/cli/delete.rb +1 -1
  26. data/lib/kubes/cli/exec.rb +37 -6
  27. data/lib/kubes/cli/get.rb +1 -1
  28. data/lib/kubes/cli/logs.rb +27 -3
  29. data/lib/kubes/cli/prune.rb +95 -0
  30. data/lib/kubes/compiler.rb +18 -7
  31. data/lib/kubes/compiler/decorator/base.rb +7 -1
  32. data/lib/kubes/compiler/decorator/{resources/secret.rb → hashable.rb} +5 -4
  33. data/lib/kubes/compiler/decorator/hashable/field.rb +53 -0
  34. data/lib/kubes/compiler/decorator/hashable/storage.rb +19 -0
  35. data/lib/kubes/compiler/decorator/post.rb +77 -0
  36. data/lib/kubes/compiler/decorator/pre.rb +12 -0
  37. data/lib/kubes/compiler/strategy.rb +2 -2
  38. data/lib/kubes/compiler/strategy/base.rb +1 -1
  39. data/lib/kubes/compiler/strategy/result.rb +4 -6
  40. data/lib/kubes/config.rb +16 -11
  41. data/lib/kubes/docker/strategy/build/docker.rb +1 -1
  42. data/lib/kubes/docker/strategy/build/gcloud.rb +1 -1
  43. data/lib/kubes/docker/strategy/image_name.rb +1 -1
  44. data/lib/kubes/docker/strategy/push/docker.rb +1 -1
  45. data/lib/kubes/docker/strategy/push/gcloud.rb +1 -1
  46. data/lib/kubes/docker/strategy/utils.rb +1 -1
  47. data/lib/kubes/hooks/builder.rb +29 -15
  48. data/lib/kubes/hooks/concern.rb +10 -0
  49. data/lib/kubes/hooks/dsl.rb +2 -1
  50. data/lib/kubes/hooks/runner.rb +22 -0
  51. data/lib/kubes/kubectl.rb +21 -18
  52. data/lib/kubes/kubectl/batch.rb +8 -5
  53. data/lib/kubes/kubectl/{decider.rb → dispatcher.rb} +1 -1
  54. data/lib/kubes/kubectl/fetch/base.rb +12 -9
  55. data/lib/kubes/kubectl/fetch/deployment.rb +12 -13
  56. data/lib/kubes/kubectl/fetch/pods.rb +4 -15
  57. data/lib/kubes/kubectl/kustomize.rb +1 -1
  58. data/lib/kubes/kubectl/ordering.rb +12 -0
  59. data/lib/kubes/util/consider.rb +2 -1
  60. data/lib/kubes/util/sh.rb +1 -1
  61. data/lib/kubes/version.rb +1 -1
  62. data/spec/fixtures/decorators/deployment/both/envFrom.yaml +31 -0
  63. data/spec/fixtures/prune/capture.yaml +57 -0
  64. data/spec/fixtures/prune/fetch_items.yaml +268 -0
  65. data/spec/kubes/cli/prune_spec.rb +38 -0
  66. data/spec/kubes/compiler/decorator/{resources → post}/deployment_spec.rb +25 -6
  67. data/spec/kubes/compiler/decorator/{resources → post}/pod_spec.rb +2 -11
  68. metadata +35 -19
  69. data/docs/_docs/config/kubectl/hooks.md +0 -39
  70. data/lib/kubes/compiler/decorator.rb +0 -17
  71. data/lib/kubes/compiler/decorator/compile.rb +0 -12
  72. data/lib/kubes/compiler/decorator/resources/base.rb +0 -13
  73. data/lib/kubes/compiler/decorator/resources/container.rb +0 -76
  74. data/lib/kubes/compiler/decorator/resources/container/mapping.rb +0 -28
  75. data/lib/kubes/compiler/decorator/resources/deployment.rb +0 -10
  76. data/lib/kubes/compiler/decorator/resources/pod.rb +0 -10
  77. data/lib/kubes/compiler/decorator/write.rb +0 -14
  78. data/lib/kubes/docker/strategy/hooks.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d239ce306b5a9eea427cab3ec5ca5f753f0eae3d1822fce65017c23172779562
4
- data.tar.gz: 3d97c8d85e6f5bfd02babaf14140f186ebd22c3981fa8eed76ddcdbe7f24958d
3
+ metadata.gz: 3d309f1eb882767efd06378aa5bff9fbe8e162db4ebcd19b9ffec2637929d8b0
4
+ data.tar.gz: a60c4ae73920a38cda6780f435475922f318409e34aed8dec827df0b8483d6c5
5
5
  SHA512:
6
- metadata.gz: 74b0ad9bc27e15f1b8742d26f6b2c09e11e990a69623a7e0b54d12565dc08e3dec5d0c640bfd4f5457aa09f0069c0010a78d39dedc18bd9a2223ebdb34be9c31
7
- data.tar.gz: 7f3508f0d3650677a48f1f0069f71b1801ddd0a760f052f725a81f564fd144b6eecbd8c08e79fd2e9ec571a0ada2308d4f84bdfbc6971f66a80a20eec8ffbaae
6
+ metadata.gz: 600df214d8b09d66bbea43b3114dc8dd3b41011025e76e2741ce2a076fa4af1ab8f07b68e54f1aeaaa72d166a1c9c2970c34f22f314b14b99384c00d8818aee4
7
+ data.tar.gz: 491bf32c8f78ce324aa500d57976345e28696d2fa483b6c8671d92c62191a3c84ffe11048b743251903c4b9b2ff1a0dc7c92b86211b9b909f8fcb5d813c79b7a
@@ -3,6 +3,20 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.4.0]
7
+ - #26 features: kubes vs kubectl hooks, prune, etc
8
+ - hooks: kubes, kubectl, docker breaking changes.
9
+ - hooks now in the .kubes/config/hooks folder.
10
+ - hook for kubectl supports `on` option for more control over when to run hook.
11
+ - generalize hasher
12
+ - auto prune hashed resources like ConfigMap and Secret
13
+ - kubes prune command for manual running
14
+ - support .yml extension also
15
+ - renamed exec `--name` to `--deployment` option.
16
+ - add `--pod` option to `exec` and `logs` command.
17
+ - fix md5 hash for multiple types within envFrom
18
+ - add skip config option
19
+
6
20
  ## [0.3.5]
7
21
  - #25 small fixes: show pod and fetch items nil
8
22
 
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <div align="center">
2
+ <a href="https://kubes.guru"><img src="https://img.boltops.com/boltops/logos/kubes-black-v1.png" /></a>
3
+ </div>
4
+
1
5
  # Kubes
2
6
 
3
7
  [![Gem Version](https://badge.fury.io/rb/kubes.png)](http://badge.fury.io/rb/kubes)
@@ -37,12 +41,9 @@ In fact, you can use Kubes to build the files first, and then run `kubectl` dire
37
41
  kubes docker push
38
42
  kubes compile # compiles the .kubes/resources files to .kubes/output
39
43
 
40
- Now, use `kubectl` directly. This will apply all the files:
41
-
42
- kubectl apply --recursive -f .kubes/output
43
-
44
- You can also selectively apply specific files:
44
+ Now, use `kubectl` directly in the proper order:
45
45
 
46
+ kubectl apply -f .kubes/output/shared/namespace.yaml
46
47
  kubectl apply -f .kubes/output/web/deployment.yaml
47
48
  kubectl apply -f .kubes/output/web/service.yaml
48
49
 
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: Args
3
+ ---
4
+
5
+ Kubes supports customizing the args passed to the `docker` and `kubectl` commands:
6
+
7
+ {% assign docs = site.docs | where: "categories","args" %}
8
+ {% for doc in docs -%}
9
+ * [{{ doc.title }}]({{ doc.url }})
10
+ {% endfor %}
@@ -0,0 +1,19 @@
1
+ ---
2
+ title: Docker Args
3
+ nav_text: Docker
4
+ categories: args
5
+ ---
6
+
7
+ Here are some examples of customizing the docker args.
8
+
9
+ .kubes/config/args/docker.rb
10
+
11
+ ```ruby
12
+ command("build",
13
+ args: ["--quiet"],
14
+ )
15
+
16
+ command("push",
17
+ args: ["--disable-content-trust"],
18
+ )
19
+ ```
@@ -1,5 +1,7 @@
1
1
  ---
2
2
  title: Kubectl Args
3
+ nav_text: Kubectl
4
+ categories: args
3
5
  ---
4
6
 
5
7
  Here are some examples of customizing the kubectl args.
@@ -26,45 +26,9 @@ Also, kubes apply another way to skip the docker build:
26
26
 
27
27
  kubes apply web
28
28
 
29
- ## Customizing Args
29
+ ## Customizing Args and Hooks
30
30
 
31
- Here are some examples of customizing the docker args.
31
+ See:
32
32
 
33
- .kubes/config/docker/args.rb
34
-
35
- ```ruby
36
- command("build",
37
- args: ["--quiet"],
38
- )
39
-
40
- command("push",
41
- args: ["--disable-content-trust"],
42
- )
43
- ```
44
-
45
- ## Hooks
46
-
47
- Here are some examples of running custom hooks before and after the docker commands.
48
-
49
- .kubes/config/docker/hooks.rb
50
-
51
- ```ruby
52
- before("build",
53
- execute: "echo 'docker build before hook'",
54
- )
55
-
56
- after("push",
57
- execute: "echo 'docker push before hook'",
58
- )
59
- ```
60
-
61
- ### exit on fail
62
-
63
- By default, if the hook commands fail, then terraspace will exit with the original hook error code. You can change this behavior with the `exit_on_fail` option.
64
-
65
- ```ruby
66
- before("build"
67
- execute: "/command/will/fail/but/will/continue",
68
- exit_on_fail: false,
69
- )
70
- ```
33
+ * [Docker Args Docs]({% link _docs/config/args/docker.md %})
34
+ * [Docker Hooks Docs]({% link _docs/config/hooks/docker.md %})
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: Hooks
3
+ ---
4
+
5
+ Kubes supports a variety of hooks. They can be used to customize and finely control the kubes deploy process.
6
+
7
+ {% assign docs = site.docs | where: "categories","hooks" %}
8
+ {% for doc in docs -%}
9
+ * [{{ doc.title }}]({{ doc.url }})
10
+ {% endfor %}
@@ -0,0 +1,70 @@
1
+ ---
2
+ title: Docker Hooks
3
+ nav_text: Docker
4
+ categories: hooks
5
+ ---
6
+
7
+ Here are some examples of running custom hooks before and after the docker commands.
8
+
9
+ ## Build Hooks
10
+
11
+ .kubes/config/hooks/docker.rb
12
+
13
+ ```ruby
14
+ before("build",
15
+ execute: "echo 'docker build before hook'",
16
+ )
17
+
18
+ after("build",
19
+ execute: "echo 'docker build after hook'",
20
+ )
21
+ ```
22
+
23
+ Results in:
24
+
25
+ $ kubes docker build
26
+ Running docker before build hook.
27
+ => echo 'docker build before hook'
28
+ docker build before hook
29
+ => docker build -t gcr.io/tung-275700/demo:kubes-2020-10-10T20-06-28-2e80bf4 -f Dockerfile .
30
+ Running docker after build hook.
31
+ => echo 'docker build after hook'
32
+ docker build after hook
33
+ $
34
+
35
+ ## Push Hooks
36
+
37
+ ```ruby
38
+ before("push",
39
+ execute: "echo 'docker push before hook'",
40
+ )
41
+
42
+ after("push",
43
+ execute: "echo 'docker push after hook'",
44
+ )
45
+ ```
46
+
47
+ Results in:
48
+
49
+ $ kubes docker push
50
+ Running docker before push hook.
51
+ => echo 'docker push before hook'
52
+ docker push before hook
53
+ => docker push gcr.io/tung-275700/demo:kubes-2020-10-10T20-06-28-2e80bf4
54
+ Running docker after push hook.
55
+ => echo 'docker push after hook'
56
+ docker push after hook
57
+ $
58
+
59
+ ## exit_on_fail option
60
+
61
+ By default, if the hook commands fail, then terraspace will exit with the original hook error code. You can change this behavior with the `exit_on_fail` option.
62
+
63
+ ```ruby
64
+ before("build"
65
+ execute: "/command/will/fail/but/will/continue",
66
+ exit_on_fail: false,
67
+ )
68
+ ```
69
+
70
+ {% include config/hooks/options.md command="docker" %}
@@ -0,0 +1,83 @@
1
+ ---
2
+ title: Kubectl Hooks
3
+ nav_text: Kubectl
4
+ categories: hooks
5
+ ---
6
+
7
+ You can use hooks to run scripts at any part of the `kubectl` commands. Here's an example of running a script before and after the `kubectl apply` command for the `web/deployment` resource.
8
+
9
+ .kubes/config/hooks/kubectl.rb
10
+
11
+ ```ruby
12
+ before("apply",
13
+ on: "web/deployment",
14
+ execute: "echo 'before apply hook test'",
15
+ )
16
+
17
+ after("delete",
18
+ on: "web/deployment",
19
+ execute: "echo 'after delete hook test'",
20
+ )
21
+ ```
22
+
23
+ ## on option
24
+
25
+ The `on` option is important. If it is not set, then the hook script will run on every `kubectl` command. So given this hook definition:
26
+
27
+ ```ruby
28
+ before("apply",
29
+ # Note how the on option is not set
30
+ execute: "echo 'before apply hook test'",
31
+ )
32
+ ```
33
+
34
+ With these resource definition files:
35
+
36
+ .kubes/resources/shared/namespace.yaml
37
+ .kubes/resources/web/deployment.yaml
38
+ .kubes/resources/web/web.yaml
39
+
40
+ The hook script will run **3** times.
41
+
42
+ $ kubes apply
43
+ # before apply hook test <= HERE 1
44
+ => kubectl apply -f .kubes/output/shared/namespace.yaml
45
+ # before apply hook test <= HERE 2
46
+ => kubectl apply -f .kubes/output/web/service.yaml
47
+ # before apply hook test <= HERE 3
48
+ => kubectl apply -f .kubes/output/web/deployment.yaml
49
+ $
50
+
51
+ This is probably not what you want. So it is important to use the `on` option to scope when to run your hook like so:
52
+
53
+ ```ruby
54
+ before("apply",
55
+ on: "web/deployment",
56
+ execute: "echo 'before apply hook test'",
57
+ )
58
+ ```
59
+
60
+ The hook script will run **1** time for the `.kubes/resources/web/deployment.yaml`:
61
+
62
+ $ kubes apply
63
+ => kubectl apply -f .kubes/output/shared/namespace.yaml
64
+ => kubectl apply -f .kubes/output/web/service.yaml
65
+ # before apply hook test <= HERE
66
+ => kubectl apply -f .kubes/output/web/deployment.yaml
67
+ $
68
+
69
+ The `on` option is used to match the path the gets applied: .kubes/resources/**web/deployment**.yaml
70
+
71
+ ## exit on fail
72
+
73
+ By default, if the hook commands fail, then terraspace will exit with the original hook error code. You can change this behavior with the `exit_on_fail` option.
74
+
75
+ ```ruby
76
+ before("apply"
77
+ on: "web/deployment",
78
+ execute: "/command/will/fail/but/will/continue",
79
+ exit_on_fail: false,
80
+ )
81
+ ```
82
+
83
+ {% include config/hooks/options.md command="kubectl" %}
@@ -0,0 +1,67 @@
1
+ ---
2
+ title: Kubes Hooks
3
+ nav_text: Kubes
4
+ categories: hooks
5
+ ---
6
+
7
+ You can use hooks to run scripts at specific steps of the `kubes deploy` lifecycle.
8
+
9
+ ## Lifecycle Hooks
10
+
11
+ Hook | Description
12
+ ---|---
13
+ compile | When kubes compiles the `.kubes/resources` to `.kubes/output`.
14
+ apply | When kubes runs all the `kubectl apply` commands.
15
+ delete | When kubes runs all the `kubectl delete` commands.
16
+
17
+ ## Lifecycle At Kubes Level
18
+
19
+ These lifecycle points occur at a higher-level than the `kubectl` commands. Here's an example to help explain:
20
+
21
+ $ kubes apply
22
+ => kubectl apply -f .kubes/output/shared/namespace.yaml
23
+ => kubectl apply -f .kubes/output/web/service.yaml
24
+ => kubectl apply -f .kubes/output/web/deployment.yaml
25
+ $
26
+
27
+ Kubes calls out to `kubectl apply` 3 times for each resource kind.
28
+
29
+ The kubes hooks run before and after **all** the `kubectl apply` commands. So the hook only runs once.
30
+
31
+ $ kubes apply
32
+ # kubes apply before hook <= HERE
33
+ => kubectl apply -f .kubes/output/shared/namespace.yaml
34
+ => kubectl apply -f .kubes/output/web/service.yaml
35
+ => kubectl apply -f .kubes/output/web/deployment.yaml
36
+ # kubes apply after hook <= HERE
37
+ $
38
+
39
+ ## Example
40
+
41
+ .kubes/config/hooks/kubes.rb
42
+
43
+ ```ruby
44
+ before("apply",
45
+ execute: "echo 'kubes before apply hook'",
46
+ )
47
+
48
+ after("apply",
49
+ execute: "echo 'kubes after apply hook'",
50
+ )
51
+ ```
52
+
53
+ Example results:
54
+
55
+ $ kubes apply
56
+ Running kubes before apply hook.
57
+ => echo 'kubes before apply hook'
58
+ kubes before apply hook
59
+ => kubectl apply -f .kubes/output/shared/namespace.yaml
60
+ => kubectl apply -f .kubes/output/web/service.yaml
61
+ => kubectl apply -f .kubes/output/web/deployment.yaml
62
+ Running kubes after apply hook.
63
+ => echo 'kubes after apply hook'
64
+ kubes after apply hook
65
+ $
66
+
67
+ {% include config/hooks/options.md command="kubes" %}
@@ -0,0 +1,74 @@
1
+ ---
2
+ title: Ruby Hooks
3
+ nav_text: Ruby
4
+ categories: hooks
5
+ ---
6
+
7
+ The hook `execute` option can also be provided Ruby code instead of a string. Here's how it works:
8
+
9
+ 1. When the execute option is a String: Kubes will shell out and run it as a script.
10
+ 2. When the execute option is a Ruby object: Kubes will perform the `call` method on the object or class.
11
+
12
+ ## Ruby Class
13
+
14
+ When the Ruby object is a class with an instance method `call`, Kubes creates a new instance of the class and runs its `call` method. Example:
15
+
16
+ .kubes/config/hooks/kubes.rb
17
+
18
+ ```ruby
19
+ class EnvExporter
20
+ def call
21
+ ENV['SECRET_FOO'] = Base64.encode64("hi").strip
22
+ end
23
+ end
24
+
25
+ before("compile",
26
+ execute: EnvExporter,
27
+ )
28
+ ```
29
+
30
+ Kubes will do something like this:
31
+
32
+ ```ruby
33
+ EnvExporter.new.call
34
+ ```
35
+
36
+ The example sets the `SECRET_FOO` environment variable. It is then available from ERB in the kubes resource files. For example:
37
+
38
+ .kubes/resources/shared/secret.yaml
39
+
40
+ ```yaml
41
+ metadata:
42
+ namespace: garden
43
+ name: demo-secret
44
+ labels:
45
+ app: garden
46
+ apiVersion: v1
47
+ kind: Secret
48
+ data:
49
+ foo: <%= ENV['SECRET_FOO']
50
+ ```
51
+
52
+ ## Ruby Object
53
+
54
+ When the Ruby object, Kubes expects it to have a `call` method and will run it. Example:
55
+
56
+ .kubes/config/hooks/kubes.rb
57
+
58
+ ```ruby
59
+ before("compile",
60
+ execute: lambda { ENV['SECRET_FOO'] = Base64.encode64("hi2").strip }
61
+ )
62
+ ```
63
+
64
+ Kubes will do something like this:
65
+
66
+ ```ruby
67
+ @hook[:execute].call
68
+ ```
69
+
70
+ ## Process Context
71
+
72
+ The context in which the hook runs is worth highlighting. When the `execute` option is a String, Kubes runs the script in a **new** child process. This the script is an independent process, and whatever is done to its environment is segregated.
73
+
74
+ When the `execute` option a Ruby object, then Kubes runs the hook within the **same** process. It means the hook can affect the **same** environment. IE: Setting environment variables.