krane 3.7.0 → 3.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bb4b346e9146186c9e1549f71708707568aa9872a2b7e0e1a0e6fd01e9f4d52
4
- data.tar.gz: fb3662468c546ba6717cfd9de125cd4d6ef2caa2269404a618c2152770fc0d3d
3
+ metadata.gz: 2267692b50f9327c811d105ec23b0b373549086409dbfa9320dab7110056927e
4
+ data.tar.gz: 8d59aa496ab87f54b1108aa55d049a8f895ebd129f47952eb2cb0a4d379bf17e
5
5
  SHA512:
6
- metadata.gz: 7a4e23ab9d917f223c6e294a61b26d17791c3554257bbc81a95e5372f1d90af727a13b3bf470008be750fafbb7dbef322486289a2b247e9e60881eff2f4bad15
7
- data.tar.gz: b73325f5894e1a9ed67e75d1dc1759ceea4afe58aad5be81f27905bd3d0a10ff38012494c26cf68b06c338cd24367bb8e6d472e7b394aed3f3e0f3dd1ff56546
6
+ metadata.gz: 75763fd98cd6d5cb06fb5a27607d3b1db32880a012f24914a7f62c638a79375350e91eb2779fb44085c3ab6867969136e3207c513ea0036087e819b9aead7e83
7
+ data.tar.gz: 128adcfb1addadd78d28ce99d9a0d337f3bc6286157a4ada522efb5747a3175c360b318dcd69fbc03021595610fae66e91d6f3ff14fca1412344b1ed63a49d8c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## next
2
2
 
3
+ ## 3.7.2
4
+
5
+ - Explicitly convert `current_generation` and `observed_generation` values to integers using `.to_i` to ensure consistentency during comparison
6
+
7
+ ## 3.7.1
8
+
9
+ - Add a `--partials-dir` parameter. When provided, this path will be check for partials first, prior to both `./partials` and `../partials` being checked.
10
+
3
11
  ## 3.7.0
4
12
 
5
13
  - Annotate individual resources with `last-applied-configuration` when using `krane deploy` with `--annotate-individuals`. Previously, eligible resources that were made with `create` or `replace` were applied along with the rest of the resources. However, this causes issues when a mutating admission controller modifies otherwise immutable fields.
@@ -11,6 +11,8 @@ module Krane
11
11
  desc: "[DEPRECATED] Read resources from stdin" },
12
12
  "current-sha" => { type: :string, banner: "SHA", desc: "Expose SHA `current_sha` in ERB bindings",
13
13
  lazy_default: '' },
14
+ "partials-dir" => { type: :string, banner: "partials", required:false, default: nil,
15
+ desc: "First directory to look for partials, before checking `./partials` and `../partials`" },
14
16
  }
15
17
 
16
18
  def self.from_options(options)
@@ -32,6 +34,7 @@ module Krane
32
34
  current_sha: options['current-sha'],
33
35
  filenames: paths,
34
36
  bindings: bindings_parser.parse,
37
+ partials_dir: options['partials-dir'],
35
38
  )
36
39
  renderer.run!(stream: STDOUT)
37
40
  end
@@ -204,13 +204,13 @@ module Krane
204
204
 
205
205
  def current_generation
206
206
  return -1 unless exists? # must be different default than observed_generation
207
- @instance_data.dig("metadata", "generation")
207
+ @instance_data.dig("metadata", "generation")&.to_i
208
208
  end
209
209
 
210
210
  def observed_generation
211
211
  return -2 unless exists?
212
212
  # populating this is a best practice, but not all controllers actually do it
213
- @instance_data.dig('status', 'observedGeneration')
213
+ @instance_data.dig('status', 'observedGeneration')&.to_i
214
214
  end
215
215
 
216
216
  def status
@@ -14,11 +14,13 @@ module Krane
14
14
  # @param current_sha [String] The SHA of the commit
15
15
  # @param filenames [Array<String>] An array of filenames and/or directories containing templates (*required*)
16
16
  # @param bindings [Hash] Bindings parsed by Krane::BindingsParser
17
- def initialize(logger: nil, current_sha:, filenames: [], bindings:)
17
+ # @params partials_dir [String] A directory to look for partials, before checking `./partials` and `../partials`
18
+ def initialize(logger: nil, current_sha:, filenames: [], bindings:, partials_dir: nil)
18
19
  @logger = logger || Krane::FormattedLogger.build
19
20
  @filenames = filenames.map { |path| File.expand_path(path) }
