From d7e6e67a1407bbc07fad31a482a0d4a4c0f16e10 Mon Sep 17 00:00:00 2001 From: Diego Alvarez Date: Thu, 22 Sep 2022 15:54:50 -0700 Subject: [PATCH] remove test for dropped support of k8s v1.21 --- test/integration-serial/serial_deploy_test.rb | 71 ------------------- .../mutating_webhook_configuration_test.rb | 62 ---------------- 2 files changed, 133 deletions(-) diff --git a/test/integration-serial/serial_deploy_test.rb b/test/integration-serial/serial_deploy_test.rb index d00ee4aa1..1eb321705 100644 --- a/test/integration-serial/serial_deploy_test.rb +++ b/test/integration-serial/serial_deploy_test.rb @@ -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 diff --git a/test/unit/krane/kubernetes_resource/mutating_webhook_configuration_test.rb b/test/unit/krane/kubernetes_resource/mutating_webhook_configuration_test.rb index 183536732..7c77d5b09 100644 --- a/test/unit/krane/kubernetes_resource/mutating_webhook_configuration_test.rb +++ b/test/unit/krane/kubernetes_resource/mutating_webhook_configuration_test.rb @@ -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