Skip to content

Commit a68b3aa

Browse files
authored
Merge branch 'Shopify:main' into master
2 parents eb74e07 + c365e29 commit a68b3aa

18 files changed

Lines changed: 170 additions & 22 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- "3.0.4"
1919
- "2.7.6"
2020
kubernetes_version:
21+
- "1.31.2"
2122
- "1.30.0"
2223
- "1.29.4"
2324
- "1.28.0"
@@ -29,6 +30,8 @@ jobs:
2930
- "serial_integration_test"
3031
- "integration_test"
3132
include:
33+
- kubernetes_version: "1.31.2"
34+
kind_image: "kindest/node:v1.31.2@sha256:18fbefc20a7113353c7b75b5c869d7145a6abd6269154825872dc59c1329912e"
3235
- kubernetes_version: "1.30.0"
3336
kind_image: "kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e"
3437
- kubernetes_version: "1.29.4"

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
## next
22

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+
11+
## 3.7.0
12+
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.
14+
15+
## 3.6.3
16+
17+
- Test against k8s 1.31
18+
19+
## 3.6.2
20+
21+
- Pinning `stats-instrument` to < 3.9 to avoid breaking changes.
22+
23+
## 3.6.1
24+
25+
*Features*
26+
27+
- Enable the option to bypass endpoint validation for a service by using the annotation `krane.shopify.io/skip-endpoint-validation: true`.
28+
329
## 3.6.0
430

531
- Test against k8s 1.29, 1.30

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Krane provides support for official upstream supported versions [Kubernetes](htt
9797
| 1.28 | Yes | -- |
9898
| 1.29 | Yes | -- |
9999
| 1.30 | Yes | -- |
100+
| 1.31 | Yes | -- |
100101

101102
## Installation
102103

@@ -176,6 +177,10 @@ before the deployment is considered successful.
176177
- _Accepted values_: `create`, `replace`, and `replace-force`
177178
- _Warning_: Resources whose deploy method is overridden are no longer subject to pruning on deploy.
178179
- This feature is _experimental_ and may be removed at any time.
180+
- `krane.shopify.io/skip-endpoint-validation`: Skip endpoint validation for the service.
181+
- _Compatibility_: Service
182+
- _Default_: `false`
183+
- `true`: Endpoint validation is not performed during the deployment of the service.
179184

180185

181186
### Running tasks at the beginning of a deploy

dev.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ up:
66
- podman
77
- kind:
88
name: krane
9-
image: kindest/node:v1.28.0@sha256:dad5a6238c5e41d7cac405fae3b5eda2ad1de6f1190fa8bfc64ff5bb86173213
9+
image: kindest/node:v1.31.2@sha256:18fbefc20a7113353c7b75b5c869d7145a6abd6269154825872dc59c1329912e
1010
commands:
1111
test:
12-
run: bin/test
12+
run: bin/test unit_test && bin/test cli_test && bin/test serial_integration_test && bin/test integration_test
13+
test-unit:
14+
run: bin/test unit_test
15+
test-cli:
16+
run: bin/test cli_test
17+
test-serial_integration:
18+
run: bin/test serial_integration_test,
19+
test-integration:
20+
run: bin/test integration_test
1321
tophat:
1422
run: PRINT_LOGS=1 bundle exec ruby -I test test/integration/krane_deploy_test.rb -n/${1}/
1523
desc: Tophat a change by running a test scenario with logging output enabled.

krane.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
3131
spec.add_dependency("googleauth", "~> 1.2")
3232
spec.add_dependency("ejson", "~> 1.0")
3333
spec.add_dependency("colorize", "~> 0.8")
34-
spec.add_dependency("statsd-instrument", ['>= 2.8', "< 4"])
34+
spec.add_dependency("statsd-instrument", ['>= 2.8', "< 3.9"])
3535
spec.add_dependency("multi_json")
3636
spec.add_dependency("concurrent-ruby", "~> 1.1")
3737
spec.add_dependency("jsonpath", "~> 1.0")

lib/krane/cli/render_command.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class RenderCommand
1111
desc: "[DEPRECATED] Read resources from stdin" },
1212
"current-sha" => { type: :string, banner: "SHA", desc: "Expose SHA `current_sha` in ERB bindings",
1313
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`" },
1416
}
1517

1618
def self.from_options(options)
@@ -32,6 +34,7 @@ def self.from_options(options)
3234
current_sha: options['current-sha'],
3335
filenames: paths,
3436
bindings: bindings_parser.parse,
37+
partials_dir: options['partials-dir'],
3538
)
3639
renderer.run!(stream: STDOUT)
3740
end

lib/krane/kubernetes_resource.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ def exists?
204204

205205
def current_generation
206206
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
208208
end
209209

210210
def observed_generation
211211
return -2 unless exists?
212212
# 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
214214
end
215215

216216
def status

lib/krane/kubernetes_resource/service.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Krane
55
class Service < KubernetesResource
66
TIMEOUT = 7.minutes
77
SYNC_DEPENDENCIES = %w(Pod Deployment StatefulSet)
8+
SKIP_ENDPOINT_VALIDATION_ANNOTATION = 'skip-endpoint-validation'
89

910
def sync(cache)
1011
super
@@ -59,6 +60,9 @@ def exposes_zero_replica_workload?
5960
end
6061

6162
def requires_endpoints?
63+
# skip validation if the annotation is present
64+
return false if skip_endpoint_validation
65+
6266
# services of type External don't have endpoints
6367
return false if external_name_svc?
6468

@@ -96,5 +100,9 @@ def requires_publishing?
96100
def published?
97101
@instance_data.dig('status', 'loadBalancer', 'ingress').present?
98102
end
103+
104+
def skip_endpoint_validation
105+
krane_annotation_value(SKIP_ENDPOINT_VALIDATION_ANNOTATION) == 'true'
106+
end
99107
end
100108
end

lib/krane/render_task.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ class RenderTask
1414
# @param current_sha [String] The SHA of the commit
1515
# @param filenames [Array<String>] An array of filenames and/or directories containing templates (*required*)
1616
# @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)
1819
@logger = logger || Krane::FormattedLogger.build
1920
@filenames = filenames.map { |path| File.expand_path(path) }
2021
@bindings = bindings
2122
@current_sha = current_sha
23+
@partials_dir = partials_dir
2224
end
2325

2426
# Runs the task, returning a boolean representing success or failure
@@ -58,7 +60,7 @@ def render_templates(stream, template_sets)
5860
@logger.phase_heading("Rendering template(s)")
5961
count = 0
6062
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|
6264
write_to_stream(rendered_content, filename, stream)
6365
count += 1
6466
end

lib/krane/renderer.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ def initialize(msg, parents: [], content: nil, filename:)
1616
end
1717
class PartialNotFound < InvalidTemplateError; end
1818

19-
def initialize(current_sha:, template_dir:, logger:, bindings: {})
19+
def initialize(current_sha:, template_dir:, logger:, bindings: {}, partials_dir: nil)
2020
@current_sha = current_sha
2121
@template_dir = template_dir
2222
@partials_dirs =
2323
%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
2427
@logger = logger
2528
@bindings = bindings
2629
# Max length of podname is only 63chars so try to save some room by truncating sha to 8 chars

0 commit comments

Comments
 (0)