View Source Bonny.Operator behaviour (bonny v1.4.0)

Defines a Bonny operator.

The operator defines custom resources, watch queries and their controllers and serves as the entry point to the watching and handling of processes.

Overall, an operator has the following responsibilities:

  • to provide a wrapper for starting and stopping the operator as part of a supervision tree

  • To define the resources to be watched together with the controllers which handle action events on those resources.

  • to define an initial pluggable pipeline for all action events to pass through

  • To define any custom resources ending up in the manifest generated by mix bonny.gen.manifest

Operators

An operator is defined with the help of Bonyy.Operator. The step :delegate_to_controller has do be part of the pipeline. It is the step that calls the handling controller for a given action event:

defmodule MyOperatorApp.Operator do
  use Bonny.Operator, default_watching_namespace: "default"

  # step ...
  step :delegate_to_controller
  # step ...

  def controllers(watching_namespace, _opts) do
    [
      %{
        query: K8s.Client.watch("my-controller.io", "MyCustomResource", namespace: nil)
        controller: MyOperator.Controller.MyCustomResourceController
      }
    ]
  end


end

Summary

Types

@type controller_spec() :: %{
  optional(:controller) => module() | {module(), keyword()},
  query: K8s.Operation.t()
}

Callbacks

@callback controllers(binary(), Keyword.t()) :: [controller_spec()]
@callback crds() :: [Bonny.API.CRD.t()]