Skip to content

Commit

Permalink
avoid needless per-resource dry-run apply validation
Browse files Browse the repository at this point in the history
  • Loading branch information
timothysmith0609 committed Jan 22, 2024
1 parent 358f91c commit e5fe76b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/krane/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def run(**args)
def run!(verify_result: true, prune: true)
start = Time.now.utc
@logger.reset

@logger.phase_heading("Initializing deploy")
validate_configuration(prune: prune)
resources = discover_resources
Expand Down Expand Up @@ -285,17 +284,21 @@ def validate_configuration(prune:)
measure_method(:validate_configuration)

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
Krane::Concurrency.split_across_threads(resources) do |r|
validate_globals(resources)
applyables, individuals = resources.partition { |r| r.deploy_method == :apply }
batch_dry_run_success = validate_dry_run(applyables)
resources_to_validate = batch_dry_run_success ? individuals : resources

Krane::Concurrency.split_across_threads(resources_to_validate) 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
end

failed_resources = resources.select(&:validation_failed?)
if failed_resources.present?
failed_resources.each do |r|
Expand Down

0 comments on commit e5fe76b

Please sign in to comment.