Skip to content

Commit

Permalink
Merge pull request Shopify#944 from Shopify/skip-validate-dryrun
Browse files Browse the repository at this point in the history
Created new optional flag to skip dry run proccess during deploy
  • Loading branch information
veragluza authored Jan 29, 2024
2 parents 41a63a8 + 36b803e commit 63799d2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/krane/cli/deploy_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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!(
Expand Down
5 changes: 3 additions & 2 deletions lib/krane/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module Krane
VERSION = "3.4.0"
VERSION = "3.4.1"
end
1 change: 1 addition & 0 deletions test/exe/deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/fixture_deploy_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions test/integration-serial/serial_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63799d2

Please sign in to comment.