-
Notifications
You must be signed in to change notification settings - Fork 409
Improvements for webhooks docs and tests #3414
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
Merged
kcp-ci-bot
merged 4 commits into
kcp-dev:main
from
gman0:admissionwebhooks-tests-and-docs
May 30, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cb43661
e2e/fixtures/webhook: pass the parsed obj to ResponseFn
gman0 2b7b2fe
e2e: added checks for logicalcluster annotation for in-review objs in…
gman0 5b723c6
e2e/apibinding: test webhook in source ws too
gman0 a2f5d62
docs: added description for admission webhooks
gman0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Admission Webhooks | ||
|
||
kcp extends the vanilla [admission plugins](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/) for webhooks, and makes them cluster-aware. | ||
|
||
``` | ||
┌────────────────────────┐ | ||
│ Consumer Workspace ws2 │ | ||
├────────────────────────┤ | ||
│ │ | ||
┌────┼─ Widgets APIBinding │ | ||
│ │ │ | ||
│ │ Widget a │ | ||
┌───────────────────────────────────────────────┐ │ │ Widget b │ | ||
│ API Provider Workspace ws1 │ │ │ Widget c │ | ||
├───────────────────────────────────────────────┤ │ │ │ | ||
│ │ │ └────────────────────────┘ | ||
│ Widgets APIExport ◄──────────────┼────┤ | ||
│ │ │ │ | ||
│ ▼ │ │ | ||
│ Widgets APIResourceSchema │ │ ┌────────────────────────┐ | ||
│ (widgets.v1.example.org) │ │ │ Consumer Workspace ws3 │ | ||
│ ▲ │ │ ├────────────────────────┤ | ||
│ │ │ │ │ │ | ||
│ ┌───────────────────┴─────────────────────┐ │ └────┼─ Widgets APIBinding │ | ||
│ │ Mutating/ValidatingWebhookConfiguration │ │ │ │ | ||
│ │ for widgets.v1.example.org │ │ │ Widget a │ | ||
│ │ │ │ │ Widget b │ | ||
│ │ Handle a from ws2 (APIResourceSchema) │ │ │ Widget c │ | ||
│ │ Handle b from ws3 (APIResourceSchema) │ │ │ │ | ||
│ │ Handle a from ws1 (CRD) │ │ └────────────────────────┘ | ||
│ │ ... │ │ | ||
│ └───────────────────┬─────────────────────┘ │ | ||
│ │ │ | ||
│ ▼ │ | ||
│ Widgets CustomResourceDefinition │ | ||
│ (widgets.v1.example.org) │ | ||
│ │ | ||
│ Widget a │ | ||
│ │ | ||
└───────────────────────────────────────────────┘ | ||
``` | ||
|
||
When an object is to be mutated or validated, the webhook admission plugin ([`apis.kcp.io/MutatingWebhook`](https://github.com/kcp-dev/kcp/tree/main/pkg/admission/mutatingwebhook) and [`apis.kcp.io/ValidatingWebhook`](https://github.com/kcp-dev/kcp/tree/main/pkg/admission/validatingwebhook) respectively) looks for the owner of the resource schema. Once found, it then dispatches the handling for that object in the owner's workspace. There are two such cases in the diagram above: | ||
|
||
* **Admitting bound resources.** During the request handling, Widget objects inside the consumer workspaces `ws2` and `ws3` are picked up by the respective webhook admission plugin. The plugin sees the resource's schema comes from an APIBinding, and so it sets up an instance of `{Mutating,Validating}Webhook` to be working with its APIExport's workspace, in `ws1`. Afterwards, normal webhook admission flow continues: the request is dispatched to all eligible webhook configurations inside `ws1` and the object in request is mutated or validated. | ||
* **Admitting local resources.** The second case is when the webhook configuration exists in the same workspace as the object it's handling. The admission plugin sees the resource is not sourced via an APIBinding, and so it looks for eligible webhook configurations locally, and dispatches the request to the webhooks there. The same would of course be true if APIExport and its APIBinding lived in the same workspace: the APIExport would resolve to the same cluster. | ||
|
||
Lastly, objects in admission review are annotated with the name of the workspace that owns that object. For example, when Widget `b` from `ws3` is being validated, its caught by `ValidatingWebhookConfiguration` in `ws1`, but the webhook will see `kcp.io/cluster: ws3` annotation on the reviewed object. |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.