kubeconfig

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package kubeconfig is a minimal implementation of the Kubernetes kubeconfig configuration file format. It aims to be simple, fast, and use minimal dependencies.

The package makes a best-effort attempt to follow the same schema and merging logic published on the Kubernetes documentation. If perfect compatibility with Kubernetes is needed, the official Kubernetes client-go/tools/clientcmd package should be used instead.

Types have the same identifiers and YAML/JSON names as those used specified by Kubernetes source code for the kubeconfig structs, with the exception of changes that make it possible to differentiate between nil and empty basic types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthInfo

type AuthInfo struct {
	ClientCertificateFile *string             `yaml:"client-certificate,omitempty"      json:"client-certificate,omitempty"`
	ClientCertificateData *string             `yaml:"client-certificate-data,omitempty" json:"client-certificate-data,omitempty"`
	ClientKeyFile         *string             `yaml:"client-key,omitempty"              json:"client-key,omitempty"`
	ClientKeyData         *string             `yaml:"client-key-data,omitempty"         json:"client-key-data,omitempty"`
	TokenFile             *string             `yaml:"tokenFile,omitempty"               json:"tokenFile,omitempty"`
	Token                 *string             `yaml:"token,omitempty"                   json:"token,omitempty"`
	As                    *string             `yaml:"as,omitempty"                      json:"as,omitempty"`
	AsUID                 *string             `yaml:"as-uid,omitempty"                  json:"as-uid,omitempty"`
	AsGroups              []string            `yaml:"as-groups,omitempty"               json:"as-groups,omitempty"`
	AsUserExtra           map[string][]string `yaml:"as-user-extra,omitempty"           json:"as-user-extra,omitempty"`
	Username              *string             `yaml:"username,omitempty"                json:"username,omitempty"`
	Password              *string             `yaml:"password,omitempty"                json:"password,omitempty"`
	AuthProvider          *AuthProviderConfig `yaml:"auth-provider,omitempty"           json:"auth-provider,omitempty"`
	Exec                  *ExecConfig         `yaml:"exec,omitempty"                    json:"exec,omitempty"`
	Extensions            []NamedExtension    `yaml:"extensions,omitempty"              json:"extensions,omitempty"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

AuthInfo describes the authentication method for a user.

See: documentation or kubernetes source

func (*AuthInfo) Clone

func (a *AuthInfo) Clone() *AuthInfo

Clone creates a deep copy.

func (AuthInfo) CloneInto

func (a AuthInfo) CloneInto(target *AuthInfo)

CloneInto replaces the value of another AuthInfo with a deep copy of this AuthInfo's values.

type AuthProviderConfig

type AuthProviderConfig struct {
	Name   *string           `yaml:"name,omitempty"   json:"name,omitempty"   validate:"required"`
	Config map[string]string `yaml:"config,omitempty" json:"config,omitempty" validate:"required"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

AuthProviderConfig specifies an authentication provider and its configuration.

See: documentation or kubernetes source

func (*AuthProviderConfig) Clone

Clone creates a deep copy.

func (AuthProviderConfig) CloneInto

func (a AuthProviderConfig) CloneInto(target *AuthProviderConfig)

CloneInto replaces the value of another AuthProviderConfig with a deep copy of this AuthProviderConfig's values.

type Cluster

type Cluster struct {
	Server                   *string          `yaml:"server,omitempty"                     json:"server,omitempty"                     validate:"required"`
	TLSServerName            *string          `yaml:"tls-server-name,omitempty"            json:"tls-server-name,omitempty"`
	InsecureSkipTLSVerify    *bool            `yaml:"insecure-skip-tls-verify,omitempty"   json:"insecure-skip-tls-verify,omitempty"`
	CertificateAuthorityFile *string          `yaml:"certificate-authority,omitempty"      json:"certificate-authority,omitempty"`
	CertificateAuthorityData *string          `yaml:"certificate-authority-data,omitempty" json:"certificate-authority-data,omitempty"`
	ProxyURL                 *string          `yaml:"proxy-url,omitempty"                  json:"proxy-url,omitempty"`
	DisableCompression       *bool            `yaml:"disable-compression,omitempty"        json:"disable-compression,omitempty"`
	Extensions               []NamedExtension `yaml:"extensions,omitempty"                 json:"extensions,omitempty"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

Cluster describes how to communicate with a Kubernetes cluster.

func (*Cluster) Clone

func (c *Cluster) Clone() *Cluster

Clone creates a deep copy.

func (Cluster) CloneInto

func (c Cluster) CloneInto(target *Cluster)

CloneInto replaces the value of another Cluster with a deep copy of this Cluster's values.

type Config

type Config struct {
	ApiVersion     *string          `yaml:"apiVersion,omitempty"      json:"apiVersion,omitempty"`
	Kind           *string          `yaml:"kind,omitempty"            json:"kind,omitempty"`
	CurrentContext *string          `yaml:"current-context,omitempty" json:"current-context,omitempty" validate:"required"`
	Preferences    *Preferences     `yaml:"preferences,omitempty"     json:"preferences,omitempty"     validate:"required"`
	Clusters       []NamedCluster   `yaml:"clusters,omitempty"        json:"clusters,omitempty"        validate:"required"`
	Contexts       []NamedContext   `yaml:"contexts,omitempty"        json:"contexts,omitempty"        validate:"required"`
	AuthInfos      []NamedAuthInfo  `yaml:"users,omitempty"           json:"users,omitempty"           validate:"required"`
	Extensions     []NamedExtension `yaml:"extensions,omitempty"      json:"extensions,omitempty"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

Config is the root of the kubeconfig file.

See: documentation or kubernetes source

func MergeConfig

func MergeConfig(first, other *Config) *Config

MergeConfig merges two kubeconfig [Config]s together using the same first-definition-wins and never-merge-values rules as kubectl.

REF: https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#merging-kubeconfig-files

func (*Config) Clone

func (c *Config) Clone() *Config

Clone creates a deep copy.

func (Config) CloneInto

func (c Config) CloneInto(target *Config)

CloneInto replaces the value of another Config with a deep copy of this Config's values.

type Context

type Context struct {
	Cluster    *string          `yaml:"cluster,omitempty"    json:"cluster,omitempty"    validate:"required"`
	User       *string          `yaml:"user,omitempty"       json:"user,omitempty"       validate:"required"`
	Namespace  *string          `yaml:"namespace,omitempty"  json:"namespace,omitempty"`
	Extensions []NamedExtension `yaml:"extensions,omitempty" json:"extensions,omitempty"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

Context specifies a NamedCluster to communicate with, a NamedAuthInfo to authenticate with, and a target namespace to work with.

See: documentation or kubernetes source

func (*Context) Clone

func (c *Context) Clone() *Context

Clone creates a deep copy.

func (Context) CloneInto

func (c Context) CloneInto(target *Context)

CloneInto replaces the value of another Context with a deep copy of this Context's values.

type ExecConfig

type ExecConfig struct {
	Command            *string      `yaml:"command,omitempty"             json:"command,omitempty"             validate:"required"`
	Args               []string     `yaml:"args,omitempty"                json:"args,omitempty"`
	Env                []ExecEnvVar `yaml:"env,omitempty"                 json:"env,omitempty"`
	ApiVersion         *string      `yaml:"apiVersion,omitempty"          json:"apiVersion,omitempty"          validate:"required"`
	InstallHint        *string      `yaml:"installHint,omitempty"         json:"installHint,omitempty"         validate:"required"`
	ProvideClusterInfo *bool        `yaml:"providerClusterInfo,omitempty" json:"providerClusterInfo,omitempty" validate:"required"`
	InteractiveMode    *string      `yaml:"interactiveMode,omitempty"     json:"interactiveMode,omitempty"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

ExecConfig describes an external command used for authentication.

See: documentation or kubernetes source

func (*ExecConfig) Clone

func (e *ExecConfig) Clone() *ExecConfig

Clone creates a deep copy.

func (ExecConfig) CloneInto

func (e ExecConfig) CloneInto(target *ExecConfig)

CloneInto replaces the value of another ExecConfig with a deep copy of this ExecConfig's values.

type ExecEnvVar

type ExecEnvVar struct {
	Name  *string `yaml:"name,omitempty"  json:"name,omitempty"  validate:"required"`
	Value *string `yaml:"value,omitempty" json:"value,omitempty" validate:"required"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

ExecEnvVar is an environment variable provided to the external command used for authentication.

See: documentation or kubernetes source

func (*ExecEnvVar) Clone

func (e *ExecEnvVar) Clone() *ExecEnvVar

Clone creates a deep copy.

func (ExecEnvVar) CloneInto

func (e ExecEnvVar) CloneInto(target *ExecEnvVar)

CloneInto replaces the value of another ExecEnvVar with a deep copy of this ExecEnvVar's values.

type Extension

type Extension struct {
	ApiVersion *string `yaml:"apiVersion,omitempty" json:"apiVersion,omitempty"`
	Kind       *string `yaml:"kind,omitempty"       json:"kind,omitempty"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

Extension is a shim implementation of the Kubernetes RawExtension. This contains an `apiVersion` and `kind`, along with unstructured data.

func (*Extension) Clone

func (e *Extension) Clone() *Extension

Clone creates a deep copy.

func (Extension) CloneInto

func (e Extension) CloneInto(target *Extension)

CloneInto replaces the value of another Extension with a deep copy of this Preferences's values.

func (*Extension) Is

func (e *Extension) Is(apiVersion, kind string) bool

Is returns true if the extension matches the provided apiVersion and kind.

func (*Extension) MarshalJSON

func (e *Extension) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

This is needed because `inline` tag isn't supported by `encoding/json` (issue), and we want to at least support decoding extensions properly. When encoding/json/v2 becomes available, that would be preferred over this hack.

func (*Extension) UnmarshalJSON

func (e *Extension) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

This is needed because `inline` tag isn't supported by `encoding/json` (issue), and we want to at least support decoding extensions properly. When encoding/json/v2 becomes available, that would be preferred over this hack.

type NamedAuthInfo

type NamedAuthInfo struct {
	Name *string   `yaml:"name,omitempty" json:"name,omitempty" validate:"required"`
	User *AuthInfo `yaml:"user,omitempty" json:"user,omitempty" validate:"required"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

NamedAuthInfo provides a name for an AuthInfo.

See: documentation or kubernetes source

func (*NamedAuthInfo) Clone

func (n *NamedAuthInfo) Clone() *NamedAuthInfo

Clone creates a deep copy.

func (NamedAuthInfo) CloneInto

func (n NamedAuthInfo) CloneInto(target *NamedAuthInfo)

CloneInto replaces the value of another NamedAuthInfo with a deep copy of this NamedAuthInfo's values.

type NamedCluster

type NamedCluster struct {
	Name    *string  `yaml:"name,omitempty"    json:"name,omitempty"    validate:"required"`
	Cluster *Cluster `yaml:"cluster,omitempty" json:"cluster,omitempty" validate:"required"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

NamedCluster provides a name for a Cluster.

See: documentation or kubernetes source

func (*NamedCluster) Clone

func (n *NamedCluster) Clone() *NamedCluster

Clone creates a deep copy.

func (NamedCluster) CloneInto

func (n NamedCluster) CloneInto(target *NamedCluster)

CloneInto replaces the value of another NamedCluster with a deep copy of this NamedCluster's values.

type NamedContext

type NamedContext struct {
	Name    *string  `yaml:"name,omitempty"    json:"name,omitempty"    validate:"required"`
	Context *Context `yaml:"context,omitempty" json:"context,omitempty" validate:"required"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

NamedContext provides a name for a Context.

See: documentation or kubernetes source

func (*NamedContext) Clone

func (n *NamedContext) Clone() *NamedContext

Clone creates a deep copy.

func (NamedContext) CloneInto

func (n NamedContext) CloneInto(target *NamedContext)

CloneInto replaces the value of another NamedContext with a deep copy of this NamedContext's values.

type NamedExtension

type NamedExtension struct {
	Name      *string    `yaml:"name,omitempty"      json:"name,omitempty"      validate:"required"`
	Extension *Extension `yaml:"extension,omitempty" json:"extension,omitempty" validate:"required"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

NamedExtension provides a name for an Extension.

See: documentation or kubernetes source

func (*NamedExtension) Clone

func (n *NamedExtension) Clone() *NamedExtension

Clone creates a deep copy.

func (NamedExtension) CloneInto

func (n NamedExtension) CloneInto(target *NamedExtension)

CloneInto replaces the value of another NamedExtension with a deep copy of this NamedExtension's values.

type Preferences deprecated

type Preferences struct {
	Colors     *bool            `yaml:"colors,omitempty"     json:"colors,omitempty"`
	Extensions []NamedExtension `yaml:"extensions,omitempty" json:"extensions,omitempty"`

	// Remaining contains any remaining unknown fields.
	Remaining map[string]any `yaml:",inline,omitempty" json:",inline,omitempty"`
}

Preferences specifies kubecli client preferences.

See: documentation or kubernetes source

Deprecated: Replaced by kuberc in Kubernetes 1.33, KEP-3104 (proposal, tracker)

func (*Preferences) Clone

func (p *Preferences) Clone() *Preferences

Clone creates a deep copy.

func (Preferences) CloneInto

func (p Preferences) CloneInto(target *Preferences)

CloneInto replaces the value of another Preferences with a deep copy of this Preferences's values.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL