Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update matching for Kubernetes error message when server-dry-run is not supported #663

Merged
merged 6 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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