aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorStefan Majewsky <stefan.majewsky@sap.com>2020-11-27 15:19:24 +0100
committerStefan Majewsky <stefan.majewsky@sap.com>2020-11-27 15:19:24 +0100
commita0e3def20e355054baa93cff5e3b5d8f5de205a4 (patch)
tree2c95e636c478e7c670f15b3a308c4030a97a5d0b /internal
parente962f86b50215af4486bd73155c603e715ce1ab1 (diff)
downloadgofu-a0e3def20e355054baa93cff5e3b5d8f5de205a4.tar.gz
prettyprompt: support u8s
Diffstat (limited to 'internal')
-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 == "" {