Skip to content

Commit

Permalink
Revert #798
Browse files Browse the repository at this point in the history
  • Loading branch information
d1egoaz committed Sep 28, 2022
1 parent d7e6e67 commit 9f1fe2a
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 222 deletions.
13 changes: 0 additions & 13 deletions lib/krane/cluster_resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ def fetch_resources(namespaced: false)
end.compact.uniq { |r| "#{r['apigroup']}/#{r['kind']}" }
end

def fetch_mutating_webhook_configurations
command = %w(get mutatingwebhookconfigurations)
raw_json, err, st = kubectl.run(*command, output: "json", attempts: 5, use_namespace: false)
if st.success?
JSON.parse(raw_json)["items"].map do |definition|
Krane::MutatingWebhookConfiguration.new(namespace: namespace, context: context, logger: logger,
definition: definition, statsd_tags: @namespace_tags)
end
else
raise FatalKubeAPIError, "Error retrieving mutatingwebhookconfigurations: #{err}"
end
end

private

# During discovery, the api paths may not actually be at the root, so we must programatically find it.
Expand Down
25 changes: 8 additions & 17 deletions lib/krane/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
custom_resource_definition
horizontal_pod_autoscaler
secret
mutating_webhook_configuration
).each do |subresource|
require "krane/kubernetes_resource/#{subresource}"
end
Expand Down Expand Up @@ -285,26 +284,18 @@ def validate_configuration(prune:)
end
measure_method(:validate_configuration)

def partition_dry_run_resources(resources)
individuals = []
mutating_webhook_configurations = cluster_resource_discoverer.fetch_mutating_webhook_configurations
mutating_webhook_configurations.each do |mutating_webhook_configuration|
mutating_webhook_configuration.webhooks.each do |webhook|
individuals = (individuals + resources.select { |resource| webhook.matches_resource?(resource) }).uniq
resources -= individuals
end
end
[resources, individuals]
end

def validate_resources(resources)
validate_globals(resources)
batchable_resources, individuals = partition_dry_run_resources(resources.dup)
batch_dry_run_success = kubectl.server_dry_run_enabled? && validate_dry_run(batchable_resources)
individuals += batchable_resources unless batch_dry_run_success
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|
r.validate_definition(kubectl: kubectl, selector: @selector, dry_run: individuals.include?(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?
Expand Down
5 changes: 0 additions & 5 deletions lib/krane/kubernetes_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,6 @@ def group
version ? grouping : "core"
end

def version
prefix, version = @definition.dig("apiVersion").split("/")
version || prefix
end

def kubectl_resource_type
type
end
Expand Down
87 changes: 0 additions & 87 deletions lib/krane/kubernetes_resource/mutating_webhook_configuration.rb

This file was deleted.

31 changes: 0 additions & 31 deletions test/fixtures/mutating_webhook_configurations/ingress_hook.yaml

This file was deleted.

31 changes: 0 additions & 31 deletions test/fixtures/mutating_webhook_configurations/secret_hook.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions test/integration-serial/serial_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,4 @@ def test_batch_dry_run_apply_success_precludes_individual_resource_dry_run_valid
def rollout_conditions_annotation_key
Krane::Annotation.for(Krane::CustomResourceDefinition::ROLLOUT_CONDITIONS_ANNOTATION)
end

def mutating_webhook_fixture(path)
JSON.parse(File.read(path))['items'].map do |definition|
Krane::MutatingWebhookConfiguration.new(namespace: @namespace, context: @context, logger: @logger,
definition: definition, statsd_tags: @namespace_tags)
end
end
end

This file was deleted.

0 comments on commit 9f1fe2a

Please sign in to comment.