Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Cmd = &Z.Cmd{ Name: `kube`, Summary: `({{.Version}}) Kubernetes utility commands`, Version: `v0.1.0`, Copyright: `Copyright 2021 Robert S Muhlestein`, License: `Apache-2.0`, Source: `git@github.com:rwxrob/kube.git`, Issues: `github.com/rwxrob/kube/issues`, Commands: []*Z.Cmd{help.Cmd, contextCmd}, MinArgs: 1, Description: ` The {{cmd .Name}} commands provide user-centric utilities and tools for working with Kubernetes clusters and applications. `, }
Functions ¶
func CurrentContext ¶
func CurrentContext() string
CurrentContext first loads the kubeconfig (see Config.Load) and then returns the current-context value or empty string if not found.
Example ¶
package main import ( "fmt" "log" "os" "path/filepath" "strings" "github.com/rwxrob/kube" ) func main() { path := []string{ filepath.Join(`testdata`, `conf1.yaml`), filepath.Join(`testdata`, `conf2.yaml`), } pathstr := strings.Join(path, string(filepath.ListSeparator)) log.Println(pathstr) orig := os.Getenv(`KUBECONFIG`) os.Setenv(`KUBECONFIG`, pathstr) defer func() { if orig != "" { os.Setenv(`KUBECONFIG`, orig) } }() fmt.Println(kube.CurrentContext()) }
Output: foo
func DefConfFile ¶
func DefConfFile() string
DefConfFile returns the full path to the default config file depending on the OS. Returns empty if nothing found.
Types ¶
type Config ¶
func (*Config) Load ¶
Load follows the same conventions as kubectl for loading Kubernetes configuration YAML data, first from all files in any KUBECONFIG environment variable path are loaded with the values of the last file having priority over those before it. If KUBECONFIG is not set or empty then .kube/config file in the users' home directory is loaded instead. Any files that do not exist are silently ignored.
Example (Kubeconfig) ¶
package main import ( "fmt" "log" "os" "path/filepath" "strings" "github.com/rwxrob/kube" ) func main() { path := []string{ filepath.Join(`testdata`, `conf1.yaml`), filepath.Join(`testdata`, `conf2.yaml`), } pathstr := strings.Join(path, string(filepath.ListSeparator)) log.Println(pathstr) orig := os.Getenv(`KUBECONFIG`) os.Setenv(`KUBECONFIG`, pathstr) defer func() { if orig != "" { os.Setenv(`KUBECONFIG`, orig) } }() c := kube.Config{} c.Load() fmt.Println(c.O[`current-context`]) }
Output: foo
Click to show internal directories.
Click to hide internal directories.