Repository navigation
[feat] Webhook hooks: normalize allow/deny arguments, add the ValidationWebhook main and test loaders - #14
Merged
Merged
Conversation
allow() unpacks lists of warnings and drops empty ones; deny() joins a list of messages with "; " and leaves out an empty message. A webhook can hand over whatever its check returned without converting it first. Signed-off-by: Yuriy Losev <yuriy.losev@flant.com>
…ebhook hooks validations.handle() answers an admission request with the result of validate(binding_context), the way the hook webhook-operator renders for a ValidationWebhook does. webhook-operator can call it instead of keeping its own copy of that code. tests.load_validation_webhook() and tests.load_conversion_webhook() build the hook webhook-operator renders for a ValidationWebhook or a ConversionWebhook from the handler files, so module tests run the same code as the cluster without keeping a copy of the templates. dotmap becomes a runtime dependency: the hooks get the binding context as a DotMap. Signed-off-by: Yuriy Losev <yuriy.losev@flant.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Webhook hooks of Deckhouse modules can hand their result to the library as is, and their unit tests no longer need copies of the webhook-operator templates.
validations.allow()accepts a list of warnings next to strings and drops empty ones.validations.deny()accepts a list of messages and joins it with;. Existing calls give the same response.validations.handle(ctx, validate)answers an admission request with the result ofvalidate(binding_context). webhook-operator will call it from the hook it renders for a ValidationWebhook.tests.load_validation_webhook(*paths)andtests.load_conversion_webhook(crd, conversions, *paths)build the hook webhook-operator renders for a ValidationWebhook or a ConversionWebhook, sohook.testrunruns the same code as the cluster.Details
validation_webhook_test_helper.pyandconversion_webhook_test_helper.pynext to their webhooks. Each holds a verbatim copy of the template code, and Go tests check that every copy matches the template. With the code in the library, the template and the tests use one function, and the copies and the checks go away.dotmapmoves from dev to runtime dependencies: the hooks get the binding context as aDotMap. The webhook-handler image installs it already.poetry.lockis regenerated with Poetry 1.6.1, the version the PR workflow uses; it drops thecategoryfields.allow()ordeny()is dropped. Before,allow("")gave an empty warning anddeny("")an empty message.