kubernetes_template_rendering 0.1.0 → 0.2.1.pre.dc.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 +12 -1
- 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 +17 -5
- data/lib/kubernetes_template_rendering/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7b242fd586f046697f6e535add0afa36a8788db2525180b8371c6dd21723c3d
|
4
|
+
data.tar.gz: 32d98d08ae6e0f05f5beaffe8a494cbc4bb090983f03c2e7887d2e3818e243df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cccee5ee9a9d1bbca7ff720134f7de6acf91cc8eb06b5a8915bb7809465282db7fca7aef639b13b6c874ef4e580aab235bb3b86a287dba349c031f5cb71401f
|
7
|
+
data.tar.gz: 7809594f19e079b1358411bbae0a7c03cf235e5ce84ade1c4fc77b1d87666d6827e7600413b4eafbb38277dda8416252e5bae62ec8371ff1c36cf124582837cf
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,17 @@ 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.1
|
7
|
+
## [0.2.1] - Unreleased
|
8
|
+
### Fixed
|
9
|
+
- Fixed a bug allowing child process errors to be ignored while rendering.
|
10
|
+
|
11
|
+
## [0.2.0] - 2024-05-06
|
12
|
+
### Added
|
13
|
+
- Added support for passing `--source-repo` flag into command line so that the rendered manifest comments can include a link to the source repository.
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
- Updated the code comment to include the variable overrides used when rendering the current version of the templates
|
17
|
+
|
18
|
+
## [0.1.0] - 2024-04-22
|
8
19
|
|
9
20
|
- Initial release
|
@@ -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)
|
@@ -48,7 +49,11 @@ module KubernetesTemplateRendering
|
|
48
49
|
end
|
49
50
|
|
50
51
|
if args.fork?
|
51
|
-
Process.waitall
|
52
|
+
process_statuses = Process.waitall
|
53
|
+
|
54
|
+
if (failed_processes = process_statuses.select { |_, status| !status.success? }).any?
|
55
|
+
raise "Child process completed with non-zero status: #{failed_processes.inspect}"
|
56
|
+
end
|
52
57
|
end
|
53
58
|
end
|
54
59
|
|
@@ -102,7 +107,15 @@ module KubernetesTemplateRendering
|
|
102
107
|
kubernetes_cluster_type = name.sub('SPP-PLACEHOLDER', 'staging').sub(/\..*/, '') # prod.gcp => prod
|
103
108
|
|
104
109
|
hash[name] ||= []
|
105
|
-
hash[name] << ResourceSet.new(
|
110
|
+
hash[name] << ResourceSet.new(
|
111
|
+
config: config,
|
112
|
+
template_directory: dir,
|
113
|
+
rendered_directory: @rendered_directory,
|
114
|
+
kubernetes_cluster_type: kubernetes_cluster_type,
|
115
|
+
definitions_path: definitions_path,
|
116
|
+
variable_overrides: @variable_overrides,
|
117
|
+
source_repo: @source_repo
|
118
|
+
)
|
106
119
|
end
|
107
120
|
end
|
108
121
|
end
|
@@ -156,7 +169,6 @@ module KubernetesTemplateRendering
|
|
156
169
|
|
157
170
|
cluster_type_config.regions = cluster_type_config.regions & [region] if region
|
158
171
|
cluster_type_config.colors = cluster_type_config.colors & [color] if color
|
159
|
-
cluster_type_config.variables = (cluster_type_config.variables || {}).merge(variable_overrides)
|
160
172
|
|
161
173
|
hash[name] = cluster_type_config if (region.nil? && color.nil?) || (cluster_type_config.regions.any? && cluster_type_config.colors.any?)
|
162
174
|
end
|
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.1.0
|
4
|
+
version: 0.2.1.pre.dc.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-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -104,11 +104,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: 3.1.0
|
105
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- - "
|
107
|
+
- - ">"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
109
|
+
version: 1.3.1
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.3.26
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Tool for rendering ERB and Jsonnet templates
|