View Source K8s.Resource (k8s v2.4.2)
Kubernetes manifest attribute helpers
Summary
Types
@type yaml_elixir_error_t() :: YamlElixir.FileNotFoundError.t() | YamlElixir.ParsingError.t()
Functions
@spec all_from_file( binary(), keyword() ) :: {:ok, [map()]} | {:error, :enoent | yaml_elixir_error_t()}
Create a list of resource Map
s from a YAML file containing a YAML stream.
Examples
iex> opts = [namespace: "default", name: "nginx", image: "nginx:nginx:1.7.9"]
...> K8s.Resource.all_from_file("test/support/helm-chart.yaml", opts)
{:ok, [
%{
"apiVersion" => "v1",
"kind" => "Namespace",
"metadata" => %{"name" => "default"}
},
%{
"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}]
}
]
}
}
}
}
]}
Create a list of resource Map
s from a YAML file containing a YAML stream.
Raises File.Error
when the file does not exist.
Examples
iex> opts = [namespace: "default", name: "nginx", image: "nginx:nginx:1.7.9"]
...> K8s.Resource.all_from_file!("test/support/helm-chart.yaml", opts)
[
%{
"apiVersion" => "v1",
"kind" => "Namespace",
"metadata" => %{"name" => "default"}
},
%{
"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}]
}
]
}
}
}
}
]
Helper for building a kubernetes' resource Map
Examples
iex> K8s.Resource.build("v1", "Pod")
%{"apiVersion" => "v1", "kind" => "Pod", "metadata" => %{}}
iex> K8s.Resource.build("v1", "Namespace", "foo")
%{"apiVersion" => "v1", "kind" => "Namespace", "metadata" => %{"name" => "foo"}}
iex> K8s.Resource.build("v1", "Pod", "default", "foo")
%{"apiVersion" => "v1", "kind" => "Pod", "metadata" => %{"namespace" => "default", "name" => "foo"}}
@spec from_file(binary(), keyword() | nil) :: {:ok, map()} | {:error, :enoent | yaml_elixir_error_t()}
Create a resource Map
from a YAML file.
Examples
iex> opts = [namespace: "default", name: "nginx", image: "nginx:nginx:1.7.9"]
...> K8s.Resource.from_file("test/support/deployment.yaml", opts)
{:ok, %{
"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}]
}
]
}
}
}
}}
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}]
}
]
}
}
}
}