View Source Bonny.Resource (bonny v1.4.0)

Helper functions for dealing with kubernetes resources.

Summary

Functions

Add an owner reference to the given resource.

Applies the given resource to the cluster.

Applies the given resource to the cluster.

Applies the status subresource of the given resource to the cluster. If the given resource doesn't contain a status object, nothing is done and :noop is returned.

Removes .metadata.managedFields from the resource.

Removes .metadata.resourceVersion from the resource.

Returns a tuple in the form

Get a reference to the given resource

Set a label on the given resource.

Sets .status.observedGeneration to .metadata.generation

Types

Functions

Link to this function

add_owner_reference(resource, owner, opts \\ [])

View Source
@spec add_owner_reference(t(), map(), keyword(boolean())) :: t()

Add an owner reference to the given resource.

Example

iex> owner = %{
...>   "apiVersion" => "example.com/v1",
...>   "kind" => "Orange",
...>   "metadata" => %{
...>     "name" => "annoying",
...>     "namespace" => "default",
...>     "uid" => "e19b6f40-3293-11ed-a261-0242ac120002"
...>   }
...> }
...> resource = %{
...>   "apiVersion" => "v1",
...>   "kind" => "Pod",
...>   "metadata" => %{"name" => "nginx", "namespace" => "default"}
...>   # spec
...> }
...> Bonny.Resource.add_owner_reference(resource, owner)
%{
  "apiVersion" => "v1",
  "kind" => "Pod",
  "metadata" => %{
    "name" => "nginx",
    "namespace" => "default",
    "ownerReferences" => [%{
      "apiVersion" => "example.com/v1",
      "blockOwnerDeletion" => false,
      "controller" => true,
      "kind" => "Orange",
      "name" => "annoying",
      "uid" => "e19b6f40-3293-11ed-a261-0242ac120002"
    }]
  }
}
Link to this function

apply(resource, conn, opts)

View Source

Applies the given resource to the cluster.

Link to this function

apply_async(resources, conn, opts \\ [])

View Source
@spec apply_async([t()], K8s.Conn.t(), Keyword.t()) :: [
  {t(), K8s.Client.Runner.Base.result_t()}
]

Applies the given resource to the cluster.

Link to this function

apply_status(resource, conn, opts \\ [])

View Source
@spec apply_status(t(), K8s.Conn.t(), Keyword.t()) ::
  K8s.Client.Runner.Base.result_t() | :noop

Applies the status subresource of the given resource to the cluster. If the given resource doesn't contain a status object, nothing is done and :noop is returned.

Link to this function

drop_managed_fields(resource)

View Source
@spec drop_managed_fields(t()) :: t()

Removes .metadata.managedFields from the resource.

@spec drop_rv(t()) :: t()

Removes .metadata.resourceVersion from the resource.

@spec gvkn(t()) ::
  {namespace_name :: binary(), api_version :: binary(), kind :: binary()}

Returns a tuple in the form

  • {apiVersion, kind, namespace/name} for namespaced resources
  • {apiVersion, kind, name} for cluster scoped resources
Link to this function

resource_reference(resource)

View Source

Get a reference to the given resource

Example

iex> resource = %{
...>   "apiVersion" => "example.com/v1",
...>   "kind" => "Orange",
...>   "metadata" => %{
...>     "name" => "annoying",
...>     "namespace" => "default",
...>     "uid" => "e19b6f40-3293-11ed-a261-0242ac120002"
...>   }
...> }
...> Bonny.Resource.resource_reference(resource)
%{
  "apiVersion" => "example.com/v1",
  "kind" => "Orange",
  "name" => "annoying",
  "namespace" => "default",
  "uid" => "e19b6f40-3293-11ed-a261-0242ac120002"
}
Link to this function

set_label(resource, label, value)

View Source
@spec set_label(t(), binary(), binary()) :: t()

Set a label on the given resource.

Example

iex> resource = %{
...>   "apiVersion" => "v1",
...>   "kind" => "Pod",
...>   "metadata" => %{"name" => "nginx", "namespace" => "default"}
...>   # spec
...> }
...> Bonny.Resource.set_label(resource, "app.kubernetes.io/managed-by", "my-operator")
%{
  "apiVersion" => "v1",
  "kind" => "Pod",
  "metadata" => %{
    "name" => "nginx",
    "namespace" => "default",
    "labels" => %{
      "app.kubernetes.io/managed-by" => "my-operator"
    }
  }
}
Link to this function

set_observed_generation(resource)

View Source
@spec set_observed_generation(t()) :: t()

Sets .status.observedGeneration to .metadata.generation