aboutsummaryrefslogtreecommitdiff
path: root/internal/prompt/cloud.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/prompt/cloud.go')
-rw-r--r--internal/prompt/cloud.go40
1 files changed, 39 insertions, 1 deletions
diff --git a/internal/prompt/cloud.go b/internal/prompt/cloud.go
index 72bd6f9..807d2e2 100644
--- a/internal/prompt/cloud.go
+++ b/internal/prompt/cloud.go
@@ -1,6 +1,6 @@
/*******************************************************************************
*
-* Copyright 2017 Stefan Majewsky <majewsky@gmx.net>
+* Copyright 2017-2020 Stefan Majewsky <majewsky@gmx.net>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
@@ -21,6 +21,7 @@ package prompt
import (
"io/ioutil"
"os"
+ "os/exec"
"path/filepath"
"strings"
@@ -28,6 +29,11 @@ import (
)
func getKubernetesField() string {
+ _, err := os.Stat("/x/bin/u8s")
+ if err == nil {
+ return getKubernetesFieldViaU8S()
+ }
+
configPaths := filepath.SplitList(os.Getenv("KUBECONFIG"))
var context string
@@ -74,6 +80,38 @@ func getKubernetesContext(configPath string) string {
return strings.TrimSpace(data.CurrentContext)
}
+func getKubernetesFieldViaU8S() string {
+ stdout, err := exec.Command("u8s", "env").Output()
+ if err != nil {
+ return ""
+ }
+
+ var (
+ context string
+ namespace string
+ )
+ for _, line := range strings.Split(string(stdout), "\n") {
+ fields := strings.SplitN(strings.TrimSpace(line), "=", 2)
+ if len(fields) != 2 {
+ continue
+ }
+ switch fields[0] {
+ case "U8S_CONTEXT":
+ context = fields[1]
+ case "U8S_NAMESPACE":
+ namespace = fields[1]
+ }
+ }
+
+ if context == "" {
+ return ""
+ }
+ if namespace != "" {
+ context += "/" + namespace
+ }
+ return withType("kube", context)
+}
+
func getOpenstackField() string {
cloudName := os.Getenv("CURRENT_OS_CLOUD")
if cloudName == "" {