View Source Bonny.Pluggable.Finalizer (bonny v1.4.0)

Declare a finalizer and its implementation.

Kubernetes Docs:

Use with SkipObservedGenerations

This step is best used with and placed right after Bonny.Pluggable.SkipObservedGenerations in your controller. Have a look at the examples below.

Note for Testing

This step directly updates the resource on the kubernetes cluster. In order to write unit tests, you therefore want to use K8s.Client.DynamicHTTPProvider in order to mock the calls to Kubernetes.

Examples

See options/0, finalizer_impl/0 and add_to_resource/0 for more infos on the options.

By default, a missing finalizer is not added to the resource.

step Bonny.Pluggable.SkipObservedGenerations
step Bonny.Pluggable.Finalizer,
  id: "example.com/cleanup",
  impl: &__MODULE__.cleanup/1

Set add_to_resource to true in order for Bonny to always add it.

step Bonny.Pluggable.SkipObservedGenerations
step Bonny.Pluggable.Finalizer,
  id: "example.com/cleanup",
  impl: &__MODULE__.cleanup/1,
  add_to_resource: true

Or make it depending on the event/resource and enable logs.

step Bonny.Pluggable.SkipObservedGenerations
step Bonny.Pluggable.Finalizer,
  id: "example.com/cleanup",
  impl: &__MODULE__.cleanup/1,
  add_to_resource: &__MODULE__.deletion_policy_not_abandon/1,
  log: :debug

Summary

Types

Boolean or callback of arity 1 to tell Bonny whether or not to add the finalizer to the resource if it is missing. If it is a callback, it receives the %Bonny.Axn{} token and shoulr return a boolean.

The implementation of the finalizer. This is a function of arity 1 which is called when the resource is deleted. It receives the %Bonny.Axn{} token as argument and should return the same.

  • id - Fully qualified finalizer identifier
  • impl - The implementation of the finalizer. See finalizer_impl/0
  • add_to_resource - (otional) whether Bonny should add the finalizer to the resource if it is missing. See add_to_resource/0 %Bonny.Axn{} token. Defaults to false.
  • log_level - (optional) Log level used for logging by this step. :disable for no logs. Defaults to :disable

Types

@type add_to_resource() :: boolean() | (Bonny.Axn.t() -> boolean())

Boolean or callback of arity 1 to tell Bonny whether or not to add the finalizer to the resource if it is missing. If it is a callback, it receives the %Bonny.Axn{} token and shoulr return a boolean.

@type finalizer_impl() ::
  (Bonny.Axn.t() -> {:ok, Bonny.Axn.t()} | {:error, Bonny.Axn.t()})

The implementation of the finalizer. This is a function of arity 1 which is called when the resource is deleted. It receives the %Bonny.Axn{} token as argument and should return the same.

@type options() :: [
  id: binary(),
  impl: finalizer_impl(),
  add_to_resource: add_to_resource(),
  log_level: Logger.level() | :disable
]
  • id - Fully qualified finalizer identifier
  • impl - The implementation of the finalizer. See finalizer_impl/0
  • add_to_resource - (otional) whether Bonny should add the finalizer to the resource if it is missing. See add_to_resource/0 %Bonny.Axn{} token. Defaults to false.
  • log_level - (optional) Log level used for logging by this step. :disable for no logs. Defaults to :disable