kubeconfig

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExpirationFlag     = "expiration"
	DisableWritingFlag = "disable-writing"
	FilepathFlag       = "filepath"
	OverwriteFlag      = "overwrite"
	SwitchContextFlag  = "switch-context"
)

User input flags for kubeconfig commands

View Source
const (
	ExpirationUsage     = "Expiration time for the kubeconfig, e.g. 5d. By default, the token is valid for 1h."
	FilepathUsage       = "Path to the kubeconfig file. A default is chosen by Kubernetes if not set."
	DisableWritingUsage = "Disable writing the kubeconfig to a file."
	OverwriteUsage      = "Force overwrite the kubeconfig file if it exists."
	SwitchContextUsage  = "Switch to the context in the kubeconfig file to the new context."
)

Flag usage texts

View Source
const (
	ExpirationShorthand     = "e"
	DisableWritingShorthand = ""
	FilepathShorthand       = "f"
	OverwriteShorthand      = ""
	SwitchContextShorthand  = ""
)

Flag shorthands

View Source
const (
	ExpirationSecondsDefault = 3600 // 60 * 60 seconds = 1 hour
)

Defaults taken from OpenApi spec.

Variables

This section is empty.

Functions

func ValidateExpiration

func ValidateExpiration(expiration *uint64) error

func WriteKubeconfig

func WriteKubeconfig(filePath *string, kubeconfig string, options WriteOptions) (*string, error)

WriteKubeconfig writes the provided kubeconfig data to a file on the filesystem. By default, if the file already exists, it will be merged with the provided data. This behavior can be controlled using the provided options.

The function takes the following parameters:

  • filePath: The path to the destination file. The file and the directory tree for the file will be created if it does not exist. If nil, the default kubeconfig path is used.
  • kubeconfig: The kubeconfig content to write.
  • options: Options for controlling the write behavior.

It returns the file path actually used to write to on success.

Types

type ConfirmationCallback

type ConfirmationCallback func(message string) error

ConfirmationCallback is a function that prompts for confirmation with the given message and returns true if confirmed, false otherwise

type EmptyKubeconfigError

type EmptyKubeconfigError struct{}

EmptyKubeconfigError is returned when the kubeconfig content is empty.

func (*EmptyKubeconfigError) Error

func (e *EmptyKubeconfigError) Error() string

Error returns the error message.

type InvalidKubeconfigPathError

type InvalidKubeconfigPathError struct {
	Path string
}

InvalidKubeconfigPathError is returned when an invalid kubeconfig path is provided.

func (*InvalidKubeconfigPathError) Error

Error returns the error message.

type LoadKubeconfigError

type LoadKubeconfigError struct {
	Err error
}

LoadKubeconfigError is returned when loading the kubeconfig fails.

func (*LoadKubeconfigError) Error

func (e *LoadKubeconfigError) Error() string

Error returns the error message.

func (*LoadKubeconfigError) Unwrap

func (e *LoadKubeconfigError) Unwrap() error

Unwrap returns the underlying error.

type WriteKubeconfigError

type WriteKubeconfigError struct {
	Err error
}

WriteKubeconfigError is returned when writing the kubeconfig fails.

func (*WriteKubeconfigError) Error

func (e *WriteKubeconfigError) Error() string

Error returns the error message.

func (*WriteKubeconfigError) Unwrap

func (e *WriteKubeconfigError) Unwrap() error

Unwrap returns the underlying error.

type WriteOptions

type WriteOptions struct {
	Overwrite     bool
	SwitchContext bool
	ConfirmFn     ConfirmationCallback
}

WriteOptions contains options for writing kubeconfig files

func NewWriteOptions

func NewWriteOptions() WriteOptions

NewWriteOptions creates a new WriteOptions with default values

func (WriteOptions) WithConfirmation

func (w WriteOptions) WithConfirmation(fn ConfirmationCallback) WriteOptions

WithConfirmation sets the confirmation callback function

func (WriteOptions) WithOverwrite

func (w WriteOptions) WithOverwrite(overwrite bool) WriteOptions

WithOverwrite sets whether to overwrite existing files instead of merging

func (WriteOptions) WithSwitchContext

func (w WriteOptions) WithSwitchContext(switchContext bool) WriteOptions

WithSwitchContext sets whether to switch to the new context after writing

Jump to

Keyboard shortcuts

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