Documentation
¶
Index ¶
- Variables
- type Config
- func (c *Config) CreateListItems(filterConfig, filterContext string) []ContextItem
- func (c *Config) GetContextBy(name string) (*KubeConf, map[string]string, int)
- func (c *Config) GetKubeConfigBy(path string) *KubeConf
- func (c *Config) GetState() error
- func (c *Config) RemoveCurrentContexts() error
- func (c *Config) SyncNamespaces() error
- func (c *Config) UpdateState(k *KubeConf, currentContext string) error
- type Context
- type ContextItem
- type KubeConf
- type KubeConfig
- func (k *KubeConfig) AddNamespaceTo(contextName, namespace string) error
- func (k *KubeConfig) GetContextBy(name string) (*KubeContext, int, error)
- func (k *KubeConfig) GetContextNames() (names []string)
- func (k *KubeConfig) Read() error
- func (k *KubeConfig) RemoveCurrentContext() error
- func (k *KubeConfig) SaveContexts() error
- func (k *KubeConfig) SetContextTo(contextName string) error
- func (k *KubeConfig) SyncContexts(c *KubeConf) error
- type KubeConfigs
- type KubeContext
- type State
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Dir of the config files
Dir string
// GlobalConfig holds the jsonnet file path of the context config
GlobalConfig string
// KubeConfs is list of kube config items. With allows you to
// handle multiple kube configs with a single "GlobalConfig".
KubeConfs []*KubeConf `json:"kube_configs"`
// State contains the name of the state file
// LastConf, CurrentContext and LastContext
*State `json:"state"`
}
Config is the main struct, which is generated from the config file and holds one or more kube configs.
func Get ¶
Get reads the config.jsonnet file and the bound kube config files. In addition, if not exist, it creates the contexts and state files.
func (*Config) CreateListItems ¶
func (c *Config) CreateListItems(filterConfig, filterContext string) []ContextItem
CreateListItems is a helper function for the TUI and creates the list of context names and a description.
func (*Config) GetContextBy ¶
GetContextBy takes a name or alias of the desired context as argument and returns the KubeConf, the context and its index.
func (*Config) GetKubeConfigBy ¶
GetKubeConfigBy returns the KubeConf by a given path.
func (*Config) GetState ¶
GetState stores the current state file content into the config. It returns ErrReadStateFile or ErrReadStateFile if the .state file cannot be read or parsed.
func (*Config) RemoveCurrentContexts ¶
RemoveCurrentContexts removes from every kube config the setting for the currentContext.
func (*Config) SyncNamespaces ¶
SyncNamespaces loops over the KubeConf and runs in turn the SyncNamespaces for every kube config.
type Context ¶
type Context struct {
Cluster string `yaml:"cluster"`
User string `yaml:"user"`
Namespace string `yaml:"namespace,omitempty"`
}
Context item.
type ContextItem ¶
ContextItem is used in the "list" Model in the cmd/ktx.
type KubeConf ¶
type KubeConf struct {
// Path of the kube config file
Path string `json:"path"`
// Alias the kube config file
Alias string `json:"alias"`
// ContextFile holds the path of the context file in yaml format
ContextFile string `json:"context_file"`
// Contexts will be synced with the kube config file
// and extended by the GlobalConfig file
Contexts []map[string]string `json:"contexts"`
// KubeConfig holds the kube config file content
KubeConfig *KubeConfig `json:"-"`
}
KubeConf stores the content of a single kube config file.
func (*KubeConf) GetContextBy ¶
GetContextBy returns the context and its index within a single KubeConf given by name.
func (*KubeConf) Save ¶
Save writes the contexts stored in a KubeConfig into a contexts_<alias>.yaml file.
func (*KubeConf) SyncNamespaces ¶
SyncNamespaces loops over the contexts and updates the namespace in the underlying kube config file.
type KubeConfig ¶
type KubeConfig struct {
// Path holds the file path of the kube config.
Path string `yaml:"-"`
// APIVersion comes from the underlying K8s Kube Config specs.
APIVersion string `yaml:"apiVersion"`
// Kind comes from the underlying K8s Kube Config specs.
Kind string `yaml:"kind"`
// Preferences comes from the underlying K8s Kube Config specs.
Preferences interface{} `yaml:"preferences"`
// Contexts comes from the underlying K8s Kube Config specs and will be
// next to the CurrentContext interesting part for us.
Contexts []KubeContext `yaml:"contexts"`
// CurrentContext contains the desired context name.
CurrentContext string `yaml:"current-context"`
// Clusters comes from the underlying K8s Kube Config specs.
Clusters []struct {
Name string `yaml:"name"`
Cluster interface{} `yaml:"cluster"`
} `yaml:"clusters"`
// Users comes from the underlying K8s Kube Config specs.
Users []struct {
Name string `yaml:"name"`
User interface{} `yaml:"user"`
} `yaml:"users"`
}
KubeConfig holds the content of the kube config file.
func GetKubeConfig ¶
func GetKubeConfig(kubeconfig string) (*KubeConfig, error)
func (*KubeConfig) AddNamespaceTo ¶
func (k *KubeConfig) AddNamespaceTo(contextName, namespace string) error
func (*KubeConfig) GetContextBy ¶
func (k *KubeConfig) GetContextBy(name string) (*KubeContext, int, error)
GetContextBy returns the kube context by a given name
func (*KubeConfig) GetContextNames ¶
func (k *KubeConfig) GetContextNames() (names []string)
GetProfilesNames returns all context names
func (*KubeConfig) Read ¶
func (k *KubeConfig) Read() error
func (*KubeConfig) RemoveCurrentContext ¶
func (k *KubeConfig) RemoveCurrentContext() error
func (*KubeConfig) SaveContexts ¶
func (k *KubeConfig) SaveContexts() error
func (*KubeConfig) SetContextTo ¶
func (k *KubeConfig) SetContextTo(contextName string) error
func (*KubeConfig) SyncContexts ¶
func (k *KubeConfig) SyncContexts(c *KubeConf) error
type KubeConfigs ¶
type KubeConfigs []KubeConfig
type KubeContext ¶
KubeContext holds a single context.
type State ¶
type State struct {
// Filename of the state file
Filename string `yaml:"filename"`
// CurrentConf holds the name of the curently used kube config. This
// is used to jump back via "-" argument of the ktx cli command.
CurrentConf string `yaml:"currentKubeConfig"`
// LastConf stores the name of the previous used kube config. This
// is used to jump back via "-" argument of the ktx cli command.
LastConf string `yaml:"lastKubeConfig"`
// CurrentContext stores the name of the currently used Kubernetes context.
CurrentContext string `yaml:"currentContext"`
// LastContext together with LastConf will be used to switch between
// two contexts.
LastContext string `yaml:"lastContext"`
}
State is used to switch back to the previous contexts.



