View Source BonnyPlug.WebhookHandler behaviour (bonny_plug v1.0.3)
This module dispatches the admission webhook requests to the handlers. You can use
this module in your webhook
handler to connect it to the Plug.
options
Options
When use
-ing this module, you have to tell it about the resource you want to act upon:
custom-resource-definition
Custom Resource Definition
crd
- If you have a CRD YAML file, just pass the path to the file as optioncrd
. TheWebhookHandler
will extract the required values from the file.
explicit-resource-specification
Explicit Resource Specification
The WebhookHandler
needs to know the following values from the resource you want to act upon:
group
- The group of the resource, e.g."apps"
plural
- The plural name of the resource, e.g."deployments"
api_versions
- A list of versions of the resource, e.g.["v1beta1", "v1"]
functions-to-be-implemented-in-your-webhook-handler
Functions to be implemented in your Webhook Handler
Your webhook handler should implement at least one of the two functions validating_webhook/1
and
mutating_webhook/1
. These are going to be called by this module depending on whether the incoming request is of
type :validating_webhook
or :mutating_webhook
according to the BonnyPlug.WebhookPlug
configuration.
examples
Examples
defmodule FooAdmissionWebhookHandler do
use BonnyPlug.WebhookHandler, crd: "manifest/src/crds/foo.crd.yaml"
@impl true
def validating_webhook(admission_review) do
check_immutable(admission_review, ["spec", "someField"])
end
@impl true
def mutating_webhook(admission_review) do
allow(admission_review)
end
end
defmodule BarAdmissionWebhookHandler do
use BonnyPlug.WebhookHandler,
group: "my.operator.com",
resource: "barresources",
api_versions: ["v1"]
@impl true
def validating_webhook(admission_review) do
check_immutable(admission_review, ["spec", "someField"])
end
@impl true
def mutating_webhook(admission_review) do
deny(admission_review)
end
end
Link to this section Summary
Link to this section Types
@type webhook_type() :: :mutating_webhook | :validating_webhook
Link to this section Callbacks
@callback mutating_webhook(BonnyPlug.AdmissionReview.t()) :: BonnyPlug.AdmissionReview.t()
@callback process(BonnyPlug.AdmissionReview.t(), BonnyPlug.WebhookPlug.webhook_type()) :: BonnyPlug.AdmissionReview.t()
@callback validating_webhook(BonnyPlug.AdmissionReview.t()) :: BonnyPlug.AdmissionReview.t()