krane 3.6.2 → 3.7.1

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: ba72a52b848777243b9335d8df21f98080fcf49142706c2443bf40475d071b5f
4
- data.tar.gz: 4f1a17c291e5ef38847f7a083cc1d6dcc00262c0dd447a39b7c39ab044268142
3
+ metadata.gz: 034cf54d143695589902632153ddb65969bae6135c88b076ec023c3c7dc3264a
4
+ data.tar.gz: 309a1d3c9cf5afad784f48a12d9fe1b13568f1485aec95b0007739a13973932a
5
5
  SHA512:
6
- metadata.gz: fdae1d679008ec4de4ee83c2f1925f7b168456189f824face6b3d3f7079bdda89c25bea6da676ab95508cc5ce125587863e8af307a6f6d3814dc75b029280d56
7
- data.tar.gz: 603e6f890a482b0e549ed9b1c0deca4ae3e4bb73144c7174f2a430c964127ee4cd75d516eb4e7561258afac29c711f5b595c3cc35316cf4c9e05a6a1aeab9bf0
6
+ metadata.gz: 44e89c3a956dec061b554f17a38a2e7afc552cf94a5071470baa3f60fb16ae2510f287d9dd8c2f9e9cc92d78fc330be225de62ce43c3be9bb22eab06104076c4
7
+ data.tar.gz: c9d79cd30d415ea7dc718541921a9c02cb60712fe2d021e22869bb03c0e7608b918f8c285a0362fe19d709780c8c48d4f3b5a3c6ba7fa34d299613421350722a
@@ -18,6 +18,7 @@ jobs:
18
18
  - "3.0.4"
19
19
  - "2.7.6"
20
20
  kubernetes_version:
21
+ - "1.31.2"
21
22
  - "1.30.0"
22
23
  - "1.29.4"
23
24
  - "1.28.0"
@@ -29,6 +30,8 @@ jobs:
29
30
  - "serial_integration_test"
30
31
  - "integration_test"
31
32
  include:
33
+ - kubernetes_version: "1.31.2"
34
+ kind_image: "kindest/node:v1.31.2@sha256:18fbefc20a7113353c7b75b5c869d7145a6abd6269154825872dc59c1329912e"
32
35
  - kubernetes_version: "1.30.0"
33
36
  kind_image: "kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e"
34
37
  - kubernetes_version: "1.29.4"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## next
2
2
 
3
+ ## 3.7.1
4
+
5
+ - Add a `--partials-dir` parameter. When provided, this path will be check for partials first, prior to both `./partials` and `../partials` being checked.
6
+
7
+ ## 3.7.0
8
+
9
+ - 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.
10
+
11
+ ## 3.6.3
12
+
13
+ - Test against k8s 1.31
14
+
3
15
  ## 3.6.2
4
16
 
5
17
  - Pinning `stats-instrument` to < 3.9 to avoid breaking changes.
@@ -8,7 +20,7 @@
8
20
 
9
21
  *Features*
10
22
 
11
- - Enable the option to bypass endpoint validation for a service by using the annotation `krane.shopify.io/skip-endpoint-validation: true`.
23
+ - Enable the option to bypass endpoint validation for a service by using the annotation `krane.shopify.io/skip-endpoint-validation: true`.
12
24
 
13
25
  ## 3.6.0
14
26
 
