From b7a8d55a132ef8f2cf72b716916344af3dc658dd Mon Sep 17 00:00:00 2001 From: Aditya Sharma Date: Tue, 29 Aug 2023 15:27:18 -0700 Subject: [PATCH] Update: --prune-allowlist -> --prune-allowlist --- lib/krane/kubectl.rb | 9 +++++++++ lib/krane/resource_deployer.rb | 2 +- test/unit/krane/resource_deployer_test.rb | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/krane/kubectl.rb b/lib/krane/kubectl.rb index c2a8e461d..96971f34c 100644 --- a/lib/krane/kubectl.rb +++ b/lib/krane/kubectl.rb @@ -12,6 +12,7 @@ class Kubectl DEFAULT_TIMEOUT = 15 MAX_RETRY_DELAY = 16 SERVER_DRY_RUN_MIN_VERSION = "1.13" + PRUNE_ALLOWLIST_MIN_VERSION = "1.26" class ResourceNotFoundError < StandardError; end @@ -112,6 +113,14 @@ def dry_run_flag "--dry-run=server" end + def prune_allowlist_flag + if client_version >= Gem::Version.new(PRUNE_ALLOWLIST_MIN_VERSION) + return "--prune-allowlist" + else + return "--prune-whitelist" + end + end + private def build_command_from_options(args, use_namespace, use_context, output) diff --git a/lib/krane/resource_deployer.rb b/lib/krane/resource_deployer.rb index b8d54ff96..bf908f358 100644 --- a/lib/krane/resource_deployer.rb +++ b/lib/krane/resource_deployer.rb @@ -154,7 +154,7 @@ def apply_all(resources, prune, dry_run: false) else command.push("--all") end - @prune_whitelist.each { |type| command.push("--prune-whitelist=#{type}") } + @prune_whitelist.each { |type| command.push("#{kubectl.prune_allowlist_flag}=#{type}") } end command.push(kubectl.dry_run_flag) if dry_run diff --git a/test/unit/krane/resource_deployer_test.rb b/test/unit/krane/resource_deployer_test.rb index 7c15e56c7..bac63ccab 100644 --- a/test/unit/krane/resource_deployer_test.rb +++ b/test/unit/krane/resource_deployer_test.rb @@ -7,7 +7,7 @@ def test_deploy_prune_builds_whitelist whitelist_kind = "fake_kind" resource = build_mock_resource Krane::Kubectl.any_instance.expects(:run).with do |*args| - args.include?("--prune-whitelist=#{whitelist_kind}") + args.include?("--prune-allowlist=#{whitelist_kind}") end.returns(["", "", stub(success?: true)]) resource_deployer(kubectl_times: 0, prune_whitelist: [whitelist_kind]).deploy!([resource], false, true) end @@ -16,7 +16,7 @@ def test_deploy_no_prune_doesnt_prune whitelist_kind = "fake_kind" resource = build_mock_resource Krane::Kubectl.any_instance.expects(:run).with do |*args| - !args.include?("--prune-whitelist=#{whitelist_kind}") + !args.include?("--prune-allowlist=#{whitelist_kind}") end.returns(["", "", stub(success?: true)]) resource_deployer(kubectl_times: 0, prune_whitelist: [whitelist_kind]).deploy!([resource], false, false) end