kubes 0.7.5 → 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +5 -5
  4. data/docs/_docs/config/reference.md +1 -0
  5. data/docs/_docs/dsl/resources.md +1 -1
  6. data/docs/_docs/dsl.md +3 -3
  7. data/docs/_docs/helpers/google/gke.md +1 -1
  8. data/docs/_docs/intro/how-kubes-works.md +2 -0
  9. data/docs/_docs/intro/structure.md +2 -2
  10. data/docs/_docs/layering/{merge.md → merge-dsl.md} +0 -0
  11. data/docs/_docs/layering/merge-options.md +76 -0
  12. data/docs/_docs/layering.md +1 -1
  13. data/docs/_docs/vs/helm.md +3 -3
  14. data/docs/_includes/layering/layers.md +12 -10
  15. data/docs/_includes/reference.md +1 -1
  16. data/docs/_includes/sidebar.html +2 -1
  17. data/docs/index.html +2 -2
  18. data/lib/kubes/cli/init.rb +2 -1
  19. data/lib/kubes/compiler/decorator/hashable/field.rb +41 -21
  20. data/lib/kubes/compiler/decorator/hashable.rb +1 -1
  21. data/lib/kubes/compiler/decorator/post.rb +12 -12
  22. data/lib/kubes/compiler/layering.rb +17 -15
  23. data/lib/kubes/compiler/shared/runtime_helpers.rb +1 -1
  24. data/lib/kubes/compiler.rb +2 -1
  25. data/lib/kubes/config.rb +3 -0
  26. data/lib/kubes/core.rb +1 -1
  27. data/lib/kubes/docker/args/default.rb +0 -4
  28. data/lib/kubes/util/consider.rb +2 -2
  29. data/lib/kubes/version.rb +1 -1
  30. data/lib/templates/yaml/.kubes/resources/base/deployment.yaml.tt +0 -3
  31. data/lib/templates/yaml/.kubes/resources/shared/namespace.yaml.tt +0 -2
  32. data/spec/fixtures/decorators/deployment/configMap/volumes-name-first.yaml +14 -0
  33. data/spec/fixtures/decorators/deployment/configMap/volumes-name-second.yaml +14 -0
  34. data/spec/fixtures/decorators/ingress/tls.yaml +12 -0
  35. data/spec/kubes/compiler/decorator/post/deployment_spec.rb +25 -0
  36. data/spec/kubes/compiler/decorator/post/ingress_spec.rb +22 -0
  37. metadata +13 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d1ec1d6ee1348fc20d3e56bca7f82275510eee4b6d7cc2d6830aa0ae21016a1
4
- data.tar.gz: 2edc8e10565bbeba2551e8b1463ebe2ea122c8c089413bbc41283daefb9eeceb
3
+ metadata.gz: 8ee8de54a6c00bee7cbcfec249f26c5adc0beaabe0ab5d47d87d2a26fb673f71
4
+ data.tar.gz: 5c2330ca0688b565f0db169e3c3ce776e51d59fc26375c2ebeee429939a81425
5
5
  SHA512:
6
- metadata.gz: 7d7ef397578596e7dc9c9225447073eb2d0dedd21b6429d6ee1febd1b5d45cebcea69171fd5d4ed1de1a45772824d919e9287a43306c0796e8d33c295eb250ce
7
- data.tar.gz: a3fc1e2e6ba21cbb820ccf290acda1f353bc536be0a72c769467314057a25dd83a1de93bac2aee461b5c3cb70abf59cb60ce83c5250a2e48f28197a311b46d64
6
+ metadata.gz: 77ca91f3c0ce775bb69f9ab3630fac958625426ee719186a1fc966262d633d31eaccf98fc7052e90f1c62f38c3ac0a365238cb17c769429c9100020a7d9e99c0
7
+ data.tar.gz: 8b8a284692016d2487bdcb281d757511f2bb5bc2d8db4614de0b1a9ff1c97075d38bf4a9eefa757c005f8244548d5a6ba606163315838f0f6600ad338ef38643
data/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
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.7.9] - 2021-11-07
7
+ - [#55](https://github.com/boltops-tools/kubes/pull/55) make helper methods available in variables files
8
+
9
+ ## [0.7.8] - 2021-10-29
10
+ - [#54](https://github.com/boltops-tools/kubes/pull/54) fix configMap and secret hash when not first element in Array
11
+
12
+ ## [0.7.7] - 2021-10-21
13
+ - [#51](https://github.com/boltops-tools/kubes/pull/51) add hash checksum for tls secretName
14
+ - [#52](https://github.com/boltops-tools/kubes/pull/52) add role all layer to pre_layers
15
+ - [#53](https://github.com/boltops-tools/kubes/pull/53) Merger options
16
+
17
+ ## [0.7.6] - 2021-10-12
18
+ - remove init yaml templates, removed duplication
19
+ - write full.yaml to .kubes/tmp instead
20
+
6
21
  ## [0.7.5] - 2021-06-03
7
22
  - [#47](https://github.com/boltops-tools/kubes/pull/47) add search
8
23
  - [#48](https://github.com/boltops-tools/kubes/pull/48) use deep_merge overwrite_arrays option fixes #45
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  [![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
10
10
 
11
- Kubernetes Deployment Tool: build docker image, compile Kubernetes YAML files, and apply them.
11
+ Kubernetes App Deploy Tool: build docker image, compile Kubernetes YAML files, and apply them.
12
12
 
13
13
  Please **watch/star** this repo to help grow and support the project.
14
14
 
@@ -17,8 +17,8 @@ Official Docs Site: [kubes.guru](https://kubes.guru)
17
17
  Kubes will:
18
18
 
19
19
  1. Build the docker image and push it to repo
20
- 2. Compile Kubernetes YAML files from YAML/ERB or a DSL and adjusts the Docker build image
21
- 3. Deploy via kubectl apply on the compiled Kubernetes YAML files
20
+ 2. Compile Kubernetes YAML files from YAML/ERB or a DSL with built Docker image
21
+ 3. Deploy via `kubectl apply` on the compiled Kubernetes YAML files
22
22
 
23
23
  ## Usage
24
24
 
@@ -42,7 +42,7 @@ Now, use `kubectl` directly in the proper order:
42
42
  kubectl apply -f .kubes/output/web/service.yaml
43
43
  kubectl apply -f .kubes/output/web/deployment.yaml
44
44
 
45
- You can also apply with kubes. This will compile the automatically files also.
45
+ You can also apply with kubes. This will automatically compile the files also.
46
46
 
47
47
  kubes apply
48
48
 
@@ -50,7 +50,7 @@ The deploy command, does all 3 steps: builds the docker image, compiles the `.ku
50
50
 
51
51
  kubes deploy
52
52
 
53
- ## Multiple Enviroments
53
+ ## Multiple Environments
54
54
 
55
55
  You can easily create multiple environments with the same YAML configs. Example:
56
56
 
@@ -20,3 +20,4 @@ repo_auto_auth | Whether or not to try to auth authorize docker repo registry if
20
20
  skip | List of resources to skip. Can also be set with the `KUBES_SKIP` env var. `KUBES_SKIP` should be a list of strings separated by spaces. It adds onto the `config.skip` option. | []
21
21
  state.path | Where to store the state file with the last build Docker image. | .kubes/state/KUBES_ENV/data.json
22
22
  suffix_hash | Whether or not to append suffix hash to ConfigMap and Secret | true
23
+ merger.options | Merger options that control how Hashes are merged. More info: [Merger Options]({% link _docs/layering/merge-options.md %}) | `{overwrite_arrays: true}`
@@ -6,7 +6,7 @@ Here's a list of the resources supported by the Kubes DSL.
6
6
 
7
7
  {% assign docs = site.docs | where: "categories","dsl" %}
8
8
  {% for doc in docs -%}
9
- * [{{ doc.nav_text }}]({{ doc.url }})
9
+ * [{{ doc.title }}]({{ doc.url }})
10
10
  {% endfor %}
11
11
 
12
12
  For resources, that are not supported, you can use the [Generic resource]({% link _docs/dsl/resources/generic.md %}) or use [YAML]({% link _docs/yaml.md %}) instead. You can use a mix of DSL and YAML definitions in the `.kubes/resources` folder.
data/docs/_docs/dsl.md CHANGED
@@ -58,9 +58,9 @@ Notice how `port` and `targetPort` correspond to `spec.ports.port` and `spec.por
58
58
 
59
59
  In general:
60
60
 
61
- * The DSL methods behave as reader methods when no arguments are passed to it. IE: `name "demo-web"` sets the value.
62
- * The DSL methods behave as writer methods when arguments are passed to it. IE: `name` returns the value.
61
+ * The DSL methods behave as reader methods when no arguments are passed to it. IE: `name` returns the value.
62
+ * The DSL methods behave as writer methods when arguments are passed to it. IE: `name "demo-web"` sets the value.
63
63
 
64
64
  ## Merge Behavior
65
65
 
66
- Generally, the merge should behave as expected. For example, map or Hash fields are merged together from multiple layers. Strings are simply replaced. See more details at [Layering Merge Behavior]({% link _docs/layering/merge.md %})
66
+ Generally, the merge should behave as expected. For example, map or Hash fields are merged together from multiple layers. Strings are simply replaced. See more details at [Layering Merge Behavior]({% link _docs/layering/merge-dsl.md %})
@@ -49,7 +49,7 @@ To build kubes as a Docker image entrypoint for [Google CloudBuild Custom Builde
49
49
 
50
50
  Be sure to set GOOGLE_PROJECT to your own project id.
51
51
 
52
- ## Example Codebuild YAML
52
+ ## Example Cloudbuild YAML
53
53
 
54
54
  cloudbuild.yaml:
55
55
 
@@ -20,6 +20,8 @@ The deploy command simpifily does all 3 steps: build, compile, and apply.
20
20
 
21
21
  kubes deploy
22
22
 
23
+ Kubes is very transparent about it does. It prints out the `kubectl` commands as they are being called.
24
+
23
25
  You can also run the `kubectl apply` only. The `kube apply` command compiles but will skip the docker build stage if it's already been built.
24
26
 
25
27
  kubes apply
@@ -34,10 +34,10 @@ Here's what a .kubes folder structure can look like this:
34
34
 
35
35
  Name | Description
36
36
  --- | ---
37
- base | The base folder is processed first and can be used to define common fields and resources. Learn more on the [Layering Docs]({% link _docs/layering.md %}).
38
37
  config | The config folder can be used to configure behavior of Kubes. The [docker]({% link _docs/config/docker.md %}) config is used to customize the docker command. The [env]({% link _docs/config/env.md %}) config is used to override `config.rb` settings on a `KUBES_ENV` basis. The [kubectl]({% link _docs/config/kubectl.md %}) config is used to customize the kubectl command.
39
38
  config.rb | The main thing to configure here is the repo to push the docker image to.
40
39
  output | Where kubes builds and writes the Kubernetes YAML to.
41
40
  resources | Where you define your Kubernetes resources.
42
- shared | The shared folder is where you can put shared resources. This folder gets applied first. More info: [Ordering]({% link _docs/intro/ordering.md %}).
41
+ resources/base | The base folder is processed first and can be used to define common fields and resources. Learn more on the [Layering Docs]({% link _docs/layering.md %}).
42
+ resources/shared | The shared folder is where you can put shared resources. This folder gets applied first. More info: [Ordering]({% link _docs/intro/ordering.md %}).
43
43
  state | Temporary state info that stores the built Docker image name.
File without changes
@@ -0,0 +1,76 @@
1
+ ---
2
+ title: Merge Options
3
+ ---
4
+
5
+ Underneath the hood, Kubes uses the [danielsdeleo/deep_merge](https://github.com/danielsdeleo/deep_merge) library to merge layers together. You can control the merge behavior options with [config.merger.options]({% link _docs/config/reference.md %}).
6
+
7
+ The default merge options is:
8
+
9
+ {overwrite_arrays: true}
10
+
11
+ You can control the merge behavior by setting:
12
+
13
+ .kubes/config.rb
14
+
15
+ ```ruby
16
+ Kubes.configure do |config|
17
+ # ...
18
+ config.merger.options = {overwrite_arrays: false}
19
+ end
20
+ ```
21
+
22
+ See the [danielsdeleo/deep_merge](https://github.com/danielsdeleo/deep_merge) docs for the different options.
23
+
24
+ ## Example of overwrite_arrays false
25
+
26
+ An example of where you might want to use `{overwrite_arrays: false}` is if you are using YAML and want a base sidecar container in all of your deployments.
27
+
28
+ .kubes/resources/base/deployment.yaml
29
+
30
+ ```yaml
31
+ spec:
32
+ template:
33
+ spec:
34
+ containers:
35
+ - name: sidecar
36
+ image: sidecar-image
37
+ ```
38
+
39
+ .kubes/resources/web/deployment.yaml
40
+
41
+ ```yaml
42
+ spec:
43
+ template:
44
+ metadata:
45
+ labels:
46
+ role: web
47
+ spec:
48
+ containers:
49
+ - name: web
50
+ image: <%= docker_image %>
51
+ ```
52
+
53
+ Produces:
54
+
55
+ ```yaml
56
+ # ...
57
+ spec:
58
+ template:
59
+ metadata:
60
+ labels:
61
+ role: web
62
+ spec:
63
+ containers:
64
+ - name: sidecar
65
+ image: sidecar-image
66
+ - name: web
67
+ image: gcr.io/boltops-learn/demo:kubes-2021-10-21T18-06-48
68
+ # ...
69
+ ```
70
+
71
+ However, using this merge behavior will also add additional ports if you are assigning a `targetPort` in the DSL. See:
72
+
73
+ * [DSL in service creates always default port 80 #45](https://github.com/boltops-tools/kubes/issues/45)
74
+ * [use deep_merge overwrite_arrays option #48](https://github.com/boltops-tools/kubes/pull/48)
75
+
76
+ Will welcome PRs for improvements.
@@ -7,4 +7,4 @@ Kubes supports layering files together so you can use the same Kubernetes files
7
7
  * [YAML Layering]({% link _docs/layering/yaml.md %})
8
8
  * [DSL Layering]({% link _docs/layering/dsl.md %})
9
9
  * [Mix Layering]({% link _docs/layering/mix.md %})
10
- * [Merge Behavior]({% link _docs/layering/merge.md %})
10
+ * [Merge Behavior]({% link _docs/layering/merge-dsl.md %})
@@ -4,7 +4,7 @@ nav_text: Helm
4
4
  categories: vs
5
5
  ---
6
6
 
7
- Though both Kubes and Helm can be used to deploy applications to Kubernetes, they work quite differently. Kubernetes is more focused on deploying your application. Helm is more like a package manager.
7
+ Kubes and Helm are quite different. Helm is a package manager tool. In contrast, Kubernetes is focused on deploying your application. While you can use package manager tools like Helm to deploy your application, application-focused deploy tools are better for the job. For example, apt-get and yum are also package manager tools. But few companies use `apt-get install` or `yum install` to deploy their application code. Instead, people usually use application-specific tools to deploy their web app.
8
8
 
9
9
  {% include vs/article.md %}
10
10
 
@@ -168,7 +168,7 @@ Helm supports a wide variety of hooks for the install, delete, upgrade, and roll
168
168
 
169
169
  Kubes also supports hook as the kubes-level; this is similar to the helm-level. Kubes also provide finer-grain control hooks at the kubectl-level.
170
170
 
171
- Overally, Helm and Kubes hooks work quite differently. We'll take a look at **some** examples:
171
+ Overall, Helm and Kubes hooks work quite differently. We'll take a look at **some** examples:
172
172
 
173
173
  ### Helm Hook Example
174
174
 
@@ -240,4 +240,4 @@ Kubes supports the deployment workflow. It can build the docker image from your
240
240
 
241
241
  ## Summary
242
242
 
243
- Helm and Kubes are quite different. Helm is a full-fledge package management. Kubes is a more focused on deployment. Both tools support templating logic to help keep your code DRY. Additionally, Kubes supports layering to merge YAML files together for DRYness. Kubes also helps you build your Docker images.
243
+ Helm and Kubes are quite different. Helm is a full-fledge package management tool. In contrast, Kubes is more focused on app deployment. Both tools support templating logic to help keep your code DRY. Additionally, Kubes supports layering to merge YAML files together for DRYness. Kubes also helps you build your Docker images.
@@ -11,6 +11,7 @@ Here's an example structure, so we can understand how layering works.
11
11
  ├── clock
12
12
  │ └── deployment.{{ include.ext }}
13
13
  └── web
14
+ ├── all.{{ include.ext }}
14
15
  ├── deployment
15
16
  │ ├── dev.{{ include.ext }}
16
17
  │ └── prod.{{ include.ext }}
@@ -34,16 +35,17 @@ Notes
34
35
 
35
36
  Here's a table showing the the full layering.
36
37
 
37
- Folder/Pattern | Example
38
- -------------------|--------------------------------------------
39
- base/all.{{ include.ext }} | base/all.{{ include.ext }}
40
- base/all/ENV.{{ include.ext }} | base/all/dev.{{ include.ext }}
41
- base/KIND.{{ include.ext }} | base/deployment.{{ include.ext }}
42
- base/KIND/base.{{ include.ext }} | base/deployment/base.{{ include.ext }}
43
- base/KIND/ENV.{{ include.ext }} | base/deployment/dev.{{ include.ext }}
44
- ROLE/KIND.{{ include.ext }} | web/deployment.{{ include.ext }}
45
- ROLE/KIND/base.{{ include.ext }} | web/deployment/base.{{ include.ext }}
46
- ROLE/KIND/ENV.{{ include.ext }} | web/deployment/dev.{{ include.ext }}
38
+ Type | Folder/Pattern | Example
39
+ ---|---|---
40
+ pre | base/all.{{ include.ext }} | base/all.{{ include.ext }}
41
+ pre | base/all/ENV.{{ include.ext }} | base/all/dev.{{ include.ext }}
42
+ pre | base/KIND.{{ include.ext }} | base/deployment.{{ include.ext }}
43
+ pre | base/KIND/base.{{ include.ext }} | base/deployment/base.{{ include.ext }}
44
+ pre | base/KIND/ENV.{{ include.ext }} | base/deployment/dev.{{ include.ext }}
45
+ pre | ROLE/all.{{ include.ext }} | web/all.{{ include.ext }}
46
+ main | ROLE/KIND.{{ include.ext }} | web/deployment.{{ include.ext }}
47
+ post | ROLE/KIND/base.{{ include.ext }} | web/deployment/base.{{ include.ext }}
48
+ post | ROLE/KIND/ENV.{{ include.ext }} | web/deployment/dev.{{ include.ext }}
47
49
 
48
50
  ## Real-World Uses
49
51
 
@@ -1,3 +1,3 @@
1
- Kubes is a Kubernetes deployment tool. It automates the deployment process. Kubes will:
1
+ Kubes is a Kubernetes deployment tool. It focuses on deploying your specific application. It is very good at automating the deployment process. Kubes will:
2
2
 
3
3
  {% include kubes-steps.md %}
@@ -97,7 +97,8 @@
97
97
  <li><a href="{% link _docs/layering/yaml.md %}">YAML</a></li>
98
98
  <li><a href="{% link _docs/layering/dsl.md %}">DSL</a></li>
99
99
  <li><a href="{% link _docs/layering/mix.md %}">Mix</a></li>
100
- <li><a href="{% link _docs/layering/merge.md %}">Merge Behavior</a></li>
100
+ <li><a href="{% link _docs/layering/merge-dsl.md %}">Merge DSL</a></li>
101
+ <li><a href="{% link _docs/layering/merge-options.md %}">Merge Options</a></li>
101
102
  </ul>
102
103
  </li>
103
104
  <li><a href="{% link _docs/dsl.md %}">DSL</a>
data/docs/index.html CHANGED
@@ -9,8 +9,8 @@ sidebar: false
9
9
  <div class="col-sm-8 col-sm-offset-2">
10
10
  <div class="header-content">
11
11
  <div class="header-content-inner">
12
- <h1>Kubes: Kubernetes Deployment Tool</h1>
13
- <h2>Kubes is a Kubernetes Deployment Tool. It builds the docker image, creates the Kubernetes YAML, and runs kubectl apply. It automates the deployment process and saves you precious finger-typing energy.</h2>
12
+ <h1>Kubes: Kubernetes App Deploy Tool</h1>
13
+ <h2>Kubes is a Kubernetes App Deployment Tool. It focuses on deploying your specific application. It builds the docker image, creates the Kubernetes YAML, and runs kubectl apply. It automates the deployment process and saves you precious finger-typing energy.</h2>
14
14
  </div>
15
15
  </div>
16
16
  </div>
@@ -86,10 +86,11 @@ class Kubes::CLI
86
86
  ignores = %w[
87
87
  .kubes/output
88
88
  .kubes/state
89
+ .kubes/tmp
89
90
  ].map {|l| "#{l}\n"} # the readlines will have lines with \n so keep consistent for processing
90
91
  if File.exist?(".gitignore")
91
92
  lines = IO.readlines(".gitignore")
92
- if lines.detect { |l| l.include?('.kubes/output') }
93
+ if lines.detect { |l| l.include?('.kubes/tmp') }
93
94
  return # early
94
95
  else
95
96
  lines += ignores
@@ -1,52 +1,72 @@
1
1
  class Kubes::Compiler::Decorator::Hashable
2
2
  class Field
3
- # item is full wrapper structure
3
+ # item is full structure
4
4
  #
5
- # secretRef: <--- wrapper
6
- # name: demo-secret
5
+ # secretRef: <--- wrapper_key
6
+ # name: demo-secret <--- target_key is 'name' from wrapper_map[wrapper_key]
7
7
  #
8
+ attr_reader :item # for debugging
8
9
  def initialize(item)
9
10
  @item = item
10
11
  end
11
12
 
12
13
  def hashable?
13
- x = @item.keys & map.keys
14
+ x = @item.keys & wrapper_map.keys
14
15
  !x.empty?
15
16
  end
16
17
 
17
18
  def kind
18
- wrapper =~ /configMap/ ? "ConfigMap" : "Secret"
19
+ wrapper_key =~ /configMap/ ? "ConfigMap" : "Secret"
19
20
  end
20
21
 
21
- # The key of the hashable value.
22
+ # The target key of the hashable value is that key used for find value to add hash
22
23
  #
23
24
  # envFrom:
24
- # - secretRef:
25
- # name: demo-secret <--- wrapper is 'name'
25
+ # - secretRef: <--- wrapper_key
26
+ # name: demo-secret <--- target_key is 'name' from wrapper_map[wrapper_key]
26
27
  #
27
- def key
28
- map[wrapper]
28
+ def target_key
29
+ wrapper_map[wrapper_key]
29
30
  end
30
31
 
31
32
  # The wrapper field is nested right above the item with the hashable value.
33
+ # Simple example:
32
34
  #
33
35
  # envFrom:
34
- # - secretRef: <--- wrapper
35
- # name: demo-secret
36
+ # - secretRef: <--- wrapper_key
37
+ # name: demo-secret <--- target_key is 'name' from wrapper_map[wrapper_key]
36
38
  #
37
- def wrapper
38
- @item.keys.first
39
+ # More complex example where there's a configMap.name key also on the same level.
40
+ #
41
+ # volumes:
42
+ # - name: config-map-volume
43
+ # configMap:
44
+ # name: demo-config-map
45
+ #
46
+ # Note: Wont work for case when there's are 2 matching wrapper_map keys,
47
+ # but don't think Kubernetes allows 2 matching wrapper_map keys.
48
+ # Example: This is invalid Kubernetes YAML.
49
+ #
50
+ # volumes:
51
+ # - name: config-map-volume
52
+ # configMap:
53
+ # name: demo-config-map
54
+ # secretRef:
55
+ # name: demo-seret
56
+ def wrapper_key
57
+ @item.keys.find { |k| wrapper_map.keys.include?(k) } # this key used for map[wrapper_key]
39
58
  end
40
59
 
41
60
  # wrapper element to key that stores the hashable value
42
- def map
61
+ def wrapper_map
43
62
  {
44
- 'configMapRef' => 'name',
45
- 'configMapKeyRef' => 'name',
46
- 'configMap' => 'name',
47
- 'secretRef' => 'name',
48
- 'secretKeyRef' => 'name',
49
- 'secret' => 'secretName',
63
+ 'configMapRef' => 'name', # containers.env.envFrom.configMapRef.name
64
+ 'configMapKeyRef' => 'name', # containers.env.valueFrom.configMapKeyRef.name
65
+ 'configMap' => 'name', # containers.env.envFrom.configMapRef.name
66
+ 'secretRef' => 'name', # containers.env.envFrom.secretRef.name
67
+ 'secretKeyRef' => 'name', # containers.env.valueFrom.secretKeyRef.name
68
+ 'secret' => 'secretName', # volumes.secret.secretName
69
+ 'tls' => 'secretName', # tls.secretName
50
70
  }
51
71
  end
52
72
  end
@@ -9,7 +9,7 @@ module Kubes::Compiler::Decorator
9
9
  name = @data.dig('metadata','name')
10
10
  return @data unless name
11
11
 
12
- # puts "name #{name}" # TODO: scope Kind so Secret and ConfigMap can have the same name...
12
+ # scope Kind so Secret and ConfigMap can have same name
13
13
  md5 = md5(@data)
14
14
  @data['metadata']['name'] = "#{name}-#{md5}"
15
15
  Storage.store(@data['kind'], name, md5)
@@ -16,12 +16,12 @@ module Kubes::Compiler::Decorator
16
16
  # hashable set from previous stack call
17
17
  if options[:hashable_field] && item.is_a?(Hash)
18
18
  field = options[:hashable_field]
19
- value_without_md5 = item[field.key]
19
+ value_without_md5 = item[field.target_key]
20
20
  @reset_hashable_field = true unless value_without_md5
21
21
  if field.hashable? && value_without_md5
22
22
  md5 = Hashable::Storage.fetch(field.kind, value_without_md5)
23
23
  v = [value_without_md5, md5].compact.join('-')
24
- item[field.key] = v
24
+ item[field.target_key] = v
25
25
  end
26
26
  end
27
27
 
@@ -29,10 +29,10 @@ module Kubes::Compiler::Decorator
29
29
  # Pretty tricky case. Given:
30
30
  #
31
31
  # envFrom:
32
- # - secretRef:
33
- # name: demo-secret
34
- # - configMapRef:
35
- # name: demo-config-map
32
+ # - secretRef: <--- wrapper_key
33
+ # name: demo-secret <--- target_key is 'name' from wrapper_map[wrapper_key]
34
+ # - configMapRef: <--- wrapper_key
35
+ # name: demo-config-map <--- target_key is 'name' from wrapper_map[wrapper_key]
36
36
  #
37
37
  # Need to reset the stored hashable_field in the call stack.
38
38
  # Else the field.kind is cached and the md5 look is incorrect
@@ -52,19 +52,19 @@ module Kubes::Compiler::Decorator
52
52
  #
53
53
  # 1. envFrom example
54
54
  # envFrom:
55
- # - secretRef:
56
- # name: demo-secret
55
+ # - secretRef: <--- wrapper_key
56
+ # name: demo-secret <--- target_key is 'name' from wrapper_map[wrapper_key]
57
57
  #
58
58
  # 2. valueFrom example
59
59
  # valueFrom:
60
- # secretKeyRef:
61
- # name: demo-secret
60
+ # secretKeyRef: <--- wrapper_key
61
+ # name: demo-secret <--- target_key is 'name' from wrapper_map[wrapper_key]
62
62
  # key: password
63
63
  #
64
64
  # 3. volumes example
65
65
  # volumes:
66
- # - secret:
67
- # secretName: demo-secret
66
+ # - secret: <--- wrapper_key
67
+ # secretName: demo-secret <--- target_key is 'name' from wrapper_map[wrapper_key]
68
68
  #
69
69
  # This is useful to capture for the next level of the stack call
70
70
  #
@@ -6,29 +6,21 @@ class Kubes::Compiler
6
6
  ext = File.extname(@path)
7
7
  kind = File.basename(@path).sub(ext,'') # IE: deployment
8
8
  kind = kind.pluralize if @block_form
9
+ role = @path.split('/')[-2] # .kubes/resources/web/deployment.yaml
9
10
  layers = [
10
- "all",
11
- "all/#{Kubes.env}",
12
- "#{kind}",
13
- "#{kind}/#{Kubes.env}",
11
+ "base/all",
12
+ "base/all/#{Kubes.env}",
13
+ "base/#{kind}",
14
+ "base/#{kind}/#{Kubes.env}",
15
+ "#{role}/all",
14
16
  ]
15
17
  layers = add_exts(layers)
16
18
  layers.map! do |layer|
17
- "#{Kubes.root}/.kubes/resources/base/#{layer}"
19
+ "#{Kubes.root}/.kubes/resources/#{layer}"
18
20
  end
19
21
  layers.select { |layer| File.exist?(layer) }
20
22
  end
21
23
 
22
- def add_exts(layers)
23
- layers.map do |layer|
24
- [
25
- "#{layer}.rb",
26
- "#{layer}.yaml",
27
- "#{layer}.yml",
28
- ]
29
- end.flatten
30
- end
31
-
32
24
  def post_layers
33
25
  return [] if Kubes.kustomize?
34
26
 
@@ -45,5 +37,15 @@ class Kubes::Compiler
45
37
  end
46
38
  layers.select { |layer| File.exist?(layer) }
47
39
  end
40
+
41
+ def add_exts(*layers)
42
+ layers.flatten.map do |layer|
43
+ [
44
+ "#{layer}.rb",
45
+ "#{layer}.yaml",
46
+ "#{layer}.yml",
47
+ ]
48
+ end.flatten
49
+ end
48
50
  end
49
51
  end
@@ -3,9 +3,9 @@ module Kubes::Compiler::Shared
3
3
  include Kubes::Compiler::Shared::Helpers
4
4
 
5
5
  def load_runtime_helpers
6
- load_custom_variables # also load custom variables
7
6
  load_plugin_helpers
8
7
  load_custom_helpers
8
+ load_custom_variables # also load custom variables
9
9
  end
10
10
 
11
11
  @@custom_helpers_loaded = false
@@ -57,7 +57,8 @@ module Kubes
57
57
  acc << IO.read(file)
58
58
  end
59
59
  content = full.join("\n")
60
- path = "#{Kubes.root}/.kubes/output/full.yaml"
60
+ path = "#{Kubes.root}/.kubes/tmp/full.yaml" # write to tmp instead of output so it doesnt interfere with kubes get
61
+ FileUtils.mkdir_p(File.dirname(path))
61
62
  IO.write(path, content)
62
63
  logger.debug "Compiled #{pretty(path)}"
63
64
  end
data/lib/kubes/config.rb CHANGED
@@ -43,6 +43,9 @@ module Kubes
43
43
 
44
44
  config.suffix_hash = true # append suffix hash to ConfigMap and Secret
45
45
 
46
+ config.merger = ActiveSupport::OrderedOptions.new
47
+ config.merger.options = {overwrite_arrays: true}
48
+
46
49
  config
47
50
  end
48
51
 
data/lib/kubes/core.rb CHANGED
@@ -37,7 +37,7 @@ module Kubes
37
37
 
38
38
  # wrapper to ensure we use the same deeper_merge options everywhere
39
39
  def deep_merge!(a, b)
40
- a.deeper_merge!(b, overwrite_arrays: true)
40
+ a.deeper_merge!(b, config.merger.options)
41
41
  a
42
42
  end
43
43
  end
@@ -22,10 +22,6 @@ module Kubes::Docker::Args
22
22
 
23
23
 
24
24
  private
25
- def common_args
26
- %w[--recursive -f ]
27
- end
28
-
29
25
  def resource_path
30
26
  [".kubes/output", @options[:role], resource].compact.join('/')
31
27
  end
@@ -3,8 +3,8 @@ module Kubes::Util
3
3
  def consider?(path)
4
4
  File.file?(path) &&
5
5
  !path.include?('/resources/base') &&
6
- !path.include?('/base.yaml') &&
7
- !path.include?('/base.yml')
6
+ !path.include?('/base.') &&
7
+ !path.include?('/all.')
8
8
  end
9
9
  end
10
10
  end
data/lib/kubes/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kubes
2
- VERSION = "0.7.5"
2
+ VERSION = "0.7.9"
3
3
  end
@@ -1,6 +1,3 @@
1
- metadata:
2
- labels:
3
- app: <%= app %>
4
1
  spec:
5
2
  selector:
6
3
  matchLabels:
@@ -2,5 +2,3 @@ apiVersion: v1
2
2
  kind: Namespace
3
3
  metadata:
4
4
  name: <%= namespace %>
5
- labels:
6
- app: <%= app %>
@@ -0,0 +1,14 @@
1
+ ---
2
+ # apiVersion: apps/v1
3
+ # kind: Deployment
4
+ # spec:
5
+ # template:
6
+ # spec:
7
+ # only including structure needed for spec
8
+ volumes:
9
+ - name: config-map-volume
10
+ configMap:
11
+ name: demo-config-map
12
+ items:
13
+ - key: k1
14
+ path: config-map.conf
@@ -0,0 +1,14 @@
1
+ ---
2
+ # apiVersion: apps/v1
3
+ # kind: Deployment
4
+ # spec:
5
+ # template:
6
+ # spec:
7
+ # only including structure needed for spec
8
+ volumes:
9
+ - configMap:
10
+ name: demo-config-map
11
+ items:
12
+ - key: k1
13
+ path: config-map.conf
14
+ name: config-map-volume
@@ -0,0 +1,12 @@
1
+ apiVersion: networking.k8s.io/v1
2
+ kind: Ingress
3
+ metadata:
4
+ name: web
5
+ spec:
6
+ tls:
7
+ - secretName: tls-secret
8
+ defaultBackend:
9
+ service:
10
+ name: web
11
+ port:
12
+ number: 80
@@ -135,4 +135,29 @@ describe Kubes::Compiler::Decorator::Post do
135
135
  end
136
136
  end
137
137
  end
138
+
139
+ context "order" do
140
+ # spec to fix issue https://github.com/boltops-tools/kubes/issues/49
141
+ describe "name first" do
142
+ let(:data) { fixture("configMap/volumes-name-first") }
143
+ it "run" do
144
+ decorator.run
145
+ data = decorator.data
146
+ volumes = data['volumes']
147
+ name = volumes[0]['configMap']['name']
148
+ expect(name).to eq("demo-config-map-fakehash-config")
149
+ end
150
+ end
151
+
152
+ describe "name second" do
153
+ let(:data) { fixture("configMap/volumes-name-second") }
154
+ it "run" do
155
+ decorator.run
156
+ data = decorator.data
157
+ volumes = data['volumes']
158
+ name = volumes[0]['configMap']['name']
159
+ expect(name).to eq("demo-config-map-fakehash-config")
160
+ end
161
+ end
162
+ end
138
163
  end
@@ -0,0 +1,22 @@
1
+ describe Kubes::Compiler::Decorator::Post do
2
+ let(:decorator) { described_class.new(data) }
3
+
4
+ def fixture(name)
5
+ YAML.load_file("spec/fixtures/decorators/ingress/#{name}.yaml")
6
+ end
7
+ before(:each) do
8
+ allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:fetch).and_return("fakehash")
9
+ end
10
+
11
+ context "ingress" do
12
+ describe "tls" do
13
+ let(:data) { fixture("tls") }
14
+ it "run" do
15
+ decorator.run
16
+ data = decorator.data
17
+ name = data['spec']['tls'][0]['secretName']
18
+ expect(name).to eq("tls-secret-fakehash")
19
+ end
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-03 00:00:00.000000000 Z
11
+ date: 2021-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -336,7 +336,8 @@ files:
336
336
  - docs/_docs/intro/structure.md
337
337
  - docs/_docs/layering.md
338
338
  - docs/_docs/layering/dsl.md
339
- - docs/_docs/layering/merge.md
339
+ - docs/_docs/layering/merge-dsl.md
340
+ - docs/_docs/layering/merge-options.md
340
341
  - docs/_docs/layering/mix.md
341
342
  - docs/_docs/layering/yaml.md
342
343
  - docs/_docs/learn/dsl.md
@@ -731,10 +732,13 @@ files:
731
732
  - spec/fixtures/decorators/deployment/both/volumes.yaml
732
733
  - spec/fixtures/decorators/deployment/configMap/envFrom.yaml
733
734
  - spec/fixtures/decorators/deployment/configMap/valueFrom.yaml
735
+ - spec/fixtures/decorators/deployment/configMap/volumes-name-first.yaml
736
+ - spec/fixtures/decorators/deployment/configMap/volumes-name-second.yaml
734
737
  - spec/fixtures/decorators/deployment/configMap/volumes.yaml
735
738
  - spec/fixtures/decorators/deployment/secret/envFrom.yaml
736
739
  - spec/fixtures/decorators/deployment/secret/valueFrom.yaml
737
740
  - spec/fixtures/decorators/deployment/secret/volumes.yaml
741
+ - spec/fixtures/decorators/ingress/tls.yaml
738
742
  - spec/fixtures/decorators/pod/configMap/envFrom.yaml
739
743
  - spec/fixtures/decorators/pod/configMap/valueFrom.yaml
740
744
  - spec/fixtures/decorators/pod/configMap/volumes.yaml
@@ -761,6 +765,7 @@ files:
761
765
  - spec/fixtures/syntax/.kubes/resources/web/pod.rb
762
766
  - spec/kubes/cli/prune_spec.rb
763
767
  - spec/kubes/compiler/decorator/post/deployment_spec.rb
768
+ - spec/kubes/compiler/decorator/post/ingress_spec.rb
764
769
  - spec/kubes/compiler/decorator/post/pod_spec.rb
765
770
  - spec/kubes/compiler/strategy/dispatcher_spec.rb
766
771
  - spec/kubes/compiler_spec.rb
@@ -791,7 +796,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
791
796
  - !ruby/object:Gem::Version
792
797
  version: '0'
793
798
  requirements: []
794
- rubygems_version: 3.2.5
799
+ rubygems_version: 3.1.6
795
800
  signing_key:
796
801
  specification_version: 4
797
802
  summary: 'Kubernetes Deployment Tool: build docker image, compile Kubernetes YAML
@@ -806,10 +811,13 @@ test_files:
806
811
  - spec/fixtures/decorators/deployment/both/volumes.yaml
807
812
  - spec/fixtures/decorators/deployment/configMap/envFrom.yaml
808
813
  - spec/fixtures/decorators/deployment/configMap/valueFrom.yaml
814
+ - spec/fixtures/decorators/deployment/configMap/volumes-name-first.yaml
815
+ - spec/fixtures/decorators/deployment/configMap/volumes-name-second.yaml
809
816
  - spec/fixtures/decorators/deployment/configMap/volumes.yaml
810
817
  - spec/fixtures/decorators/deployment/secret/envFrom.yaml
811
818
  - spec/fixtures/decorators/deployment/secret/valueFrom.yaml
812
819
  - spec/fixtures/decorators/deployment/secret/volumes.yaml
820
+ - spec/fixtures/decorators/ingress/tls.yaml
813
821
  - spec/fixtures/decorators/pod/configMap/envFrom.yaml
814
822
  - spec/fixtures/decorators/pod/configMap/valueFrom.yaml
815
823
  - spec/fixtures/decorators/pod/configMap/volumes.yaml
@@ -836,6 +844,7 @@ test_files:
836
844
  - spec/fixtures/syntax/.kubes/resources/web/pod.rb
837
845
  - spec/kubes/cli/prune_spec.rb
838
846
  - spec/kubes/compiler/decorator/post/deployment_spec.rb
847
+ - spec/kubes/compiler/decorator/post/ingress_spec.rb
839
848
  - spec/kubes/compiler/decorator/post/pod_spec.rb
840
849
  - spec/kubes/compiler/strategy/dispatcher_spec.rb
841
850
  - spec/kubes/compiler_spec.rb