From a8076ee1769fb81a7669c908e65cba2b733074ee Mon Sep 17 00:00:00 2001 From: Veronica Gluza Date: Thu, 25 Jan 2024 17:13:42 -0600 Subject: [PATCH] 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