k8s v0.2.8 K8s.Config

Add runtime cluster configuration with environment variables.

Each variable consists of a prefix that determines where the value will be placed in the config and a suffix that is the cluster name. The cluster name will be atomized.

Environment Variable Prefixes:

  • K8S_CLUSTER_CONF_SA_ - boolean enables authentication to the k8s API with the pods spec.serviceAccountName.
  • K8S_CLUSTER_CONF_PATH_ - string absolute path to the kube config file.
  • K8S_CLUSTER_CONF_CONTEXT_ string which context to use in the kube config file.

Examples

  export K8S_CLUSTER_CONF_SA_us_central=true
  export K8S_CLUSTER_CONF_PATH_us_east="east.yaml"
  export K8S_CLUSTER_CONF_CONTEXT_us_east="east"
  export K8S_CLUSTER_CONF_PATH_us_west="west.yaml"
  export K8S_CLUSTER_CONF_CONTEXT_us_west="west"

Link to this section Summary

Functions

Returns runtime and compile time cluster configuration merged together.

Subset of env vars applicable to k8s

Cluster configuration read from env variables. To be merged over Application.get_env(:k8s, :clusters).

Link to this section Functions

Link to this function

clusters()
clusters() :: map()

Returns runtime and compile time cluster configuration merged together.

Link to this function

env()
env() :: map()

Subset of env vars applicable to k8s

Link to this function

runtime_clusters_config(env_vars, config)
runtime_clusters_config(map(), map()) :: map()

Cluster configuration read from env variables. To be merged over Application.get_env(:k8s, :clusters).

Examples

Overriding compile time configs

iex> env = %{"K8S_CLUSTER_CONF_PATH_dev" => "runtime/path/to/dev.conf"}
...> compile_config = %{dev: %{conf: "compiletime/path/to/dev.conf"}}
...> K8s.Config.runtime_clusters_config(env, compile_config)
%{dev: %{conf: "runtime/path/to/dev.conf"}}

Merging compile time configs

iex> env = %{"K8S_CLUSTER_CONF_CONTEXT_dev" => "runtime-context"}
...> compile_config = %{dev: %{conf: "compiletime/path/to/dev.conf"}}
...> K8s.Config.runtime_clusters_config(env, compile_config)
%{dev: %{conf: "compiletime/path/to/dev.conf", conf_opts: [context: "runtime-context"]}}

Adding clusters at runtime

iex> env = %{"K8S_CLUSTER_CONF_PATH_us_east" => "runtime/path/to/us_east.conf", "K8S_CLUSTER_CONF_CONTEXT_us_east" => "east-context"}
...> compile_config = %{us_west: %{conf: "compiletime/path/to/us_west.conf"}}
...> K8s.Config.runtime_clusters_config(env, compile_config)
%{us_east: %{conf: "runtime/path/to/us_east.conf", conf_opts: [context: "east-context"]}, us_west: %{conf: "compiletime/path/to/us_west.conf"}}