Skip to content

Commit

Permalink
remove test for dropped support of k8s v1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
d1egoaz committed Sep 22, 2022
1 parent 4c985b2 commit d7e6e67
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 133 deletions.
71 changes: 0 additions & 71 deletions test/integration-serial/serial_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,77 +546,6 @@ def test_batch_dry_run_apply_success_precludes_individual_resource_dry_run_valid
], in_order: true)
end

# Note: After we drop support for K8s 1.21 this test can be removed, since webhooks must be dry-run safe.
def test_resources_with_side_effect_inducing_webhooks_are_not_batched_server_side_dry_run
result = deploy_global_fixtures("mutating_webhook_configurations", subset: %(ingress_hook.yaml))
assert_deploy_success(result)

# Note: We have to mock `has_side_effects?`, since this won't be possible with K8s 1.22+.
Krane::MutatingWebhookConfiguration::Webhook.any_instance.stubs(:has_side_effects?).returns(true)

Krane::ResourceDeployer.any_instance.expects(:dry_run).with do |params|
# We expect the ingress to not be included in the batch run
params.length == 3 && (params.map(&:type).sort == ["ConfigMap", "Deployment", "Service"])
end.returns(true)

[Krane::ConfigMap, Krane::Deployment, Krane::Service].each do |r|
r.any_instance.expects(:validate_definition).with { |params| params[:dry_run] == false }
end
Krane::Ingress.any_instance.expects(:validate_definition).with { |params| params[:dry_run] }
result = deploy_fixtures('hello-cloud', subset: %w(web.yml.erb configmap-data.yml), render_erb: true)
assert_deploy_success(result)
assert_logs_match_all([
"Result: SUCCESS",
"Successfully deployed 4 resources",
], in_order: true)
end

# Note: After we drop support for K8s 1.21 this test can be removed, since webhooks must be dry-run safe.
def test_resources_with_side_effect_inducing_webhooks_with_transitive_dependency_does_not_fail_batch_running
result = deploy_global_fixtures("mutating_webhook_configurations", subset: %(secret_hook.yaml))
assert_deploy_success(result)

# Note: We have to mock `has_side_effects?`, since this won't be possible with K8s 1.22+.
Krane::MutatingWebhookConfiguration::Webhook.any_instance.stubs(:has_side_effects?).returns(true)

actual_dry_runs = 0
Krane::KubernetesResource.any_instance.expects(:validate_definition).with do |params|
actual_dry_runs += 1 if params[:dry_run]
true
end.times(5)
result = deploy_fixtures('hello-cloud', subset: %w(web.yml.erb secret.yml configmap-data.yml),
render_erb: true) do |fixtures|
container = fixtures['web.yml.erb']['Deployment'][0]['spec']['template']['spec']
container['volumes'] = [{
'name' => 'secret',
'secret' => {
'secretName' => fixtures['secret.yml']["Secret"][0]['metadata']['name'],
},
}]
end
assert_deploy_success(result)
assert_equal(actual_dry_runs, 1)
assert_logs_match_all([
"Result: SUCCESS",
"Successfully deployed 5 resources",
], in_order: true)
end

# Note: After we drop support for K8s 1.21 this test can be removed, since webhooks must be dry-run safe.
def test_multiple_resources_with_side_effect_inducing_webhooks_are_properly_partitioned
result = deploy_global_fixtures("mutating_webhook_configurations", subset: %(secret_hook.yaml ingress_hook.yaml))
assert_deploy_success(result)

# Note: We have to mock `has_side_effects?`, since this won't be possible with K8s 1.22+.
Krane::MutatingWebhookConfiguration::Webhook.any_instance.stubs(:has_side_effects?).returns(true)

Krane::KubernetesResource.any_instance.expects(:validate_definition).with { |p| p[:dry_run] }.times(2)
result = deploy_fixtures('hello-cloud', subset: %w(web.yml.erb secret.yml), render_erb: true) do |fixtures|
fixtures["web.yml.erb"] = fixtures["web.yml.erb"].keep_if { |key| key == "Ingress" }
end
assert_deploy_success(result)
end

