k8s v0.2.1 K8s.Resource
Manifest attribute helpers
Link to this section Summary
Functions
Returns the value of a k8s resource's annotation
Returns the annotations of k8s resource
Create a resource Map
from a YAML file
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
Link to this section Functions
annotation(resource, name)
Returns the value of a k8s resource's annotation.
Examples
iex> K8s.Resource.annotation(%{"metadata" => %{"annotations" => %{"env" => "test"}}}, "env")
"test"
annotations(resource)
Returns the annotations of k8s resource.
Examples
iex> K8s.Resource.annotations(%{"metadata" => %{"annotations" => %{"env" => "test"}}})
%{"env" => "test"}
from_file!(path, assigns)
Create a resource Map
from a YAML file.
Raises File.Error
when the file does not exist.
Examples
iex> opts = [namespace: "default", name: "nginx", image: "nginx:nginx:1.7.9"]
...> K8s.Resource.from_file!("test/support/deployment.yaml", opts)
%{
"apiVersion" => "apps/v1",
"kind" => "Deployment",
"metadata" => %{
"labels" => %{"app" => "nginx"},
"name" => "nginx-deployment",
"namespace" => "default"
},
"spec" => %{
"replicas" => 3,
"selector" => %{"matchLabels" => %{"app" => "nginx"}},
"template" => %{
"metadata" => %{"labels" => %{"app" => "nginx"}},
"spec" => %{
"containers" => [
%{
"image" => "nginx:nginx:1.7.9",
"name" => "nginx",
"ports" => [%{"containerPort" => 80}]
}
]
}
}
}
}
has_annotation?(resource, name)
Check if an annotation is present.
Examples
iex> K8s.Resource.has_annotation?(%{"metadata" => %{"annotations" => %{"env" => "test"}}}, "env")
true
iex> K8s.Resource.has_annotation?(%{"metadata" => %{"annotations" => %{"env" => "test"}}}, "foo")
false
has_label?(resource, name)
Check if a label is present.
Examples
iex> K8s.Resource.has_label?(%{"metadata" => %{"labels" => %{"env" => "test"}}}, "env")
true
iex> K8s.Resource.has_label?(%{"metadata" => %{"labels" => %{"env" => "test"}}}, "foo")
false
kind(resource)
Returns the kind of k8s resource.
Examples
iex> K8s.Resource.kind(%{"kind" => "Deployment"})
"Deployment"
label(resource, name)
Returns the value of a k8s resource's label.
Examples
iex> K8s.Resource.label(%{"metadata" => %{"labels" => %{"env" => "test"}}}, "env")
"test"
labels(resource)
Returns the labels of k8s resource.
Examples
iex> K8s.Resource.labels(%{"metadata" => %{"labels" => %{"env" => "test"}}})
%{"env" => "test"}
metadata(resource)
Returns the metadata of k8s resource.
Examples
iex> K8s.Resource.metadata(%{"metadata" => %{"name" => "nginx", "namespace" => "foo"}})
%{"name" => "nginx", "namespace" => "foo"}
name(resource)
Returns the name of k8s resource.
Examples
iex> K8s.Resource.name(%{"metadata" => %{"name" => "nginx", "namespace" => "foo"}})
"nginx"
namespace(resource)
Returns the namespace of k8s resource.
Examples
iex> K8s.Resource.namespace(%{"metadata" => %{"name" => "nginx", "namespace" => "foo"}})
"foo"