data/README.md CHANGED
@@ -97,6 +97,7 @@ Krane provides support for official upstream supported versions [Kubernetes](htt
97
97
  | 1.28 | Yes | -- |
98
98
  | 1.29 | Yes | -- |
99
99
  | 1.30 | Yes | -- |
100
+ | 1.31 | Yes | -- |
100
101
 
101
102
  ## Installation
102
103
 
data/dev.yml CHANGED
@@ -6,7 +6,7 @@ up:
6
6
  - podman
7
7
  - kind:
8
8
  name: krane
9
- image: kindest/node:v1.28.0@sha256:dad5a6238c5e41d7cac405fae3b5eda2ad1de6f1190fa8bfc64ff5bb86173213
9
+ image: kindest/node:v1.31.2@sha256:18fbefc20a7113353c7b75b5c869d7145a6abd6269154825872dc59c1329912e
10
10
  commands:
11
11
  test:
12
12
  run: bin/test unit_test && bin/test cli_test && bin/test serial_integration_test && bin/test integration_test
@@ -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
@@ -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
@@ -22,7 +22,7 @@ module Krane
22
22
 
23
23
  def deploy!(resources, verify_result, prune)
24
24
  if verify_result
25
- deploy_all_resources(resources, prune: prune, verify: true)
25
+ deploy_all_resources(resources, prune: prune, verify: true, annotate_individuals: true)
26
26
  failed_resources = resources.reject(&:deploy_succeeded?)
27
27
  success = failed_resources.empty?
28
28
  if !success && failed_resources.all?(&:deploy_timed_out?)
@@ -30,7 +30,7 @@ module Krane
30
30
  end
31
31
  raise FatalDeploymentError unless success
32
32
  else
33
- deploy_all_resources(resources, prune: prune, verify: false)
33
+ deploy_all_resources(resources, prune: prune, verify: false, annotate_individuals: true)
34
34
  logger.summary.add_action("deployed #{resources.length} #{'resource'.pluralize(resources.length)}")
35
35
  warning = <<~MSG
36
36
  Deploy result verification is disabled for this deploy.
@@ -73,12 +73,13 @@ module Krane
73
73
 
74
74
  private
75
75
 
76
- def deploy_all_resources(resources, prune: false, verify:, record_summary: true)
77
- deploy_resources(resources, prune: prune, verify: verify, record_summary: record_summary)
76
+ def deploy_all_resources(resources, prune: false, verify:, record_summary: true, annotate_individuals: false)
77
+ deploy_resources(resources, prune: prune, verify: verify, record_summary: record_summary,
78
+ annotate_individuals: annotate_individuals)
78
79
  end
79
80
  measure_method(:deploy_all_resources, 'normal_resources.duration')
80
81
 
81
- def deploy_resources(resources, prune: false, verify:, record_summary: true)
82
+ def deploy_resources(resources, prune: false, verify:, record_summary: true, annotate_individuals: false)
82
83
  return if resources.empty?
83
84
  deploy_started_at = Time.now.utc
84
85
 
@@ -96,7 +97,6 @@ module Krane
96
97
  applyables, individuals = resources.partition { |r| r.deploy_method == :apply }
97
98
  # Prunable resources should also applied so that they can be pruned
98
99
  pruneable_types = @prune_allowlist.map { |t| t.split("/").last }
99
- applyables += individuals.select { |r| pruneable_types.include?(r.type) && !r.deploy_method_override }
100
100
 
101
101
  individuals.each do |individual_resource|
102
102
  individual_resource.deploy_started_at = Time.now.utc
@@ -122,6 +122,11 @@ module Krane
122
122
 
123
123
  apply_all(applyables, prune)
124
124
 
125
+ if annotate_individuals
126
+ to_annotate = individuals.select { |r| pruneable_types.include?(r.type) && !r.deploy_method_override }
127
+ update_last_applied_annotations(to_annotate)
128
+ end
129
+
125
130
  if verify
126
131
  watcher = Krane::ResourceWatcher.new(resources: resources, deploy_started_at: deploy_started_at,
127
132
  timeout: @global_timeout, task_config: @task_config, sha: @current_sha)
@@ -252,6 +257,19 @@ module Krane
252
257
  [err, status]
253
258
  end
254
259
 
260
+ def update_last_applied_annotations(resources)
261
+ resources.each do |resource|
262
+ err, status = set_last_applied_annotation(resource)
263
+ raise FatalDeploymentError, "Failed to set last applied annotation: #{err}" unless status.success?
264
+ end
265
+ end
266
+
267
+ def set_last_applied_annotation(resource)
268
+ _, err, status = kubectl.run("apply", "set-last-applied", "--create-annotation", "-f", resource.file_path, log_failure: false,
269
+ output_is_sensitive: resource.sensitive_template_content?, use_namespace: !resource.global?)
270
+ [err, status]
271
+ end
272
+
255
273
  # Inspect the file referenced in the kubectl stderr
256
274
  # to make it easier for developer to understand what's going on
257
275
  def find_bad_files_from_kubectl_output(line)
@@ -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.6.2"
3
+ VERSION = "3.7.1"
4
4
  end
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krane
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.2
4
+ version: 3.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Verey
8
8
  - Daniel Turner
9
9
  - Kir Shatrov
10
- autorequire:
11
10
  bindir: exe
12
11
  cert_chain: []
13
- date: 2024-08-21 00:00:00.000000000 Z
12
+ date: 2025-03-11 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activesupport
@@ -512,7 +511,6 @@ licenses:
512
511
  - MIT
513
512
  metadata:
514
513
  allowed_push_host: https://rubygems.org
515
- post_install_message:
516
514
  rdoc_options: []
517
515
  require_paths:
518
516
  - lib
@@ -527,8 +525,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
527
525
  - !ruby/object:Gem::Version
528
526
  version: '0'
529
527
  requirements: []
530
- rubygems_version: 3.5.17
531
- signing_key:
528
+ rubygems_version: 3.6.5
532
529
  specification_version: 4
533
530
  summary: A command line tool that helps you ship changes to a Kubernetes namespace
534
531
  and understand the result