View Source Bonny.Resource (bonny v1.2.0)
Helper functions for dealing with kubernetes resources.
Link to this section 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
Link to this section Types
@type t() :: map()
Link to this section Functions
Add an owner reference to the given resource.
example
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"
}]
}
}
@spec apply(t(), K8s.Conn.t(), Keyword.t()) :: K8s.Client.Runner.Base.result_t()
Applies the given resource to the cluster.
@spec apply_async([t()], K8s.Conn.t(), Keyword.t()) :: [ {t(), K8s.Client.Runner.Base.result_t()} ]
Applies the given resource to the cluster.
@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.
Removes .metadata.managedFields from the resource.
Removes .metadata.resourceVersion from the resource.
Returns a tuple in the form
- {apiVersion, kind, namespace/name} for namespaced resources
- {apiVersion, kind, name} for cluster scoped resources
Get a reference to the given resource
example
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 a label on the given resource.
example
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"
}
}
}
Sets .status.observedGeneration to .metadata.generation