K8s.Conf

K8s.Conf parses Kubernetes config files and generates HTTP headers and options for authenticating to the Kubernetes API.

Build Status Coverage Status Hex.pm Documentation Hex.pm

Installation

If available in Hex, the package can be installed by adding k8s_conf to your list of dependencies in mix.exs:

def deps do
  [
    {:k8s_conf, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/k8s_conf.

Usage

# Defaults to 'current-context', optionally set cluster, context, or user
# opts = [
#   user: "alt-user",
#   cluster: "alt-cluster",
#   context: "alt-context"
# ]

opts = []
config = K8s.Conf.from_file("~/.kube/config", opts)

# Optionally load from a service account
# config = K8s.Conf.from_service_account()

http_request_options = K8s.Conf.RequestOptions.generate(config)
[header: headers, ssl_options: ssl_options] = http_request_options

# Add headers and SSL options to HTTP library of choice

Adding authorization providers

config :k8s_conf, providers: [My.Custom.Provider]

Providers are checked in order, the first to return an authorization struct wins.

Custom providers are processed before default providers.

See Certicate and Token for protocol and behavior implementations.