From 5fa1e9d1bed10d710ea7829ecb96f47f71871f75 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Tue, 28 May 2019 00:44:22 +0200 Subject: [PATCH 1/2] Add environment variables to cluster shell --- internal/cli/command/cluster/legacy.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/cli/command/cluster/legacy.go b/internal/cli/command/cluster/legacy.go index 8427ecc5..c75d3084 100644 --- a/internal/cli/command/cluster/legacy.go +++ b/internal/cli/command/cluster/legacy.go @@ -214,11 +214,24 @@ func ClusterShell(cmd *cobra.Command, args []string) { commandArgs = args[1:] } + org, _, err := pipeline.OrganizationsApi.GetOrg(context.Background(), orgId) + if err != nil { + log.Fatalf("could not get organization: %v", err) + } + log.Printf("Running %v %v", shell, strings.Join(args, " ")) c := exec.Command(shell, commandArgs...) c.Stdin = os.Stdin c.Stdout = os.Stdout c.Stderr = os.Stderr + c.Env = append( + os.Environ(), + fmt.Sprintf("BANZAI_CURRENT_ORG_ID=%d", orgId), + fmt.Sprintf("BANZAI_CURRENT_ORG_NAME=%s", org.Name), + fmt.Sprintf("BANZAI_CURRENT_CLUSTER_ID=%d", id), + fmt.Sprintf("BANZAI_CURRENT_CLUSTER_NAME=%s", cluster.Name), + ) + if err := c.Run(); err != nil { log.Errorf("Failed to run command: %v", err) } From 1114cb6edc35409693b0ce2d3de91b0082902e1e Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Tue, 28 May 2019 01:49:03 +0200 Subject: [PATCH 2/2] Pass kubeconfig environment to process --- internal/cli/command/cluster/legacy.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/cli/command/cluster/legacy.go b/internal/cli/command/cluster/legacy.go index c75d3084..7d3b644a 100644 --- a/internal/cli/command/cluster/legacy.go +++ b/internal/cli/command/cluster/legacy.go @@ -184,11 +184,6 @@ func ClusterShell(cmd *cobra.Command, args []string) { log.Fatalf("could not close temporary file: %v", err) } - // customize shell prompt - os.Setenv("PS1", fmt.Sprintf("[%s]$ ", chalk.Bold.TextStyle(cluster.Name))) - // export the temporary config file's name for k8s commands - os.Setenv("KUBECONFIG", tmpfile.Name()) - var commandArgs []string shell := os.Getenv("SHELL") if shell == "" { @@ -226,6 +221,12 @@ func ClusterShell(cmd *cobra.Command, args []string) { c.Stderr = os.Stderr c.Env = append( os.Environ(), + // customize shell prompt + fmt.Sprintf("PS1=[%s]$ ", chalk.Bold.TextStyle(cluster.Name)), + + // export the temporary config file's name for k8s commands + fmt.Sprintf("KUBECONFIG=%s", tmpfile.Name()), + fmt.Sprintf("BANZAI_CURRENT_ORG_ID=%d", orgId), fmt.Sprintf("BANZAI_CURRENT_ORG_NAME=%s", org.Name), fmt.Sprintf("BANZAI_CURRENT_CLUSTER_ID=%d", id),