k8s v0.5.2 K8s.Resource

Kubernetes manifest attribute helpers

Link to this section Summary

Link to this section Functions

Link to this function

all_from_file(path, assigns \\ [])

all_from_file(String.t(), keyword()) ::
  {:ok, [map()]} | {:error, atom() | map()}

Create a list of resource Maps 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}]
            }
          ]
        }
      }
    }
  }
]}
Link to this function

all_from_file!(path, assigns \\ [])

all_from_file!(String.t(), keyword()) :: [map()] | no_return()

Create a list of resource Maps 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}]
            }
          ]
        }
      }
    }
  }
]
Link to this function

annotation(resource, name)

See K8s.Resource.FieldAccessors.annotation/2.

Link to this function

annotations(resource)

See K8s.Resource.FieldAccessors.annotations/1.

Link to this function

api_version(resource)

See K8s.Resource.FieldAccessors.api_version/1.

Link to this function

build(api_version, kind)

build(binary(), binary()) :: map()

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"}}
Link to this function

build(api_version, kind, name)

build(binary(), binary(), binary()) :: map()
Link to this function

build(api_version, kind, namespace, name)

build(binary(), binary(), binary(), binary()) :: map()
Link to this function

build(api_version, kind, namespace, name, labels)

build(binary(), binary(), binary(), binary(), map()) :: map()

See K8s.Resource.Utilization.cpu/1.

Link to this function

from_file(path, assigns \\ [])

from_file(String.t(), keyword()) :: {:ok, map()} | {:error, atom() | map()}

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}]
          }
        ]
      }
    }
  }
}}
Link to this function

from_file!(path, assigns)

from_file!(String.t(), keyword()) :: map() | no_return()

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}]
          }
        ]
      }
    }
  }
}
Link to this function

has_annotation?(resource, name)

See K8s.Resource.FieldAccessors.has_annotation?/2.

Link to this function

has_label?(resource, name)

See K8s.Resource.FieldAccessors.has_label?/2.

See K8s.Resource.FieldAccessors.kind/1.

Link to this function

label(resource, name)

See K8s.Resource.FieldAccessors.label/2.

Link to this function

labels(resource)

See K8s.Resource.FieldAccessors.labels/1.

See K8s.Resource.Utilization.memory/1.

Link to this function

metadata(resource)

See K8s.Resource.FieldAccessors.metadata/1.

See K8s.Resource.FieldAccessors.name/1.

Link to this function

namespace(resource)

See K8s.Resource.FieldAccessors.namespace/1.