-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
37 lines (33 loc) · 891 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main // import "github.com/marcsauter/kube-tmux"
import (
"os"
"text/template"
"k8s.io/client-go/tools/clientcmd"
)
const (
defaultNamespace = "default"
)
func main() {
format := "[{{.Context}}/{{.Namespace}}]"
if len(os.Args) > 1 {
format = os.Args[1]
}
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
configOverrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
config, err := kubeConfig.RawConfig()
if err != nil {
os.Exit(1)
}
currentContext := config.CurrentContext
currentNamespace := config.Contexts[currentContext].Namespace
if currentNamespace == "" {
currentNamespace = defaultNamespace
}
template.Must(template.New("tmux").Parse(format)).Execute(os.Stdout, struct {
Context, Namespace string
}{
currentContext,
currentNamespace,
})
}