Skip to content

[feat] Webhook hooks: normalize allow/deny arguments, add the ValidationWebhook main and test loaders - #14

Merged
yalosev merged 2 commits into
mainfrom
feat/validations-normalize
Oct 12, 2026
Merged

yalosev merged 2 commits into
mainfrom
feat/validations-normalize

Conversation

@yalosev

@yalosev yalosev commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

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 of validate(binding_context). webhook-operator will call it from the hook it renders for a ValidationWebhook.
  • tests.load_validation_webhook(*paths) and tests.load_conversion_webhook(crd, conversions, *paths) build the hook webhook-operator renders for a ValidationWebhook or a ConversionWebhook, so hook.testrun runs the same code as the cluster.
Details
  • Deckhouse modules keep validation_webhook_test_helper.py and conversion_webhook_test_helper.py next 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.
  • dotmap moves from dev to runtime dependencies: the hooks get the binding context as a DotMap. The webhook-handler image installs it already.
  • poetry.lock is regenerated with Poetry 1.6.1, the version the PR workflow uses; it drops the category fields.
  • An empty string passed to allow() or deny() is dropped. Before, allow("") gave an empty warning and deny("") an empty message.
  • Tests pass on Python 3.8 and 3.12.

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>
@yalosev yalosev self-assigned this Oct 12, 2026
@yalosev
yalosev merged commit ceb79ec into main Oct 12, 2026
2 checks passed
@yalosev
yalosev deleted the feat/validations-normalize branch October 12, 2026 11:25
@yalosev yalosev changed the title [feat] Webhook hooks: normalize allow/deny arguments, add the ValidationWebhook main and test loaders [feat] Webhook hooks: normalize allow/deny arguments, add the ValidationWebhook main and test loaders, require Python 3.12 Oct 12, 2026
@yalosev yalosev changed the title [feat] Webhook hooks: normalize allow/deny arguments, add the ValidationWebhook main and test loaders, require Python 3.12 [feat] Webhook hooks: normalize allow/deny arguments, add the ValidationWebhook main and test loaders Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant