k8s v0.2.12 K8s.Path

Generates Kubernetes REST API Paths

Link to this section Summary

Functions

Generates the API path for a given group/version and resource.

Find valid path params in a URL path.

Replaces path variables with options.

Link to this section Functions

Link to this function

build(group_version, resource, verb, params)
build(binary(), map(), atom(), keyword(atom())) ::
  {:ok, binary()} | {:error, :unsupported_verb | binary()}

Generates the API path for a given group/version and resource.

Examples

Generate a path for a cluster scoped resource:

iex> resource = %{
...>   "kind" => "CertificateSigningRequest",
...>   "name" => "certificatesigningrequests",
...>   "namespaced" => false,
...>   "verbs" => ["update"]
...> }
...> K8s.Path.build("apps/v1", resource, :update, [name: "foo"])
{:ok, "/apis/apps/v1/certificatesigningrequests/foo"}

Generate a path for a namespace scoped resource:

iex> resource = %{
...>   "kind" => "Pod",
...>   "name" => "pods",
...>   "namespaced" => true,
...>   "verbs" => ["update"]
...> }
...> K8s.Path.build("v1", resource, :update, [namespace: "default", name: "foo"])
{:ok, "/api/v1/namespaces/default/pods/foo"}

Generate a path for a namespace scoped resource on the collection: (ie create, list)

iex> resource = %{
...>   "kind" => "Pod",
...>   "name" => "pods",
...>   "namespaced" => true,
...>   "verbs" => ["create"]
...> }
...> K8s.Path.build("v1", resource, :create, [namespace: "default"])
{:ok, "/api/v1/namespaces/default/pods"}

Generating a listing path for a namespace:

iex> resource = %{
...>   "kind" => "Pod",
...>   "name" => "pods",
...>   "namespaced" => true,
...>   "verbs" => ["list"]
...> }
...> K8s.Path.build("v1", resource, :list, [namespace: "default"])
{:ok, "/api/v1/namespaces/default/pods"}

Generating a listing path for a all namespaces:

iex> resource = %{
...>   "kind" => "Pod",
...>   "name" => "pods",
...>   "namespaced" => true,
...>   "verbs" => ["list"]
...> }
...> K8s.Path.build("v1", resource, :list_all_namespaces, [])
{:ok, "/api/v1/pods"}

Generating a path for a subresource:

iex> resource = %{
...>   "kind" => "Pod",
...>   "name" => "pods/status",
...>   "namespaced" => true,
...>   "verbs" => ["get"]
...> }
...> K8s.Path.build("v1", resource, :get, [namespace: "default", name: "foo"])
{:ok, "/api/v1/namespaces/default/pods/foo/status"}

Deleting a collection:

iex> resource = %{
...>   "kind" => "Pod",
...>   "name" => "pods",
...>   "namespaced" => true,
...>   "verbs" => [
...>     "deletecollection"
...>   ]
...> }
...> K8s.Path.build("v1", resource, :deletecollection, [namespace: "default"])
{:ok, "/api/v1/namespaces/default/pods"}
Link to this function

find_params(path_with_args)
find_params(binary()) :: [atom()]

Find valid path params in a URL path.

Examples

iex> K8s.Path.find_params("/foo/{name}")
[:name]

iex> K8s.Path.find_params("/foo/{namespace}/bar/{name}")
[:namespace, :name]

iex> K8s.Path.find_params("/foo/bar")
[]
Link to this function

replace_path_vars(path_template, opts)
replace_path_vars(binary(), keyword(atom())) :: binary()

Replaces path variables with options.

Examples

iex> K8s.Path.replace_path_vars("/foo/{name}", name: "bar")
"/foo/bar"