Packages
k8s
0.1.3
2.8.0
2.7.0
2.6.2
2.6.1
2.6.0
2.5.0
2.4.2
2.4.1
2.4.0
2.3.0
2.2.0
2.1.1
2.1.0
2.0.3
2.0.2
2.0.1
2.0.0
2.0.0-rc.6
2.0.0-rc.5
2.0.0-rc.4
2.0.0-rc.3
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
1.2.1
1.2.0
1.1.10
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.0
1.0.0-rc1
0.5.2
0.5.1
0.5.0
0.5.0-rc.2
0.5.0-rc.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.13
0.2.12
0.2.11
0.2.10
0.2.9
0.2.8
0.2.7
retired
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.3
Kubernetes API Client for Elixir
Current section
Files
Jump to
Current section
Files
lib/k8s.ex
defmodule K8s do
@moduledoc """
Documentation for K8s.
"""
@doc """
Returns the kind of k8s resource.
## Examples
iex> K8s.kind(%{"kind" => "Deployment"})
"Deployment"
"""
@spec kind(map()) :: binary() | nil
def kind(resource = %{}), do: resource["kind"]
@doc """
Returns the metadata of k8s resource.
## Examples
iex> K8s.metadata(%{"metadata" => %{"name" => "nginx", "namespace" => "foo"}})
%{"name" => "nginx", "namespace" => "foo"}
"""
@spec metadata(map()) :: map() | nil
def metadata(resource = %{}), do: resource["metadata"]
@doc """
Returns the name of k8s resource.
## Examples
iex> K8s.name(%{"metadata" => %{"name" => "nginx", "namespace" => "foo"}})
"nginx"
"""
@spec name(map()) :: binary() | nil
def name(resource = %{}), do: get_in(resource, ~w(metadata name))
@doc """
Returns the namespace of k8s resource.
## Examples
iex> K8s.namespace(%{"metadata" => %{"name" => "nginx", "namespace" => "foo"}})
"foo"
"""
@spec namespace(map()) :: binary() | nil
def namespace(resource = %{}), do: get_in(resource, ~w(metadata namespace))
@doc """
Returns the labels of k8s resource.
## Examples
iex> K8s.labels(%{"metadata" => %{"labels" => %{"env" => "test"}}})
%{"env" => "test"}
"""
@spec labels(map()) :: map()
def labels(resource = %{}), do: get_in(resource, ~w(metadata labels)) || %{}
@doc """
Returns the value of a k8s resource's label.
## Examples
iex> K8s.label(%{"metadata" => %{"labels" => %{"env" => "test"}}}, "env")
"test"
"""
@spec label(map(), binary) :: binary() | nil
def label(resource = %{}, name), do: get_in(resource, ["metadata", "labels", name])
@doc """
Returns the annotations of k8s resource.
## Examples
iex> K8s.annotations(%{"metadata" => %{"annotations" => %{"env" => "test"}}})
%{"env" => "test"}
"""
@spec annotations(map()) :: map()
def annotations(resource = %{}), do: get_in(resource, ~w(metadata annotations)) || %{}
@doc """
Returns the value of a k8s resource's annotation.
## Examples
iex> K8s.annotation(%{"metadata" => %{"annotations" => %{"env" => "test"}}}, "env")
"test"
"""
@spec annotation(map(), binary) :: binary() | nil
def annotation(resource = %{}, name), do: get_in(resource, ["metadata", "annotations", name])
@doc """
Check if a label is present.
## Examples
iex> K8s.has_label?(%{"metadata" => %{"labels" => %{"env" => "test"}}}, "env")
true
iex> K8s.has_label?(%{"metadata" => %{"labels" => %{"env" => "test"}}}, "foo")
false
"""
@spec has_label?(map(), binary()) :: boolean()
def has_label?(resource = %{}, name), do: resource |> labels() |> Map.has_key?(name)
@doc """
Check if an annotation is present.
## Examples
iex> K8s.has_annotation?(%{"metadata" => %{"annotations" => %{"env" => "test"}}}, "env")
true
iex> K8s.has_annotation?(%{"metadata" => %{"annotations" => %{"env" => "test"}}}, "foo")
false
"""
@spec has_annotation?(map(), binary()) :: boolean()
def has_annotation?(resource = %{}, name), do: resource |> annotations() |> Map.has_key?(name)
end