Skip to content

Commit

Permalink
If we're going to batch dry run, then let's actually use the results
Browse files Browse the repository at this point in the history
  • Loading branch information
timothysmith0609 committed Jan 22, 2024
1 parent 41a63a8 commit d319915
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in krane.gemspec
gemspec

gem "ruby-lsp", "~> 0.2.0", :group => :development
gem "ruby-lsp", "~> 0.2.0", group: :development
13 changes: 7 additions & 6 deletions lib/krane/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,16 @@ def validate_configuration(prune:)

def validate_resources(resources)
validate_globals(resources)
batch_dry_run_success = validate_dry_run(resources)
resources.select! { |r| r.selected?(@selector) } if @selector_as_filter
applyables, individuals = resources.partition { |r| r.deploy_method == :apply }
begin
batch_dry_run_success = validate_dry_run(applyables)
rescue FatalDeploymentError => e
raise FatalDeploymentError, "Template validation failed"
end
Krane::Concurrency.split_across_threads(resources) do |r|
# No need to pass in kubectl (and do per-resource dry run apply) if batch dry run succeeded
if batch_dry_run_success
r.validate_definition(kubectl: nil, selector: @selector, dry_run: false)
else
r.validate_definition(kubectl: kubectl, selector: @selector, dry_run: true)
end
r.validate_definition(kubectl: nil, selector: @selector, dry_run: false)
end
failed_resources = resources.select(&:validation_failed?)
if failed_resources.present?
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/resource_deployer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def apply_all(resources, prune, dry_run: false)
if st.success?
log_pruning(out) if prune
else
record_apply_failure(err, resources: resources) unless dry_run
record_apply_failure(err, resources: resources)
raise FatalDeploymentError, "Command failed: #{Shellwords.join(command)}"
end
end
Expand Down

0 comments on commit d319915

Please sign in to comment.