bonny v0.4.1 Bonny.Server.Watcher behaviour

Continuously watch a list Operation for add, modify, and delete events.

Link to this section Summary

Link to this section Functions

Link to this function

dispatch(map, controller)
dispatch(map(), atom()) :: no_return()

Dispatches an ADDED, MODIFIED, and DELETED events to an controller

Link to this function

process_line(line, current_rv, module)
process_line(binary(), binary(), module()) :: {:ok, binary()} | {:error, :gone}

Link to this function

process_lines(lines, rv, module)
process_lines([binary()], binary(), module()) ::
  {:ok, binary()} | {:error, :gone}

Link to this function

watch(module, rv, pid)
watch(module(), binary(), pid()) :: no_return()

Link to this section Callbacks

Link to this callback

add(map)
add(map()) :: :ok | :error

Link to this callback

delete(map)
delete(map()) :: :ok | :error

Link to this callback

modify(map)
modify(map()) :: :ok | :error

Link to this callback

watch_operation()
watch_operation() :: K8s.Operation.t()

K8s.Operation to watch.

Examples

Log all pod lifecycle events

    defmodule PodLifecycleLogger do
      use Bonny.Server.Watcher

      @impl true
      def watch_operation() do
        K8s.Client.list("v1", :pods, namespace: :all)
      end

      @impl true
      def add(pod) do
        log_event(:add, pod)
      end

      @impl true
      def modify(pod) do
        log_event(:modify, pod)
      end

      @impl true
      def delete(pod) do
        log_event(:delete, pod)
      end

      @spec log_event(atom, map) :: :ok
      def log_event(type, pod) do
        name = get_in(pod, ["metadata", "name"])
        namespace = get_in(pod, ["metadata", "namepace"]) || "default"
        # log type,name,namespace here
      end
    end