K8s.Resource.FieldAccessors (k8s v2.7.0)

View Source

Helper functions for accessing common fields

Summary

Functions

Returns the value of a k8s resource's annotation.

Returns the annotations of k8s resource.

Returns the apiVersion of k8s resource.

Check if an annotation is present.

Check if a label is present.

Returns the kind of k8s resource.

Returns the value of a k8s resource's label.

Returns the labels of k8s resource.

Returns the metadata of k8s resource.

Returns the name of k8s resource.

Returns the namespace of k8s resource.

Functions

annotation(resource, name)

@spec annotation(map(), binary()) :: binary() | nil

Returns the value of a k8s resource's annotation.

Examples

iex> K8s.Resource.FieldAccessors.annotation(%{"metadata" => %{"annotations" => %{"env" => "test"}}}, "env")
"test"

annotations(resource)

@spec annotations(map()) :: map()

Returns the annotations of k8s resource.

Examples

iex> K8s.Resource.FieldAccessors.annotations(%{"metadata" => %{"annotations" => %{"env" => "test"}}})
%{"env" => "test"}

api_version(resource)

@spec api_version(map()) :: binary() | nil

Returns the apiVersion of k8s resource.

Examples

iex> K8s.Resource.FieldAccessors.api_version(%{"apiVersion" => "apps/v1"})
"apps/v1"

has_annotation?(resource, name)

@spec has_annotation?(map(), binary()) :: boolean()

Check if an annotation is present.

Examples

iex> K8s.Resource.FieldAccessors.has_annotation?(%{"metadata" => %{"annotations" => %{"env" => "test"}}}, "env")
true

iex> K8s.Resource.FieldAccessors.has_annotation?(%{"metadata" => %{"annotations" => %{"env" => "test"}}}, "foo")
false

has_label?(resource, name)

@spec has_label?(map(), binary()) :: boolean()

Check if a label is present.

Examples

iex> K8s.Resource.FieldAccessors.has_label?(%{"metadata" => %{"labels" => %{"env" => "test"}}}, "env")
true

iex> K8s.Resource.FieldAccessors.has_label?(%{"metadata" => %{"labels" => %{"env" => "test"}}}, "foo")
false

kind(resource)

@spec kind(map()) :: binary() | nil

Returns the kind of k8s resource.

Examples

iex> K8s.Resource.FieldAccessors.kind(%{"kind" => "Deployment"})
"Deployment"

label(resource, name)

@spec label(map(), binary()) :: binary() | nil

Returns the value of a k8s resource's label.

Examples

iex> K8s.Resource.FieldAccessors.label(%{"metadata" => %{"labels" => %{"env" => "test"}}}, "env")
"test"

labels(resource)

@spec labels(map()) :: map()

Returns the labels of k8s resource.

Examples

iex> K8s.Resource.FieldAccessors.labels(%{"metadata" => %{"labels" => %{"env" => "test"}}})
%{"env" => "test"}

metadata(resource)

@spec metadata(map()) :: map() | nil

Returns the metadata of k8s resource.

Examples

iex> K8s.Resource.FieldAccessors.metadata(%{"metadata" => %{"name" => "nginx", "namespace" => "foo"}})
%{"name" => "nginx", "namespace" => "foo"}

name(resource)

@spec name(map()) :: binary() | nil

Returns the name of k8s resource.

Examples

iex> K8s.Resource.FieldAccessors.name(%{"metadata" => %{"name" => "nginx", "namespace" => "foo"}})
"nginx"

namespace(resource)

@spec namespace(map()) :: binary()

Returns the namespace of k8s resource.

Examples

iex> K8s.Resource.FieldAccessors.namespace(%{"metadata" => %{"name" => "nginx", "namespace" => "foo"}})
"foo"