View Source K8s.Resource (k8s v2.6.1)

Kubernetes manifest attribute helpers

Summary

Types

@type yaml_elixir_error_t() ::
  YamlElixir.FileNotFoundError.t() | YamlElixir.ParsingError.t()

Functions

Link to this function

all_from_file(filepath, assigns \\ [])

View Source
@spec all_from_file(
  binary(),
  keyword()
) :: {:ok, [map()]} | {:error, :enoent | yaml_elixir_error_t()}

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 \\ [])

View Source
@spec 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)

View Source

See K8s.Resource.FieldAccessors.annotation/2.

See K8s.Resource.FieldAccessors.annotations/1.

See K8s.Resource.FieldAccessors.api_version/1.

Link to this function

build(api_version, kind)

View Source
@spec 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)

View Source
@spec build(binary(), binary(), binary()) :: map()
Link to this function

build(api_version, kind, namespace, name)

View Source
@spec build(binary(), binary(), binary(), binary()) :: map()
Link to this function

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

View Source
@spec build(binary(), binary(), binary(), binary(), map()) :: map()

See K8s.Resource.Utilization.cpu/1.

Link to this function

from_file(filepath, assigns \\ [])

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

from_file!(path, assigns \\ [])

View Source
@spec from_file!(binary(), keyword() | nil) :: 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)

View Source

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

Link to this function

has_label?(resource, name)

View Source

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

See K8s.Resource.FieldAccessors.kind/1.

See K8s.Resource.FieldAccessors.label/2.

See K8s.Resource.FieldAccessors.labels/1.

See K8s.Resource.Utilization.memory/1.

See K8s.Resource.FieldAccessors.metadata/1.

See K8s.Resource.FieldAccessors.name/1.

See K8s.Resource.FieldAccessors.namespace/1.