20
21
  @bindings = bindings
21
22
  @current_sha = current_sha
23
+ @partials_dir = partials_dir
22
24
  end
23
25
 
24
26
  # Runs the task, returning a boolean representing success or failure
@@ -58,7 +60,7 @@ module Krane
58
60
  @logger.phase_heading("Rendering template(s)")
59
61
  count = 0
60
62
  template_sets.with_resource_definitions_and_filename(current_sha: @current_sha,
61
- bindings: @bindings, raw: true) do |rendered_content, filename|
63
+ bindings: @bindings, raw: true, partials_dir: @partials_dir) do |rendered_content, filename|
62
64
  write_to_stream(rendered_content, filename, stream)
63
65
  count += 1
64
66
  end
@@ -16,11 +16,14 @@ module Krane
16
16
  end
17
17
  class PartialNotFound < InvalidTemplateError; end
18
18
 
19
- def initialize(current_sha:, template_dir:, logger:, bindings: {})
19
+ def initialize(current_sha:, template_dir:, logger:, bindings: {}, partials_dir: nil)
20
20
  @current_sha = current_sha
21
21
  @template_dir = template_dir
22
22
  @partials_dirs =
23
23
  %w(partials ../partials).map { |d| File.expand_path(File.join(@template_dir, d)) }
24
+ # Prepend the partial_dir to the list of partials_dirs so that the user-provided
25
+ # directory is used first.
26
+ @partials_dirs.unshift(File.expand_path(partials_dir)) if partials_dir
24
27
  @logger = logger
25
28
  @bindings = bindings
26
29
  # Max length of podname is only 63chars so try to save some room by truncating sha to 8 chars
@@ -17,13 +17,14 @@ module Krane
17
17
  @render_erb = render_erb
18
18
  end
19
19
 
20
- def with_resource_definitions_and_filename(current_sha: nil, bindings: nil, raw: false)
20
+ def with_resource_definitions_and_filename(current_sha: nil, bindings: nil, raw: false, partials_dir: nil)
21
21
  if @render_erb
22
22
  @renderer = Renderer.new(
23
23
  template_dir: @template_dir,
24
24
  logger: @logger,
25
25
  current_sha: current_sha,
26
26
  bindings: bindings,
27
+ partials_dir: partials_dir,
27
28
  )
28
29
  end
29
30
  with_delayed_exceptions(@files, Krane::InvalidTemplateError) do |filename|
@@ -123,20 +124,21 @@ module Krane
123
124
  end
124
125
  end
125
126
 
126
- def with_resource_definitions_and_filename(current_sha: nil, bindings: nil, raw: false)
127
+ def with_resource_definitions_and_filename(current_sha: nil, bindings: nil, raw: false, partials_dir: nil)
127
128
  with_delayed_exceptions(@template_sets, Krane::InvalidTemplateError) do |template_set|
128
129
  template_set.with_resource_definitions_and_filename(
129
130
  current_sha: current_sha,
130
131
  bindings: bindings,
131
- raw: raw
132
+ raw: raw,
133
+ partials_dir: partials_dir,
132
134
  ) do |r_def, filename|
133
135
  yield r_def, filename
134
136
  end
135
137
  end
136
138
  end
137
139
 
138
- def with_resource_definitions(current_sha: nil, bindings: nil, raw: false)
139
- with_resource_definitions_and_filename(current_sha: current_sha, bindings: bindings, raw: raw) do |r_def, _|
140
+ def with_resource_definitions(current_sha: nil, bindings: nil, raw: false, partials_dir: nil)
141
+ with_resource_definitions_and_filename(current_sha: current_sha, bindings: bindings, raw: raw, partials_dir: partials_dir) do |r_def, _|
140
142
  yield r_def
141
143
  end
142
144
  end
data/lib/krane/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Krane
3
- VERSION = "3.7.0"
3
+ VERSION = "3.7.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krane
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Verey
@@ -9,7 +9,7 @@ authors:
9
9
  - Kir Shatrov
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-01-16 00:00:00.000000000 Z
12
+ date: 2025-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -525,7 +525,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
525
525
  - !ruby/object:Gem::Version
526
526
  version: '0'
527
527
  requirements: []
528
- rubygems_version: 3.6.2
528
+ rubygems_version: 3.6.5
529
529
  specification_version: 4
530
530
  summary: A command line tool that helps you ship changes to a Kubernetes namespace
531
531
  and understand the result