kubes 0.8.2 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f66db42d33089c27d90ea7daa749ae0e2b8298a06d5bd5a554c7bc2936a6734f
4
- data.tar.gz: bde5c65bfb606523754dd653c1067a2ed99ccf94c7c88ce496df2409d5581fd6
3
+ metadata.gz: f84754c7f4ac3bb6b4cf9265e9a1996790e16f1a0d559c84a2b12bfd389a08c8
4
+ data.tar.gz: 952b720a88afa528925d0fe4f910b211d7891d930903ae36e8e7e35b69eec003
5
5
  SHA512:
6
- metadata.gz: 940b22e57b741854513e1cee3367648189267ee34d1bd9ad4e0e07687ccc8d9d49f25b24977e43209e31af3967f7a7d47f251f5a0812b52d02f2a2cc64ad03c4
7
- data.tar.gz: 89a6be8317b8e1a0aa49158f54376504d7f914ae4f8d2fd22845df23d1fb7cee1574d1ac6ef9416d14d3a793908b1d30ed8b624300cf6722512f8d46987f3b58
6
+ metadata.gz: c706ad8181772d2c7dbcee9de65d96548068de2840641786c58bc7fdfa1bbe6b1173dc8ec787ad42ef60d02bcce5f6ebc3f56d60549087c72d6f17a9a8cdbb34
7
+ data.tar.gz: 4282f36a11382932f19f355c1e9c9f286c191f9486f37de9328719f8ae8b3636f2266751f65c896fd31018396ddadc00803b6b064d83836c9023c751539575a3
data/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
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.8.6] - 2022-02-16
7
+ - [#62](https://github.com/boltops-tools/kubes/pull/62) config map files: add Kubes.app txt layer
8
+
9
+ ## [0.8.5] - 2022-02-16
10
+ - [#61](https://github.com/boltops-tools/kubes/pull/61) add erb support for config_map_files and generic_secret_data helpers
11
+
12
+ ## [0.8.4] - 2022-02-16
13
+ - bump kubes_aws and kubes_google dependencies
14
+
15
+ ## [0.8.3] - 2022-02-16
16
+ - [#60](https://github.com/boltops-tools/kubes/pull/60) Config files
17
+
6
18
  ## [0.8.2] - 2022-02-07
7
19
  - improve gem dependency version specifiers
8
20
 
@@ -0,0 +1,55 @@
1
+ ---
2
+ title: AWS Secrets
3
+ nav_text: Secrets Data
4
+ categories: helpers-aws
5
+ ---
6
+
7
+ The `aws_secret_data` helper fetches secret data that is designed to be in one single file from AWS Secrets.
8
+
9
+ ## Example
10
+
11
+ For example if you have these secret values stored as one file with multiple values separated by `=`.
12
+
13
+ $ aws secretsmanager get-secret-value --secret-id demo-dev-secret-data | jq '.SecretString'
14
+ KEY1=secretvalue1
15
+ KEY2=secretvalue2
16
+
17
+ Kubes can fetch the secret data and base64 encode the values properly. Example:
18
+
19
+ .kubes/resources/shared/secret.yaml
20
+
21
+ ```yaml
22
+ apiVersion: v1
23
+ kind: Secret
24
+ metadata:
25
+ name: demo
26
+ labels:
27
+ app: demo
28
+ data:
29
+ <%= aws_secret_data("demo-dev-secret-data") %>
30
+ ```
31
+
32
+ Notice how the text is idented properly by 2 spaces and the values are automatically base64 encoded.
33
+
34
+ .kubes/output/shared/secret.yaml
35
+
36
+ ```yaml
37
+ metadata:
38
+ namespace: demo
39
+ name: demo-2a78a13682
40
+ labels:
41
+ app: demo
42
+ apiVersion: v1
43
+ kind: Secret
44
+ data:
45
+ KEY1: c2VjcmV0dmFsdWUx
46
+ KEY2: c2VjcmV0dmFsdWUy
47
+ ```
48
+
49
+ ## Options
50
+
51
+ Here's an example of the available options for `aws_secret_data`.
52
+
53
+ ```ruby
54
+ aws_secret_data("demo-#{Kubes.env}-secret-data", base64: true, ident: 2)
55
+ ```
@@ -0,0 +1,64 @@
1
+ ---
2
+ title: Config Map Files
3
+ nav_text: Config Map Files
4
+ ---
5
+
6
+ The `config_map_files` helper allows you to add config map data from a list of files. The files support layerying.
7
+
8
+ ## Example
9
+
10
+ Here's how to use it.
11
+
12
+ .kubes/resources/shared/config_map.yaml
13
+
14
+ ```yaml
15
+ apiVersion: v1
16
+ kind: ConfigMap
17
+ metadata:
18
+ name: demo
19
+ labels:
20
+ app: demo
21
+ data:
22
+ <%= config_map_files %>
23
+ ```
24
+
25
+ You can conveniently set multiple configmap values in files like so:
26
+
27
+ .kubes/resources/shared/config_map/base.txt
28
+
29
+ KEY1=cmvalue1
30
+ KEY2=cmvalue2
31
+
32
+ .kubes/resources/shared/config_map/dev.txt
33
+
34
+ KEY2=cmvalue2-dev-override
35
+ KEY3=cmvalue3
36
+
37
+ The resulting generated ConfigMap will be:
38
+
39
+ ```yaml
40
+ ---
41
+ metadata:
42
+ namespace: demo-dev
43
+ labels:
44
+ app: demo
45
+ name: demo-928146dd24
46
+ apiVersion: v1
47
+ kind: ConfigMap
48
+ data:
49
+ KEY1: cmvalue1
50
+ KEY2: cmvalue2-dev-override
51
+ KEY3: cmvalue3
52
+ ```
53
+
54
+ ## Layering Details
55
+
56
+ Layering for Config Map Files and also supports app-scoped layers.
57
+
58
+ Name | Example
59
+ --- | ---
60
+ configmap root | .kubes/resources/shared/config_map/{base,dev}.txt
61
+ configmap app file | .kubes/resources/shared/config_map/app1.txt
62
+ configmap app folder | .kubes/resources/shared/config_map/app1/{base,dev}.txt
63
+
64
+ So if `KUBES_APP=app1`, then the app-scoped layer is also used. This handles the [Central Deployer Pattern]({% link _docs/patterns/central-deployer.md %}).
@@ -0,0 +1,16 @@
1
+ ---
2
+ title: Core Built-In Helpers
3
+ ---
4
+
5
+ Kubes provides some helper methods to help write Kubernetes YAML files. Here's a list of the helper methods. These are available whether you write your resources in YAML or DSL.
6
+
7
+ Helper | Description
8
+ --- | ---
9
+ decode64 | Base64 decode a string.
10
+ docker_image | Method refers to the latest Docker image built by Kubes. This spares you from having to update the image manually in the deployment resource. Note, this can be overridden with the `--image` cli option or the `Kubes.config.image` setting. See: [Docker Image]({% link _docs/intro/docker-image.md %})
11
+ dockerfile_port | Exposed port extracted from the Dockerfile of the project.
12
+ encode64 | Base64 encode a string. Also available as `base64` method.
13
+ extra | The `KUBES_EXTRA` value.
14
+ with_extra | Appends the `KUBES_EXTRA` value to a string if it's set. It's covered in the [Extra Env Docs]({% link _docs/extra-env.md %}).
15
+
16
+ Here's also the source code with most of the helpers: [helpers.rb](https://github.com/boltops-tools/kubes/blob/master/lib/kubes/compiler/shared/helpers.rb).
@@ -0,0 +1,55 @@
1
+ ---
2
+ title: Google Secrets
3
+ nav_text: Secrets Data
4
+ categories: helpers-google
5
+ ---
6
+
7
+ The `google_secret_data` helper fetches secret data that is designed to be in one single file from Google Secrets.
8
+
9
+ ## Example
10
+
11
+ For example if you have these secret values stored as one file with multiple values separated by `=`.
12
+
13
+ $ gcloud secrets versions access latest --secret demo-dev-secret-data
14
+ KEY1=secretvalue1
15
+ KEY2=secretvalue2
16
+
17
+ Kubes can fetch the secret data and base64 encode the values properly. Example:
18
+
19
+ .kubes/resources/shared/secret.yaml
20
+
21
+ ```yaml
22
+ apiVersion: v1
23
+ kind: Secret
24
+ metadata:
25
+ name: demo
26
+ labels:
27
+ app: demo
28
+ data:
29
+ <%= google_secret_data("demo-dev-secret-data") %>
30
+ ```
31
+
32
+ Notice how the text is idented properly by 2 spaces and the values are automatically base64 encoded.
33
+
34
+ .kubes/output/shared/secret.yaml
35
+
36
+ ```yaml
37
+ metadata:
38
+ namespace: demo
39
+ name: demo-2a78a13682
40
+ labels:
41
+ app: demo
42
+ apiVersion: v1
43
+ kind: Secret
44
+ data:
45
+ KEY1: c2VjcmV0dmFsdWUx
46
+ KEY2: c2VjcmV0dmFsdWUy
47
+ ```
48
+
49
+ ## Options
50
+
51
+ Here's an example of the available options for `google_secret_data`.
52
+
53
+ ```ruby
54
+ google_secret_data("demo-#{Kubes.env}-secret-data", base64: true, ident: 2)
55
+ ```
@@ -2,18 +2,9 @@
2
2
  title: Helpers
3
3
  ---
4
4
 
5
- Kubes provides some helper methods to help write Kubernetes YAML files. Here's a list of the helper methods. These are available whether you write your resources in YAML or DSL.
6
-
7
- Helper | Description
8
- --- | ---
9
- decode64 | Base64 decode a string.
10
- docker_image | Method refers to the latest Docker image built by Kubes. This spares you from having to update the image manually in the deployment resource. Note, this can be overridden with the `--image` cli option or the `Kubes.config.image` setting. See: [Docker Image]({% link _docs/intro/docker-image.md %})
11
- dockerfile_port | Exposed port extracted from the Dockerfile of the project.
12
- encode64 | Base64 encode a string. Also available as `base64` method.
13
- extra | The `KUBES_EXTRA` value.
14
- with_extra | Appends the `KUBES_EXTRA` value to a string if it's set. It's covered in the [Extra Env Docs]({% link _docs/extra-env.md %}).
15
-
16
- Here's also the source code with most of the helpers: [helpers.rb](https://github.com/boltops-tools/kubes/blob/master/lib/kubes/compiler/shared/helpers.rb).
5
+ ## Built-In Helpers
6
+
7
+ Kubes provides core helper methods to help write Kubernetes YAML files. Docs: [Built-In Helpers]({% link _docs/helpers/builtin.md %}).
17
8
 
18
9
  ## DSL Specific Methods
19
10
 
@@ -153,7 +153,11 @@
153
153
  </li>
154
154
  <li><a href="{% link _docs/helpers.md %}">Helpers</a>
155
155
  <ul>
156
- <li><a href="{% link _docs/helpers/custom.md %}">Custom</a></li>
156
+ <li><a href="{% link _docs/helpers/builtin.md %}">Built-In</a>
157
+ <ul>
158
+ <li><a href="{% link _docs/helpers/builtin/config-map-files.md %}">Config Map Files</a>
159
+ </ul>
160
+ </li>
157
161
  <li><a href="{% link _docs/helpers/aws.md %}">AWS</a>
158
162
  <ul>
159
163
  {% assign docs = site.docs | where: "categories","helpers-aws" %}
@@ -192,6 +196,7 @@
192
196
  {% endfor %}
193
197
  </ul>
194
198
  </li>
199
+ <li><a href="{% link _docs/helpers/custom.md %}">Custom</a></li>
195
200
  </ul>
196
201
  </li>
197
202
  <li><a href="{% link _docs/patterns.md %}">Patterns</a>
data/kubes.gemspec CHANGED
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "zeitwerk"
31
31
 
32
32
  # core helper libs
33
- spec.add_dependency "kubes_aws", ">= 0.3.1"
34
- spec.add_dependency "kubes_google", ">= 0.3.8"
33
+ spec.add_dependency "kubes_aws", ">= 0.3.2"
34
+ spec.add_dependency "kubes_google", ">= 0.3.9"
35
35
 
36
36
  spec.add_development_dependency "bundler"
37
37
  spec.add_development_dependency "byebug"
@@ -0,0 +1,37 @@
1
+ module Kubes::Compiler::Shared::Helpers
2
+ module ConfigMapHelper
3
+ def config_map_files(options={})
4
+ indent = options[:indent] || 2
5
+
6
+ shared_config_map = "#{Kubes.root}/.kubes/resources/shared/config_map"
7
+ layers = [
8
+ [shared_config_map, "base.txt"],
9
+ [shared_config_map, "#{Kubes.env}.txt"],
10
+ ]
11
+ if Kubes.app
12
+ layers += [
13
+ [shared_config_map, "#{Kubes.app}.txt"],
14
+ [shared_config_map, Kubes.app, "base.txt"],
15
+ [shared_config_map, Kubes.app, "#{Kubes.env}.txt"],
16
+ ]
17
+ end
18
+ layers.map! { |layer| layer.compact.join('/') }
19
+ data = {}
20
+ layers.each do |path|
21
+ next unless File.exist?(path)
22
+ text = RenderMePretty.result(path, context: self)
23
+ lines = text.split("\n")
24
+ lines.each do |line|
25
+ key, value = parse_env_like_line(line)
26
+ data[key] = value
27
+ end
28
+ end
29
+
30
+ spacing = " " * indent
31
+ lines = data.map do |key,value|
32
+ "#{spacing}#{key}: #{value}"
33
+ end
34
+ lines.join("\n")
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ module Kubes::Compiler::Shared::Helpers
2
+ module DockerHelper
3
+ def docker_image
4
+ return @options[:image] if @options[:image] # override
5
+ return Kubes.config.image if Kubes.config.image
6
+ built_image_helper
7
+ end
8
+
9
+ def built_image
10
+ Deprecated.new.built_image
11
+ built_image_helper
12
+ end
13
+
14
+ def built_image_helper
15
+ path = Kubes.config.state.path
16
+ unless File.exist?(path)
17
+ raise Kubes::MissingDockerImage.new("Missing file with docker image built by kubes: #{path}. Try first running: kubes docker build")
18
+ end
19
+ data = JSON.load(IO.read(path))
20
+ data['image']
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module Kubes::Compiler::Shared::Helpers
2
+ module ExtraHelper
3
+ def with_extra(value)
4
+ [value, extra].compact.join('-')
5
+ end
6
+
7
+ def extra
8
+ extra = ENV['KUBES_EXTRA']
9
+ extra&.strip&.empty? ? nil : extra # if blank string then also return nil
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,45 @@
1
+ module Kubes::Compiler::Shared::Helpers
2
+ module SecretHelper
3
+ # Meant to be used by plugins. IE:
4
+ # google_secret_data and aws_secret_data
5
+ def generic_secret_data(plugin_secret_method, name, options={})
6
+ indent = options[:indent] || 2
7
+ base64 = options[:base64].nil? ? true : options[:base64]
8
+
9
+ text = send(plugin_secret_method, name, base64: false)
10
+ path = create_generic_secret_data_temp_file(text)
11
+ text = RenderMePretty.result(path, context: self)
12
+ spacing = " " * indent
13
+ lines = text.split("\n")
14
+ new_lines = lines.map do |line|
15
+ key, value = parse_env_like_line(line)
16
+ value = encode64(value) if base64
17
+ "#{spacing}#{key}: #{value}"
18
+ end
19
+ new_lines.join("\n")
20
+ end
21
+
22
+ def parse_env_like_line(line)
23
+ key, *rest = line.split('=')
24
+ value = rest.join('=')
25
+ [key, value]
26
+ end
27
+
28
+ def encode64(v)
29
+ Base64.strict_encode64(v.to_s).strip
30
+ end
31
+ alias_method :base64, :encode64
32
+
33
+ def decode64(v)
34
+ Base64.strict_decode64(v)
35
+ end
36
+
37
+ private
38
+ def create_generic_secret_data_temp_file(text)
39
+ path = "/tmp/kubes/text.erb"
40
+ FileUtils.mkdir_p(File.dirname(path))
41
+ IO.write(path, text)
42
+ path
43
+ end
44
+ end
45
+ end
@@ -6,42 +6,9 @@ module Kubes::Compiler::Shared
6
6
  extend Kubes::Compiler::Dsl::Core::Fields
7
7
  fields "name"
8
8
 
9
- def docker_image
10
- return @options[:image] if @options[:image] # override
11
- return Kubes.config.image if Kubes.config.image
12
- built_image_helper
13
- end
14
-
15
- def built_image
16
- Deprecated.new.built_image
17
- built_image_helper
18
- end
19
-
20
- def built_image_helper
21
- path = Kubes.config.state.path
22
- unless File.exist?(path)
23
- raise Kubes::MissingDockerImage.new("Missing file with docker image built by kubes: #{path}. Try first running: kubes docker build")
24
- end
25
- data = JSON.load(IO.read(path))
26
- data['image']
27
- end
28
-
29
- def with_extra(value)
30
- [value, extra].compact.join('-')
31
- end
32
-
33
- def extra
34
- extra = ENV['KUBES_EXTRA']
35
- extra&.strip&.empty? ? nil : extra # if blank string then also return nil
36
- end
37
-
38
- def encode64(v)
39
- Base64.strict_encode64(v.to_s).strip
40
- end
41
- alias_method :base64, :encode64
42
-
43
- def decode64(v)
44
- Base64.strict_decode64(v)
45
- end
9
+ include ConfigMapHelper
10
+ include DockerHelper
11
+ include ExtraHelper
12
+ include SecretHelper
46
13
  end
47
14
  end
data/lib/kubes/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kubes
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.6"
3
3
  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.8.2
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-07 00:00:00.000000000 Z
11
+ date: 2022-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -156,28 +156,28 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 0.3.1
159
+ version: 0.3.2
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: 0.3.1
166
+ version: 0.3.2
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: kubes_google
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: 0.3.8
173
+ version: 0.3.9
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
- version: 0.3.8
180
+ version: 0.3.9
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: bundler
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -334,13 +334,17 @@ files:
334
334
  - docs/_docs/helpers/aws/advanced/secrets.md
335
335
  - docs/_docs/helpers/aws/advanced/ssm.md
336
336
  - docs/_docs/helpers/aws/iam-role.md
337
+ - docs/_docs/helpers/aws/secret_data.md
337
338
  - docs/_docs/helpers/aws/secrets.md
338
339
  - docs/_docs/helpers/aws/ssm.md
340
+ - docs/_docs/helpers/builtin.md
341
+ - docs/_docs/helpers/builtin/config-map-files.md
339
342
  - docs/_docs/helpers/custom.md
340
343
  - docs/_docs/helpers/google.md
341
344
  - docs/_docs/helpers/google/advanced.md
342
345
  - docs/_docs/helpers/google/advanced/secrets.md
343
346
  - docs/_docs/helpers/google/gke.md
347
+ - docs/_docs/helpers/google/secret_data.md
344
348
  - docs/_docs/helpers/google/secrets.md
345
349
  - docs/_docs/helpers/google/service-account.md
346
350
  - docs/_docs/install.md
@@ -665,7 +669,11 @@ files:
665
669
  - lib/kubes/compiler/dsl/syntax/service_account.rb
666
670
  - lib/kubes/compiler/layering.rb
667
671
  - lib/kubes/compiler/shared/helpers.rb
672
+ - lib/kubes/compiler/shared/helpers/config_map_helper.rb
668
673
  - lib/kubes/compiler/shared/helpers/deprecated.rb
674
+ - lib/kubes/compiler/shared/helpers/docker_helper.rb
675
+ - lib/kubes/compiler/shared/helpers/extra_helper.rb
676
+ - lib/kubes/compiler/shared/helpers/secret_helper.rb
669
677
  - lib/kubes/compiler/shared/runtime_helpers.rb
670
678
  - lib/kubes/compiler/strategy.rb
671
679
  - lib/kubes/compiler/strategy/base.rb