# `Bonny.Resource`
[🔗](https://github.com/coryodaniel/bonny/blob/v1.5.0/lib/bonny/resource.ex#L1)

Helper functions for dealing with kubernetes resources.

# `t`

```elixir
@type t() :: map()
```

# `add_owner_reference`

```elixir
@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"
        }]
      }
    }

# `apply`

```elixir
@spec apply(t(), K8s.Conn.t(), Keyword.t()) :: K8s.Client.Runner.Base.result_t()
```

Applies the given resource to the cluster.

# `apply_async`

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

Applies the given resource to the cluster.

# `apply_status`

```elixir
@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.

# `drop_managed_fields`

```elixir
@spec drop_managed_fields(t()) :: t()
```

Removes .metadata.managedFields from the resource.

# `drop_rv`

```elixir
@spec drop_rv(t()) :: t()
```

Removes .metadata.resourceVersion from the resource.

# `gvkn`

```elixir
@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

# `resource_reference`

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"
    }

# `set_label`

```elixir
@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"
        }
      }
    }

# `set_observed_generation`

```elixir
@spec set_observed_generation(t()) :: t()
```

Sets .status.observedGeneration to .metadata.generation

---

*Consult [api-reference.md](api-reference.md) for complete listing*
