# `Kubereq.Kubeconfig`
[🔗](https://github.com/mruoss/kubereq/blob/v0.4.3/lib/kubereq/kubeconfig.ex#L1)

This is the `Pluggable.Token` for the pipeline loading the Kubernetes config.
The Kubeconfig represents the configuration to establish a connection to
the Kubernetes cluster. It contains informations like endpoint, certificates,
user authentication details etc.

In most cases you can just rely on `Kubereq.Kubeconfig.Default` to load
the Kubeconfig from well-known places.

Sometimes you only want to allow to load the Kubeconfig from a specific
YAML file or rely on an ENV variable pointing to that file. Check out
the `Kubereq.Kubeconfig.*` modules.

You can also chain these modules to build your own Kubeconfig loader pipeline.

```
defmodule MyKubeconfLoader do
  use Pluggable.StepBuilder

  step Kubereq.Kubeconfig.ENV
  step Kubereq.Kubeconfig.File, path: "/path/to/kubeconfig.yaml"
end
```

# `t`

```elixir
@type t() :: %Kubereq.Kubeconfig{
  assigns: map(),
  clusters: [map()],
  contexts: [map()],
  current_cluster: map(),
  current_context: String.t(),
  current_namespace: String.t() | nil,
  current_user: map(),
  halted: boolean(),
  users: [map()]
}
```

The `%Kubereq.Kubeconfig{}` struct holds information required to connect to
Kubernetes clusters

For descriptions of the fields, refer to the
[kubeconfig.v1](https://kubernetes.io/docs/reference/config-api/kubeconfig.v1/) documentation.

# `load`

```elixir
@spec load(pipeline :: module() | {module(), keyword()}) :: t()
```

Loads the Kubernetes config by running the given `pipeline`. Returns the
resulting `%Kubereq.Kubeconfig{}`.

`pipeline` can be passed in the form of `{pipeline_module, opts}` tuples,
a single `pipeline_module` or a list of either.

### Example

Single pipeline module without opts passed as module:

    Kubereq.Kubeconfig.load(Kubereq.Kubeconfig.Default)

Single pipeline module with opts:

    Kubereq.Kubeconfig.load({Kubereq.Kubeconfig.File, path: "/path/to/kubeconfig"})

List of either:

    Kubereq.Kubeconfig.load([
      Kubereq.Kubeconfig.ENV,
      {Kubereq.Kubeconfig.File, path: "~/.kube/config"},
      Kubereq.Kubeconfig.ServiceAccount
    ])

# `new!`

```elixir
@spec new!(keyword()) :: t()
```

Creates a new `%Kubereq.Kubeconfig{}` struct with the given fields

# `set_current_context`

```elixir
@spec set_current_context(kubeconfig :: t(), current_context :: String.t()) :: t()
```

Sets the current context. This function sets `current_cluster` and
`current_user` in the given `Kubereq.Kubeconfig.t()`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
