BonnyPlug.WebhookHandler behaviour (bonny_plug v1.0.3) View Source

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

When use-ing this module, you have to tell it about the resource you want to act upon:

Custom Resource Definition

  • crd - If you have a CRD YAML file, just pass the path to the file as option crd. The WebhookHandler will extract the required values from the file.

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

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

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

Specs

webhook_type() :: :mutating_webhook | :validating_webhook

Link to this section Callbacks