Documentation
¶
Overview ¶
Package kubeconfig writes one cluster, user and context into a kubeconfig file and reads them back. It edits the parsed YAML tree rather than a decoded struct, so entries, keys and comments it does not own survive the rewrite.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLocked marks a kubeconfig another process holds the write lock on. ErrLocked = errors.New("kubeconfig is locked") // ErrMalformed marks a kubeconfig whose shape this package refuses to edit. ErrMalformed = errors.New("unsupported kubeconfig") // ErrContextNotFound and ErrClusterNotFound mark a Lookup miss. ErrContextNotFound = errors.New("context not found") ErrClusterNotFound = errors.New("cluster not found") )
Functions ¶
func Lookup ¶
Lookup returns the server and proxy-url of the cluster that contextName points at, merging paths the way kubectl does: each name is taken from the first file that defines it, a missing file is skipped, and a malformed one fails the whole lookup. A context found nowhere wraps ErrContextNotFound; a cluster found nowhere wraps ErrClusterNotFound.
func ReadByDefault ¶
ReadByDefault reports whether kubectl, run without --kubeconfig, reads path.
func ResolvePath ¶
ResolvePath picks the file 'kubectl config' itself would write to: the explicit path when one is given, then the first $KUBECONFIG entry that exists, else the last entry listed, and <home>/.kube/config when $KUBECONFIG names nothing.
func SearchPaths ¶
SearchPaths returns the files kubectl reads, in the order it merges them: the explicit path alone when one is given, else every $KUBECONFIG entry, else <home>/.kube/config. A $KUBECONFIG that is set but names no file is an error: kubectl then reads nothing and does not fall back to the home file.
Types ¶
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor holds a kubeconfig's write lock and its parsed contents between Open and Save, so a file that cannot be edited is found out before anything is created for it.
func Open ¶
Open takes kubectl's write lock on path (<path>.lock, created exclusively, so a kubectl editing the file at the same time and this command exclude each other), then reads and checks the file. A missing, empty or comment-only file opens as a fresh config. Close must be called on the returned Editor.
func (*Editor) Apply ¶
Apply writes e into the parsed file. It returns the current-context it replaced (which may equal e.Name), and the host of the cluster's previous server when that differs from e.Server's, so the caller can say another endpoint's entry was overwritten. Nothing reaches disk until Save.