From a8076ee1769fb81a7669c908e65cba2b733074ee Mon Sep 17 00:00:00 2001 From: Veronica Gluza Date: Thu, 25 Jan 2024 17:13:42 -0600 Subject: [PATCH 1/3] Created new optional flag to skip dry run proccess during deploy --- lib/krane/cli/deploy_command.rb | 2 ++ lib/krane/deploy_task.rb | 5 +++-- test/helpers/fixture_deploy_helper.rb | 5 +++-- test/integration-serial/serial_deploy_test.rb | 11 +++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/krane/cli/deploy_command.rb b/lib/krane/cli/deploy_command.rb index 361d89789..6e4b089a8 100644 --- a/lib/krane/cli/deploy_command.rb +++ b/lib/krane/cli/deploy_command.rb @@ -33,6 +33,7 @@ class DeployCommand default: false }, "verify-result" => { type: :boolean, default: true, desc: "Verify workloads correctly deployed" }, + "skip-dry-run" => { type: :boolean, desc: "Enable skipping dry run", default: false}, } def self.from_options(namespace, context, options) @@ -71,6 +72,7 @@ def self.from_options(namespace, context, options) selector: selector, selector_as_filter: selector_as_filter, protected_namespaces: protected_namespaces, + skip_dry_run: options["skip-dry-run"] ) deploy.run!( diff --git a/lib/krane/deploy_task.rb b/lib/krane/deploy_task.rb index 88e669208..1b0b79fed 100644 --- a/lib/krane/deploy_task.rb +++ b/lib/krane/deploy_task.rb @@ -106,7 +106,7 @@ def server_version # @param render_erb [Boolean] Enable ERB rendering def initialize(namespace:, context:, current_sha: nil, logger: nil, kubectl_instance: nil, bindings: {}, global_timeout: nil, selector: nil, selector_as_filter: false, filenames: [], protected_namespaces: nil, - render_erb: false, kubeconfig: nil) + render_erb: false, kubeconfig: nil, skip_dry_run: false) @logger = logger || Krane::FormattedLogger.build(namespace, context) @template_sets = TemplateSets.from_dirs_and_files(paths: filenames, logger: @logger, render_erb: render_erb) @task_config = Krane::TaskConfig.new(context, namespace, @logger, kubeconfig) @@ -121,6 +121,7 @@ def initialize(namespace:, context:, current_sha: nil, logger: nil, kubectl_inst @selector_as_filter = selector_as_filter @protected_namespaces = protected_namespaces || PROTECTED_NAMESPACES @render_erb = render_erb + @skip_dry_run = skip_dry_run end # Runs the task, returning a boolean representing success or failure @@ -286,7 +287,7 @@ def validate_configuration(prune:) def validate_resources(resources) validate_globals(resources) - batch_dry_run_success = validate_dry_run(resources) + batch_dry_run_success = @skip_dry_run || validate_dry_run(resources) resources.select! { |r| r.selected?(@selector) } if @selector_as_filter 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 diff --git a/test/helpers/fixture_deploy_helper.rb b/test/helpers/fixture_deploy_helper.rb index 01c65e46e..1063319d4 100644 --- a/test/helpers/fixture_deploy_helper.rb +++ b/test/helpers/fixture_deploy_helper.rb @@ -87,7 +87,7 @@ def deploy_raw_fixtures(set, wait: true, bindings: {}, subset: nil, render_erb: success end - def deploy_dirs_without_profiling(dirs, wait: true, prune: true, bindings: {}, + def deploy_dirs_without_profiling(dirs, wait: true, prune: true, skip_dry_run: false, bindings: {}, sha: "k#{SecureRandom.hex(6)}", kubectl_instance: nil, global_timeout: nil, selector: nil, selector_as_filter: false, protected_namespaces: nil, render_erb: false, context: KubeclientHelper::TEST_CONTEXT) @@ -105,7 +105,8 @@ def deploy_dirs_without_profiling(dirs, wait: true, prune: true, bindings: {}, selector: selector, selector_as_filter: selector_as_filter, protected_namespaces: protected_namespaces, - render_erb: render_erb + render_erb: render_erb, + skip_dry_run: skip_dry_run ) deploy.run( verify_result: wait, diff --git a/test/integration-serial/serial_deploy_test.rb b/test/integration-serial/serial_deploy_test.rb index 576e72b0d..92f924de6 100644 --- a/test/integration-serial/serial_deploy_test.rb +++ b/test/integration-serial/serial_deploy_test.rb @@ -546,6 +546,17 @@ def test_batch_dry_run_apply_success_precludes_individual_resource_dry_run_valid ], in_order: true) end + def test_skip_dry_run_apply_success + Krane::KubernetesResource.any_instance.expects(:validate_definition).with { |params| params[:dry_run] == false } + Krane::ResourceDeployer.any_instance.expects(:dry_run).never + result = deploy_fixtures("hello-cloud", subset: %w(secret.yml), skip_dry_run: true) + assert_deploy_success(result) + assert_logs_match_all([ + "Result: SUCCESS", + "Successfully deployed 1 resource", + ], in_order: true) + end + private def rollout_conditions_annotation_key From 54fa5dcffe11b2e018c405bf26e73d9807e84a0c Mon Sep 17 00:00:00 2001 From: Veronica Gluza Date: Mon, 29 Jan 2024 14:13:14 -0600 Subject: [PATCH 2/3] updated version and changelog for new flag --- CHANGELOG.md | 4 ++++ lib/krane/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0da84f5a..0b68969bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## next +# 3.4.1 + +- Added flag `--skip-dry-run` to completely opt out of dry run validation. + # 3.4.0 - Use `prune-allowlist` instead of `prune-whitelist` for 1.26+ clusters. Clusters running 1.25 or less will continue to use `--prune-whitelist`. [#940](https://github.com/Shopify/krane/pull/940) diff --git a/lib/krane/version.rb b/lib/krane/version.rb index cce4d769d..ff2f24e2b 100644 --- a/lib/krane/version.rb +++ b/lib/krane/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module Krane - VERSION = "3.4.0" + VERSION = "3.4.1" end From 36b803e190307b0510e8f318546a521763f65d11 Mon Sep 17 00:00:00 2001 From: Veronica Gluza Date: Mon, 29 Jan 2024 14:46:37 -0600 Subject: [PATCH 3/3] fixed test default --- test/exe/deploy_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/exe/deploy_test.rb b/test/exe/deploy_test.rb index ce52fb4a5..c8e255068 100644 --- a/test/exe/deploy_test.rb +++ b/test/exe/deploy_test.rb @@ -164,6 +164,7 @@ def default_options(new_args = {}, run_args = {}) selector: nil, selector_as_filter: false, protected_namespaces: ["default", "kube-system", "kube-public"], + skip_dry_run: false, }.merge(new_args), run_args: { verify_result: true,