kubes 0.3.3 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/README.md +6 -5
- data/docs/_docs/ci/cloudbuild.md +2 -0
- data/docs/_docs/config/args.md +10 -0
- data/docs/_docs/config/args/docker.md +19 -0
- data/docs/_docs/config/args/kubectl.md +19 -0
- data/docs/_docs/config/docker.md +4 -40
- data/docs/_docs/config/env.md +1 -1
- data/docs/_docs/config/hooks.md +10 -0
- data/docs/_docs/config/hooks/docker.md +70 -0
- data/docs/_docs/config/hooks/kubectl.md +83 -0
- data/docs/_docs/config/hooks/kubes.md +67 -0
- data/docs/_docs/config/hooks/ruby.md +76 -0
- data/docs/_docs/config/kubectl.md +3 -54
- data/docs/_docs/config/reference.md +20 -0
- data/docs/_docs/config/skip.md +58 -0
- data/docs/_docs/dsl/resources.md +1 -1
- data/docs/_docs/dsl/resources/backend_config.md +1 -1
- data/docs/_docs/helpers.md +3 -2
- data/docs/_docs/intro.md +6 -3
- data/docs/_docs/learn/dsl/review-project.md +4 -2
- data/docs/_docs/learn/yaml/review-project.md +4 -2
- data/docs/_docs/{auto-context.md → misc/auto-context.md} +0 -0
- data/docs/_docs/{kustomize.md → misc/kustomize.md} +0 -0
- data/docs/_docs/misc/separate-steps.md +21 -0
- data/docs/_docs/patterns.md +4 -1
- data/docs/_docs/patterns/clock-web-worker.md +2 -0
- data/docs/_docs/patterns/migrations.md +123 -0
- data/docs/_docs/patterns/secrets.md +82 -0
- data/docs/_includes/config/hooks/options.md +20 -0
- data/docs/_includes/sidebar.html +35 -11
- data/docs/_reference/kubes-exec.md +14 -6
- data/docs/_reference/kubes-init.md +1 -0
- data/docs/_reference/kubes-logs.md +1 -0
- data/docs/_sass/theme.scss +25 -1
- data/kubes.gemspec +3 -0
- data/lib/kubes.rb +3 -0
- data/lib/kubes/cli.rb +20 -5
- data/lib/kubes/cli/apply.rb +2 -1
- data/lib/kubes/cli/base.rb +11 -0
- data/lib/kubes/cli/compile.rb +8 -0
- data/lib/kubes/cli/delete.rb +1 -1
- data/lib/kubes/cli/exec.rb +37 -6
- data/lib/kubes/cli/get.rb +3 -2
- data/lib/kubes/cli/init.rb +39 -2
- data/lib/kubes/cli/logs.rb +29 -4
- data/lib/kubes/cli/prune.rb +95 -0
- data/lib/kubes/compiler.rb +11 -7
- data/lib/kubes/compiler/decorator/base.rb +7 -1
- data/lib/kubes/compiler/decorator/{resources/secret.rb → hashable.rb} +5 -4
- data/lib/kubes/compiler/decorator/hashable/field.rb +53 -0
- data/lib/kubes/compiler/decorator/hashable/storage.rb +19 -0
- data/lib/kubes/compiler/decorator/post.rb +77 -0
- data/lib/kubes/compiler/decorator/pre.rb +12 -0
- data/lib/kubes/compiler/shared/helpers.rb +7 -2
- data/lib/kubes/compiler/strategy.rb +2 -2
- data/lib/kubes/compiler/strategy/base.rb +1 -1
- data/lib/kubes/compiler/strategy/result.rb +4 -6
- data/lib/kubes/config.rb +16 -11
- data/lib/kubes/docker/strategy/build/docker.rb +1 -1
- data/lib/kubes/docker/strategy/build/gcloud.rb +1 -1
- data/lib/kubes/docker/strategy/image_name.rb +1 -1
- data/lib/kubes/docker/strategy/push/docker.rb +1 -1
- data/lib/kubes/docker/strategy/push/gcloud.rb +1 -1
- data/lib/kubes/docker/strategy/utils.rb +1 -1
- data/lib/kubes/hooks/builder.rb +29 -15
- data/lib/kubes/hooks/concern.rb +10 -0
- data/lib/kubes/hooks/dsl.rb +2 -1
- data/lib/kubes/hooks/runner.rb +22 -0
- data/lib/kubes/kubectl.rb +21 -18
- data/lib/kubes/kubectl/batch.rb +8 -5
- data/lib/kubes/kubectl/{decider.rb → dispatcher.rb} +1 -1
- data/lib/kubes/kubectl/fetch/base.rb +13 -10
- data/lib/kubes/kubectl/fetch/deployment.rb +12 -13
- data/lib/kubes/kubectl/fetch/pods.rb +4 -15
- data/lib/kubes/kubectl/kustomize.rb +1 -1
- data/lib/kubes/kubectl/ordering.rb +12 -0
- data/lib/kubes/util/consider.rb +2 -1
- data/lib/kubes/util/sh.rb +1 -1
- data/lib/kubes/version.rb +1 -1
- data/lib/templates/dsl/.kubes/resources/base/all.rb.tt +6 -1
- data/lib/templates/dsl/.kubes/resources/shared/namespace.rb.tt +1 -1
- data/lib/templates/dsl/.kubes/resources/web/deployment.rb +1 -1
- data/lib/templates/yaml/.kubes/resources/base/all.yaml.tt +1 -1
- data/lib/templates/yaml/.kubes/resources/shared/namespace.yaml.tt +1 -1
- data/lib/templates/yaml/.kubes/resources/web/deployment.yaml.tt +1 -1
- data/spec/fixtures/decorators/deployment/both/envFrom.yaml +31 -0
- data/spec/fixtures/decorators/deployment/both/valueFrom.yaml +33 -0
- data/spec/fixtures/decorators/deployment/both/volumes.yaml +40 -0
- data/spec/fixtures/prune/capture.yaml +57 -0
- data/spec/fixtures/prune/fetch_items.yaml +268 -0
- data/spec/kubes/cli/prune_spec.rb +38 -0
- data/spec/kubes/compiler/decorator/{resources → post}/deployment_spec.rb +52 -6
- data/spec/kubes/compiler/decorator/{resources → post}/pod_spec.rb +2 -11
- metadata +57 -19
- data/lib/kubes/compiler/decorator.rb +0 -17
- data/lib/kubes/compiler/decorator/compile.rb +0 -12
- data/lib/kubes/compiler/decorator/resources/base.rb +0 -13
- data/lib/kubes/compiler/decorator/resources/container.rb +0 -76
- data/lib/kubes/compiler/decorator/resources/container/mapping.rb +0 -28
- data/lib/kubes/compiler/decorator/resources/deployment.rb +0 -10
- data/lib/kubes/compiler/decorator/resources/pod.rb +0 -10
- data/lib/kubes/compiler/decorator/write.rb +0 -14
- data/lib/kubes/docker/strategy/hooks.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70ab0b9bdb58186064b2ba54324059ec1944811a021f158a30f219cbd4a19711
|
4
|
+
data.tar.gz: cdccd15d027f75f1c439d1facff1ed9d0b2ef58b4600b289d6f9d7e8e63917cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23c2dddfd2608971f2d59a52f2df79cd23355e98ab1f3de1aa6611e94ea19c75d54dd744892148bbb27a0e6610fe1a952895fa0a9571cead2ef729c072f15821
|
7
|
+
data.tar.gz: b088738e2a3fa44157f2c340508ff1d87634550ebe63608c4b7a9c4241dd385019af03c132400381db4f4ea36057526afb832e1101860b745a8670b130b7ffa2
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,35 @@
|
|
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.2]
|
7
|
+
- #28 base64 helper
|
8
|
+
|
9
|
+
## [0.4.1]
|
10
|
+
- kubes init: default namespace now includes Kubes.env
|
11
|
+
- fix kubes deploy: compile it gets called once and output folder kept
|
12
|
+
- include kubes_google dependency helpers
|
13
|
+
|
14
|
+
## [0.4.0]
|
15
|
+
- #26 features: kubes vs kubectl hooks, prune, etc
|
16
|
+
- hooks: kubes, kubectl, docker breaking changes.
|
17
|
+
- hooks now in the .kubes/config/hooks folder.
|
18
|
+
- hook for kubectl supports `on` option for more control over when to run hook.
|
19
|
+
- generalize hasher
|
20
|
+
- auto prune hashed resources like ConfigMap and Secret
|
21
|
+
- kubes prune command for manual running
|
22
|
+
- support .yml extension also
|
23
|
+
- renamed exec `--name` to `--deployment` option.
|
24
|
+
- add `--pod` option to `exec` and `logs` command.
|
25
|
+
- fix md5 hash for multiple types within envFrom
|
26
|
+
- add skip config option
|
27
|
+
|
28
|
+
## [0.3.5]
|
29
|
+
- #25 small fixes: show pod and fetch items nil
|
30
|
+
|
31
|
+
## [0.3.4]
|
32
|
+
- #24 fix namespace newline and logs for single container
|
33
|
+
- #23 init namespace option
|
34
|
+
|
6
35
|
## [0.3.3]
|
7
36
|
- #22 logs -c option. fix kubes logs for pods with multiple containers
|
8
37
|
|
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
|
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
|
|
data/docs/_docs/ci/cloudbuild.md
CHANGED
@@ -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
|
+
```
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
title: Kubectl Args
|
3
|
+
nav_text: Kubectl
|
4
|
+
categories: args
|
5
|
+
---
|
6
|
+
|
7
|
+
Here are some examples of customizing the kubectl args.
|
8
|
+
|
9
|
+
.kubes/config/kubectl/args.rb
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
command("apply",
|
13
|
+
args: ["--validate=true"],
|
14
|
+
)
|
15
|
+
|
16
|
+
command("delete",
|
17
|
+
args: ["--grace-period=-1"],
|
18
|
+
)
|
19
|
+
```
|
data/docs/_docs/config/docker.md
CHANGED
@@ -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
|
-
|
31
|
+
See:
|
32
32
|
|
33
|
-
|
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 %})
|
data/docs/_docs/config/env.md
CHANGED
@@ -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 kubes 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 kubes 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,76 @@
|
|
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.strict_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
|
+
Note, the example above is used to explain how Ruby can be used as the execute option. For secrets, kubes supports secrets with some helpers. See: [Secrets Pattern Docs]({% link _docs/patterns/secrets.md %})
|
53
|
+
|
54
|
+
## Ruby Object
|
55
|
+
|
56
|
+
When the Ruby object, Kubes expects it to have a `call` method and will run it. Example:
|
57
|
+
|
58
|
+
.kubes/config/hooks/kubes.rb
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
before("compile",
|
62
|
+
execute: lambda { ENV['SECRET_FOO'] = Base64.strict_encode64("hi2").strip }
|
63
|
+
)
|
64
|
+
```
|
65
|
+
|
66
|
+
Kubes will do something like this:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
@hook[:execute].call
|
70
|
+
```
|
71
|
+
|
72
|
+
## Process Context
|
73
|
+
|
74
|
+
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.
|
75
|
+
|
76
|
+
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.
|