Skip to content

Commit

Permalink
Merge pull request #663 from sco11morgan/update-dry-run-error-message
Browse files Browse the repository at this point in the history
fix: update matching for Kubernetes error message when server-dry-run is not supported
  • Loading branch information
dturn authored Jan 13, 2020
2 parents cb26852 + 87e8a6b commit d772651
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/krane/kubernetes_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class KubernetesResource
TIMEOUT = 5.minutes
LOG_LINE_COUNT = 250
SERVER_DRY_RUN_DISABLED_ERROR =
/(unknown flag: --server-dry-run)|(doesn't support dry-run)|(dryRun alpha feature is disabled)/
/(unknown flag: --server-dry-run)|(does[\s\']n[o|']t support dry[-\s]run)|(dryRun alpha feature is disabled)/

DISABLE_FETCHING_LOG_INFO = 'DISABLE_FETCHING_LOG_INFO'
DISABLE_FETCHING_EVENT_INFO = 'DISABLE_FETCHING_EVENT_INFO'
Expand Down
18 changes: 18 additions & 0 deletions test/unit/krane/kubernetes_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,24 @@ def test_validate_definition_doesnt_log_raw_output_for_sensitive_resources
refute_includes(resource.validation_error_msg, 'S3CR3T')
end

def test_validate_definition_ignores_server_dry_run_unsupported_by_webhook_response
resource = DummySensitiveResource.new
kubectl.expects(:run)
.with('apply', '-f', anything, '--dry-run', '--output=name', anything)
.returns(["", "", stub(success?: true)])

kubectl.expects(:run)
.with('apply', '-f', anything, '--server-dry-run', '--output=name', anything)
.returns([
"Some Raw Output",
"Error from kubectl: admission webhook some-webhook does not support dry run",
stub(success?: false),
])
resource.validate_definition(kubectl)
refute(resource.validation_failed?, "Failed to ignore server dry run responses matching:
#{Krane::KubernetesResource::SERVER_DRY_RUN_DISABLED_ERROR}")
end

def test_annotation_and_kubectl_error_messages_are_combined_deprecated
customized_resource = DummyResource.new(definition_extras: build_timeout_metadata("bad", use_deprecated: true))
kubectl.expects(:run).returns([
Expand Down

0 comments on commit d772651

Please sign in to comment.