kubernetes_template_rendering 0.1.0.pre.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +2 -2
- data/catalog-info.yaml +19 -0
- data/docs/CHANGELOG.md +1 -0
- data/docs/README.md +1 -0
- data/docs/adrs/0000-template.md +72 -0
- data/lib/kubernetes_template_rendering/cli.rb +3 -1
- data/lib/kubernetes_template_rendering/cli_arguments.rb +2 -1
- data/lib/kubernetes_template_rendering/resource.rb +11 -9
- data/lib/kubernetes_template_rendering/resource_set.rb +6 -3
- data/lib/kubernetes_template_rendering/template.rb +27 -8
- data/lib/kubernetes_template_rendering/template_directory_renderer.rb +12 -4
- data/lib/kubernetes_template_rendering/version.rb +1 -1
- data/mkdocs.yml +9 -0
- data/sig/kubernetes_template_rendering.rbs +4 -0
- metadata +10 -5
- data/sig/invoca/kubernetes_templates.rbs +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faeb29036b624168016b45f8b3ec72e0d39328a8a9a82c256125873264a49796
|
4
|
+
data.tar.gz: f5c5269ab942419534e0886cd5a8f015c77b5540b9ba2c8105c4bfa6ff6bb879
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6878a2582ffcf67e8466a260be80a1a6b29a52164bfe42d9737f15da07410245757ca7f232426c13b67bca27b420c26d800018bfe010f34887a76bd12c25a95d
|
7
|
+
data.tar.gz: 8f1c70852a002f85c23636bf25d120e2e7ac4a37c933c620c6c52e2c5ce3b66bd001073c25f95a9a339b67c2d0fd4a4d0f4cd000336b9f90558570122673a16b
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,13 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
5
5
|
Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [0.
|
7
|
+
## [0.2.0] - 2024-05-06
|
8
|
+
### Added
|
9
|
+
- Added support for passing `--source-repo` flag into command line so that the rendered manifest comments can include a link to the source repository.
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
- Updated the code comment to include the variable overrides used when rendering the current version of the templates
|
13
|
+
|
14
|
+
## [0.1.0] - 2024-04-22
|
8
15
|
|
9
16
|
- Initial release
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ To use this gem you can either install it, and use the `render_kubernetes_templa
|
|
24
24
|
|
25
25
|
### Example Usage
|
26
26
|
```bash
|
27
|
-
gem exec -g kubernetes_template_rendering
|
27
|
+
gem exec -g kubernetes_template_rendering render_templates \
|
28
28
|
--jsonnet-library-path deployment/vendor \
|
29
29
|
--rendered_directory path/to/resources \
|
30
30
|
deployment/templates
|
@@ -34,7 +34,7 @@ gem exec -g kubernetes_template_rendering render_kubernetes_templates \
|
|
34
34
|
|
35
35
|
To see a full list of options and how to use them, run the following command:
|
36
36
|
```bash
|
37
|
-
gem exec -g kubernetes_template_rendering
|
37
|
+
gem exec -g kubernetes_template_rendering render_templates --help
|
38
38
|
```
|
39
39
|
|
40
40
|
## Development
|
data/catalog-info.yaml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
apiVersion: backstage.io/v1alpha1
|
2
|
+
kind: Component
|
3
|
+
metadata:
|
4
|
+
name: kubernetes_template_rendering
|
5
|
+
title: Kubernetes Template Rendering gem
|
6
|
+
description: |
|
7
|
+
A Ruby gem that provides a way to render Kubernetes templates using ERB and Jsonnet.
|
8
|
+
annotations:
|
9
|
+
github.com/project-slug: invoca/kubernetes_template_rendering
|
10
|
+
backstage.io/adr-location: >-
|
11
|
+
https://github.com/Invoca/kubernetes_template_rendering/tree/main/docs/adrs
|
12
|
+
backstage.io/techdocs-ref: dir:.
|
13
|
+
buildkite.com/project-slug: invoca/kubernetes-template-rendering
|
14
|
+
invoca.com/version-repository-location: rubygems
|
15
|
+
invoca.com/version-repository-name: kubernetes_template_rendering
|
16
|
+
spec:
|
17
|
+
type: Library
|
18
|
+
lifecycle: production
|
19
|
+
owner: octothorpe
|
data/docs/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
../CHANGELOG.md
|
data/docs/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
../README.md
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# [short title of solved problem and solution]
|
2
|
+
|
3
|
+
* Status: [proposed | rejected | accepted | deprecated | … | superseded by [ADR-0005](0005-example.md)] <!-- optional -->
|
4
|
+
* Deciders: [list everyone involved in the decision] <!-- optional -->
|
5
|
+
* Date: [YYYY-MM-DD when the decision was last updated] <!-- optional -->
|
6
|
+
|
7
|
+
Technical Story: [description | ticket/issue URL] <!-- optional -->
|
8
|
+
|
9
|
+
## Context and Problem Statement
|
10
|
+
|
11
|
+
[Describe the context and problem statement, e.g., in free form using two to three sentences. You may want to articulate the problem in form of a question.]
|
12
|
+
|
13
|
+
## Decision Drivers <!-- optional -->
|
14
|
+
|
15
|
+
* [driver 1, e.g., a force, facing concern, …]
|
16
|
+
* [driver 2, e.g., a force, facing concern, …]
|
17
|
+
* … <!-- numbers of drivers can vary -->
|
18
|
+
|
19
|
+
## Considered Options
|
20
|
+
|
21
|
+
* [option 1]
|
22
|
+
* [option 2]
|
23
|
+
* [option 3]
|
24
|
+
* … <!-- numbers of options can vary -->
|
25
|
+
|
26
|
+
## Decision Outcome
|
27
|
+
|
28
|
+
Chosen option: "[option 1]", because [justification. e.g., only option, which meets k.o. criterion decision driver | which resolves force force | … | comes out best (see below)].
|
29
|
+
|
30
|
+
### Positive Consequences <!-- optional -->
|
31
|
+
|
32
|
+
* [e.g., improvement of quality attribute satisfaction, follow-up decisions required, …]
|
33
|
+
* …
|
34
|
+
|
35
|
+
### Negative Consequences <!-- optional -->
|
36
|
+
|
37
|
+
* [e.g., compromising quality attribute, follow-up decisions required, …]
|
38
|
+
* …
|
39
|
+
|
40
|
+
## Pros and Cons of the Options <!-- optional -->
|
41
|
+
|
42
|
+
### [option 1]
|
43
|
+
|
44
|
+
[example | description | pointer to more information | …] <!-- optional -->
|
45
|
+
|
46
|
+
* Good, because [argument a]
|
47
|
+
* Good, because [argument b]
|
48
|
+
* Bad, because [argument c]
|
49
|
+
* … <!-- numbers of pros and cons can vary -->
|
50
|
+
|
51
|
+
### [option 2]
|
52
|
+
|
53
|
+
[example | description | pointer to more information | …] <!-- optional -->
|
54
|
+
|
55
|
+
* Good, because [argument a]
|
56
|
+
* Good, because [argument b]
|
57
|
+
* Bad, because [argument c]
|
58
|
+
* … <!-- numbers of pros and cons can vary -->
|
59
|
+
|
60
|
+
### [option 3]
|
61
|
+
|
62
|
+
[example | description | pointer to more information | …] <!-- optional -->
|
63
|
+
|
64
|
+
* Good, because [argument a]
|
65
|
+
* Good, because [argument b]
|
66
|
+
* Bad, because [argument c]
|
67
|
+
* … <!-- numbers of pros and cons can vary -->
|
68
|
+
|
69
|
+
## Links <!-- optional -->
|
70
|
+
|
71
|
+
* [Link type] [Link to ADR] <!-- example: Refined by [ADR-0005](0005-example.md) -->
|
72
|
+
* … <!-- numbers of links can vary -->
|
@@ -32,6 +32,7 @@ module KubernetesTemplateRendering
|
|
32
32
|
op.on("--region=REGION", "set the specific region to render") { args.region = _1 }
|
33
33
|
op.on("--color=COLOR", "set the specific color to render") { args.color = _1 }
|
34
34
|
op.on("--[no-]prune", "enable/disable pruning of untouched resources") { args.prune = _1 }
|
35
|
+
op.on("--source-repo=SOURCE_REPO", "set the source repo for the rendered templates") { args.source_repo = _1 }
|
35
36
|
|
36
37
|
op.on("--variable-override=KEY:VALUE", "override a variable value set within definitions.yaml") do |override|
|
37
38
|
args.variable_overrides ||= {}
|
@@ -64,7 +65,8 @@ module KubernetesTemplateRendering
|
|
64
65
|
cluster_type: args.cluster_type,
|
65
66
|
region: args.region,
|
66
67
|
color: args.color,
|
67
|
-
variable_overrides: args.variable_overrides
|
68
|
+
variable_overrides: args.variable_overrides,
|
69
|
+
source_repo: args.source_repo
|
68
70
|
)
|
69
71
|
end
|
70
72
|
|
@@ -9,14 +9,16 @@ module KubernetesTemplateRendering
|
|
9
9
|
class Resource
|
10
10
|
class UnexpectedFileTypeError < StandardError; end
|
11
11
|
|
12
|
-
attr_reader :variables, :template_path, :output_directory
|
13
|
-
|
14
|
-
def initialize(template_path:, definitions_path:, variables:, output_directory:, output_filename: nil)
|
15
|
-
@template_path
|
16
|
-
@definitions_path
|
17
|
-
@variables
|
18
|
-
@
|
19
|
-
@
|
12
|
+
attr_reader :variables, :variable_overrides, :template_path, :output_directory, :source_repo
|
13
|
+
|
14
|
+
def initialize(template_path:, definitions_path:, variables:, output_directory:, output_filename: nil, variable_overrides: {}, source_repo: nil)
|
15
|
+
@template_path = template_path
|
16
|
+
@definitions_path = definitions_path
|
17
|
+
@variables = variables
|
18
|
+
@variable_overrides = variable_overrides
|
19
|
+
@output_directory = output_directory
|
20
|
+
@source_repo = source_repo
|
21
|
+
@output_filename = output_filename || template_filename(template_path)
|
20
22
|
end
|
21
23
|
|
22
24
|
def render(args)
|
@@ -26,7 +28,7 @@ module KubernetesTemplateRendering
|
|
26
28
|
private
|
27
29
|
|
28
30
|
def rendered_template(args)
|
29
|
-
@rendered_template ||= template_klass.render(@template_path, variables, jsonnet_library_path: args.jsonnet_library_path)
|
31
|
+
@rendered_template ||= template_klass.render(@template_path, variables, variable_overrides:, source_repo:, jsonnet_library_path: args.jsonnet_library_path)
|
30
32
|
end
|
31
33
|
|
32
34
|
def write_template(args)
|
@@ -12,9 +12,10 @@ module KubernetesTemplateRendering
|
|
12
12
|
class ResourceSet
|
13
13
|
attr_reader :variables, :output_directory, :deploy_group_config, :omitted_resources,
|
14
14
|
:template_directory, :target_output_directory, :regions, :colors,
|
15
|
-
:definitions_path, :kubernetes_cluster_type
|
15
|
+
:definitions_path, :kubernetes_cluster_type, :variable_overrides,
|
16
|
+
:source_repo
|
16
17
|
|
17
|
-
def initialize(config:, template_directory:, rendered_directory:, definitions_path:, kubernetes_cluster_type:)
|
18
|
+
def initialize(config:, template_directory:, rendered_directory:, definitions_path:, kubernetes_cluster_type:, variable_overrides: {}, source_repo: nil)
|
18
19
|
@variables = config["variables"] || {}
|
19
20
|
@deploy_group_config = config["deploy_groups"]
|
20
21
|
@omitted_resources = config["omitted_resources"]
|
@@ -25,6 +26,8 @@ module KubernetesTemplateRendering
|
|
25
26
|
@rendered_directory = rendered_directory
|
26
27
|
@definitions_path = definitions_path
|
27
28
|
@kubernetes_cluster_type = kubernetes_cluster_type
|
29
|
+
@variable_overrides = variable_overrides
|
30
|
+
@source_repo = source_repo
|
28
31
|
@resources = {}
|
29
32
|
|
30
33
|
if @kubernetes_cluster_type != "kube-platform"
|
@@ -185,7 +188,7 @@ module KubernetesTemplateRendering
|
|
185
188
|
|
186
189
|
def standard_resources(output_directory)
|
187
190
|
standard_template_paths.map do |path|
|
188
|
-
Resource.new(template_path: path, definitions_path
|
191
|
+
Resource.new(template_path: path, definitions_path:, variables:, output_directory:, variable_overrides:, source_repo:)
|
189
192
|
end
|
190
193
|
end
|
191
194
|
|
@@ -8,10 +8,13 @@ require "yaml"
|
|
8
8
|
# This is a base class for all Templates. Derived classes must implement the render method.
|
9
9
|
module KubernetesTemplateRendering
|
10
10
|
class Template < OpenStruct
|
11
|
-
attr_reader :template_path, :variables
|
12
|
-
|
13
|
-
|
14
|
-
@
|
11
|
+
attr_reader :template_path, :variables, :source_repo, :variable_overrides
|
12
|
+
|
13
|
+
def initialize(template_path, variables, source_repo: nil, variable_overrides: {})
|
14
|
+
@template_path = template_path
|
15
|
+
@variables = variables.merge(variable_overrides)
|
16
|
+
@source_repo = source_repo
|
17
|
+
@variable_overrides = variable_overrides
|
15
18
|
end
|
16
19
|
|
17
20
|
def render(args)
|
@@ -24,9 +27,25 @@ module KubernetesTemplateRendering
|
|
24
27
|
comment = <<~EOS
|
25
28
|
# WARNING: DO NO EDIT THIS FILE!
|
26
29
|
# Any changes made here will be lost.
|
27
|
-
# This file is autogenerated from #{
|
30
|
+
# This file is autogenerated from #{full_template_path}
|
28
31
|
EOS
|
29
|
-
comment + yaml_string
|
32
|
+
comment + variable_override_comment + yaml_string
|
33
|
+
end
|
34
|
+
|
35
|
+
def full_template_path
|
36
|
+
if source_repo
|
37
|
+
"https://github.com/#{source_repo}/blob/-/#{template_path.start_with?("/") ? template_path[1..-1] : template_path}"
|
38
|
+
else
|
39
|
+
template_path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def variable_override_comment
|
44
|
+
if variable_overrides&.any?
|
45
|
+
<<~EOS
|
46
|
+
# Variable overrides used: #{variable_overrides.to_json}
|
47
|
+
EOS
|
48
|
+
end || ""
|
30
49
|
end
|
31
50
|
|
32
51
|
class << self
|
@@ -43,8 +62,8 @@ module KubernetesTemplateRendering
|
|
43
62
|
# The ErbTemplate and JsonnetTemplate classes both inherit from the Template class and implement a render method.
|
44
63
|
# However, the erb_binding parameter is used just in ErbTemplate, while the jsonnet_library_path parameter is used just in JsonnetTemplate.
|
45
64
|
# This is a little awkward. Potentially this could be refactored.
|
46
|
-
def render(template_path, variables, erb_binding: nil, jsonnet_library_path: nil)
|
47
|
-
new(template_path, variables).render(erb_binding: erb_binding, jsonnet_library_path: jsonnet_library_path)
|
65
|
+
def render(template_path, variables, erb_binding: nil, jsonnet_library_path: nil, source_repo: nil, variable_overrides: {})
|
66
|
+
new(template_path, variables, source_repo:, variable_overrides:).render(erb_binding: erb_binding, jsonnet_library_path: jsonnet_library_path)
|
48
67
|
end
|
49
68
|
end
|
50
69
|
end
|
@@ -13,9 +13,9 @@ module KubernetesTemplateRendering
|
|
13
13
|
class TemplateDirectoryRenderer
|
14
14
|
DEFINITIONS_FILENAME = "definitions.yaml"
|
15
15
|
|
16
|
-
attr_reader :directories, :omitted_names, :rendered_directory, :cluster_type, :region, :color, :variable_overrides
|
16
|
+
attr_reader :directories, :omitted_names, :rendered_directory, :cluster_type, :region, :color, :variable_overrides, :source_repo
|
17
17
|
|
18
|
-
def initialize(directories:, rendered_directory:, omitted_names: [], cluster_type: nil, region: nil, color: nil, variable_overrides: nil)
|
18
|
+
def initialize(directories:, rendered_directory:, omitted_names: [], cluster_type: nil, region: nil, color: nil, variable_overrides: nil, source_repo: nil)
|
19
19
|
@directories = directories_with_definitions(Array(directories))
|
20
20
|
@omitted_names = Array(omitted_names)
|
21
21
|
@rendered_directory = rendered_directory
|
@@ -23,6 +23,7 @@ module KubernetesTemplateRendering
|
|
23
23
|
@region = region
|
24
24
|
@color = color
|
25
25
|
@variable_overrides = variable_overrides || {}
|
26
|
+
@source_repo = source_repo
|
26
27
|
end
|
27
28
|
|
28
29
|
def render(args)
|
@@ -102,7 +103,15 @@ module KubernetesTemplateRendering
|
|
102
103
|
kubernetes_cluster_type = name.sub('SPP-PLACEHOLDER', 'staging').sub(/\..*/, '') # prod.gcp => prod
|
103
104
|
|
104
105
|
hash[name] ||= []
|
105
|
-
hash[name] << ResourceSet.new(
|
106
|
+
hash[name] << ResourceSet.new(
|
107
|
+
config: config,
|
108
|
+
template_directory: dir,
|
109
|
+
rendered_directory: @rendered_directory,
|
110
|
+
kubernetes_cluster_type: kubernetes_cluster_type,
|
111
|
+
definitions_path: definitions_path,
|
112
|
+
variable_overrides: @variable_overrides,
|
113
|
+
source_repo: @source_repo
|
114
|
+
)
|
106
115
|
end
|
107
116
|
end
|
108
117
|
end
|
@@ -156,7 +165,6 @@ module KubernetesTemplateRendering
|
|
156
165
|
|
157
166
|
cluster_type_config.regions = cluster_type_config.regions & [region] if region
|
158
167
|
cluster_type_config.colors = cluster_type_config.colors & [color] if color
|
159
|
-
cluster_type_config.variables = (cluster_type_config.variables || {}).merge(variable_overrides)
|
160
168
|
|
161
169
|
hash[name] = cluster_type_config if (region.nil? && color.nil?) || (cluster_type_config.regions.any? && cluster_type_config.colors.any?)
|
162
170
|
end
|
data/mkdocs.yml
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubernetes_template_rendering
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Octothorpe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -67,6 +67,10 @@ files:
|
|
67
67
|
- CHANGELOG.md
|
68
68
|
- README.md
|
69
69
|
- Rakefile
|
70
|
+
- catalog-info.yaml
|
71
|
+
- docs/CHANGELOG.md
|
72
|
+
- docs/README.md
|
73
|
+
- docs/adrs/0000-template.md
|
70
74
|
- exe/render_templates
|
71
75
|
- lib/kubernetes_template_rendering.rb
|
72
76
|
- lib/kubernetes_template_rendering/cli.rb
|
@@ -80,7 +84,8 @@ files:
|
|
80
84
|
- lib/kubernetes_template_rendering/template.rb
|
81
85
|
- lib/kubernetes_template_rendering/template_directory_renderer.rb
|
82
86
|
- lib/kubernetes_template_rendering/version.rb
|
83
|
-
-
|
87
|
+
- mkdocs.yml
|
88
|
+
- sig/kubernetes_template_rendering.rbs
|
84
89
|
homepage: https://github.com/Invoca/kubernetes_template_rendering
|
85
90
|
licenses: []
|
86
91
|
metadata:
|
@@ -99,9 +104,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
104
|
version: 3.1.0
|
100
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
106
|
requirements:
|
102
|
-
- - "
|
107
|
+
- - ">="
|
103
108
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
109
|
+
version: '0'
|
105
110
|
requirements: []
|
106
111
|
rubygems_version: 3.4.21
|
107
112
|
signing_key:
|