Skip to content

Commit

Permalink
Use client, not server version for server dry run flag (#793)
Browse files Browse the repository at this point in the history
* Use client, not server version for server dry run flag

* fix test (stub client_version, not server_version now)

* explicitly check for server-side dry-run

* gitVersion make same
  • Loading branch information
timothysmith0609 committed Jan 27, 2021
1 parent b8c291f commit 4935c35
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/krane/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def validate_configuration(prune:)

def validate_resources(resources)
validate_globals(resources)
batch_dry_run_success = validate_dry_run(resources)
batch_dry_run_success = kubectl.server_dry_run_enabled? && validate_dry_run(resources)
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
if batch_dry_run_success
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/kubectl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def server_dry_run_enabled?
end

def dry_run_flag
if server_version >= Gem::Version.new("1.18")
if client_version >= Gem::Version.new("1.18")
"--dry-run=server"
else
"--server-dry-run"
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/kubernetes_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def validate_spec_with_kubectl(kubectl)

# Server side dry run is only supported on apply
def validate_with_server_side_dry_run(kubectl)
command = if kubectl.server_version >= Gem::Version.new('1.18')
command = if kubectl.client_version >= Gem::Version.new('1.18')
["apply", "-f", file_path, "--dry-run=server", "--output=name"]
else
["apply", "-f", file_path, "--server-dry-run", "--output=name"]
Expand Down
4 changes: 3 additions & 1 deletion test/unit/krane/ejson_secret_provisioner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ def dummy_secret_hash(name: SecureRandom.hex(4), data: {})
end

def dummy_version
'Server: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.6", GitCommit:"a6a8ec"}'
'Server: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.6", GitCommit:"a6a8ec"}' \
"\n" \
'Client:: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.6", GitCommit:"70132b"'
end

def build_provisioner(dir = nil, selector: nil, ejson_keys_secret: dummy_ejson_secret)
Expand Down
6 changes: 3 additions & 3 deletions test/unit/krane/kubernetes_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_timeout_override_upper_bound_validation

def test_validate_definition_doesnt_log_raw_output_for_sensitive_resources
resource = DummySensitiveResource.new
kubectl.expects(:server_version).returns(Gem::Version.new('1.20'))
kubectl.expects(:client_version).returns(Gem::Version.new('1.20'))

kubectl.expects(:run)
.with('apply', '-f', "/tmp/foo/bar", "--dry-run=server", '--output=name', {
Expand All @@ -197,7 +197,7 @@ def test_validate_definition_ignores_server_dry_run_unsupported_by_webhook_respo
.with('apply', '-f', anything, '--dry-run', '--output=name', anything)
.returns(["", "", stub(success?: true)])

kubectl.expects(:server_version).returns(Gem::Version.new('1.20'))
kubectl.expects(:client_version).returns(Gem::Version.new('1.20'))

kubectl.expects(:run)
.with('apply', '-f', anything, '--dry-run=server', '--output=name', anything)
Expand All @@ -217,7 +217,7 @@ def test_validate_definition_ignores_server_dry_run_unsupported_by_webhook_respo
.with('apply', '-f', anything, '--dry-run', '--output=name', anything)
.returns(["", "", stub(success?: true)])

kubectl.expects(:server_version).returns(Gem::Version.new('1.17'))
kubectl.expects(:client_version).returns(Gem::Version.new('1.17'))

kubectl.expects(:run)
.with('apply', '-f', anything, '--server-dry-run', '--output=name', anything)
Expand Down

0 comments on commit 4935c35

Please sign in to comment.