private

def rollout_conditions_annotation_key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,66 +28,4 @@ def test_load_from_json
assert_equal(rule.resources, ['secrets'])
end

# Note: After we drop support for K8s 1.21 this test can be removed, since webhooks must be dry-run safe.
def test_webhook_configuration_matches_when_side_effects
secret_def = YAML.load_file(File.join(fixture_path('hello-cloud'), 'secret.yml'))
secret = Krane::Secret.new(namespace: 'test', context: 'nope', definition: secret_def,
logger: @logger, statsd_tags: nil)

definition = YAML.load_file(File.join(fixture_path("mutating_webhook_configurations"), "secret_hook.yaml"))
webhook_configuration = Krane::MutatingWebhookConfiguration.new(
namespace: 'test', context: 'nope', definition: definition,
logger: @logger, statsd_tags: nil
)
webhook = webhook_configuration.webhooks.first
# Note: We have to mock `has_side_effects?`, since this won't be possible with K8s 1.22+.
webhook.stubs(:has_side_effects?).returns(true).at_least_once
assert(webhook.has_side_effects?)
assert(webhook.matches_resource?(secret))
assert(webhook.matches_resource?(secret, skip_rule_if_side_effect_none: true))
assert(webhook.matches_resource?(secret, skip_rule_if_side_effect_none: false))
end

# Note: After we drop support for K8s 1.21 this test can be removed, since webhooks must be dry-run safe.
def test_matches_webhook_configuration_doesnt_match_when_no_side_effects_and_flag
secret_def = YAML.load_file(File.join(fixture_path('hello-cloud'), 'secret.yml'))
secret = Krane::Secret.new(namespace: 'test', context: 'nope', definition: secret_def,
logger: @logger, statsd_tags: nil)

definition = YAML.load_file(File.join(fixture_path("mutating_webhook_configurations"), "secret_hook.yaml"))
webhook_configuration = Krane::MutatingWebhookConfiguration.new(
namespace: 'test', context: 'nope', definition: definition,
logger: @logger, statsd_tags: nil
)
webhook = webhook_configuration.webhooks.first
webhook.stubs(:has_side_effects?).returns(false).at_least_once
refute(webhook.matches_resource?(secret))
refute(webhook.matches_resource?(secret, skip_rule_if_side_effect_none: true))
assert(webhook.matches_resource?(secret, skip_rule_if_side_effect_none: false))
end

# Note: After we drop support for K8s 1.21 this test can be removed, since webhooks must be dry-run safe.
def test_no_match_when_policy_is_exact_and_resource_doesnt_match
secret_def = YAML.load_file(File.join(fixture_path('hello-cloud'), 'secret.yml'))
secret = Krane::Secret.new(namespace: 'test', context: 'nope', definition: secret_def,
logger: @logger, statsd_tags: nil)

definition = YAML.load_file(File.join(fixture_path("mutating_webhook_configurations"), "secret_hook.yaml"))
webhook_configuration = Krane::MutatingWebhookConfiguration.new(
namespace: 'test', context: 'nope', definition: definition,
logger: @logger, statsd_tags: nil
)

webhook = webhook_configuration.webhooks.first
# Note: We have to mock `has_side_effects?`, since this won't be possible with K8s 1.22+.
webhook.stubs(:has_side_effects?).returns(true).at_least_once
assert(webhook.matches_resource?(secret))
webhook.expects(:match_policy).returns(Krane::MutatingWebhookConfiguration::Webhook::EXACT).at_least(1)
assert(webhook.matches_resource?(secret))
secret.expects(:group).returns('fake').once
refute(webhook.matches_resource?(secret))
secret.unstub(:group)
secret.expects(:type).returns('fake').once
refute(webhook.matches_resource?(secret))
end
end

0 comments on commit d7e6e67

Please sign in to comment.