kubernetes_template_rendering 0.1.0 → 0.2.0

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: 5b05563ef123216e666bf9be24a72f445455386367b500a64d202468e5ab3292
4
- data.tar.gz: e923ed36b4fdf9267ddb45860425895186c1289582cfb179bc136fb98758432d
3
+ metadata.gz: faeb29036b624168016b45f8b3ec72e0d39328a8a9a82c256125873264a49796
4
+ data.tar.gz: f5c5269ab942419534e0886cd5a8f015c77b5540b9ba2c8105c4bfa6ff6bb879
5
5
  SHA512:
6
- metadata.gz: 5ffe4df38a962360ca6f1d84ee122182e0abd3c3d220b6577e576fe3237e0cf12736b7fbb03a814e7d10870af3df36761913074b2cb428ebdf940eac64f4eaa1
7
- data.tar.gz: 6e6d5b003e44d68c59834bf25f2d0a67be7041f964030b221d2845f3bd7a50c2ef8b0fccc7b3e99f5ea63420572970f0a7679d6c99d3b28141417bad3e81de4f
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.1.0] - Unreleased
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
@@ -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
 
@@ -12,7 +12,8 @@ module KubernetesTemplateRendering
12
12
  :region,
13
13
  :color,
14
14
  :variable_overrides,
15
- :prune
15
+ :prune,
16
+ :source_repo
16
17
  ) do
17
18
  def valid?
18
19
  rendered_directory && template_directory
@@ -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 = template_path
16
- @definitions_path = definitions_path
17
- @variables = variables
18
- @output_directory = output_directory
19
- @output_filename = output_filename || template_filename(template_path)
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: @definitions_path, variables: variables, output_directory: output_directory)
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
- def initialize(template_path, variables)
13
- @template_path = template_path
14
- @variables = variables
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 #{template_path}
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(config: config, template_directory: dir, rendered_directory: @rendered_directory, kubernetes_cluster_type: kubernetes_cluster_type, definitions_path: definitions_path)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KubernetesTemplateRendering
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  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.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-04-29 00:00:00.000000000 Z
11
+ date: 2024-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport