mirror of https://github.com/k3d-io/k3d
Add the basic frame work for supporting spawning a bash shell by cli command. With this change, we can spawn a bash shell in the context of a cluster $ k3d create -n my-cluster $ k3d bash -n my-cluster [my-cluster] $> // execute commands with KUBECONFIG already set up [my-cluster] $> kubectl get podspull/66/head
parent
9f276a68f3
commit
4ef6710e22
@ -0,0 +1,31 @@ |
||||
package run |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
"os/exec" |
||||
) |
||||
|
||||
func bashShell(cluster string) error { |
||||
kubeConfigPath, err := getKubeConfig(cluster) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
cmd := exec.Command("/bin/bash", "--noprofile", "--norc") |
||||
|
||||
// Set up stdio
|
||||
cmd.Stdout = os.Stdout |
||||
cmd.Stdin = os.Stdin |
||||
cmd.Stderr = os.Stderr |
||||
|
||||
// Set up Promot
|
||||
setPS1 := fmt.Sprintf("PS1=[%s}%s", cluster, os.Getenv("PS1")) |
||||
|
||||
// Set up KUBECONFIG
|
||||
setKube := fmt.Sprintf("KUBECONFIG=%s", kubeConfigPath) |
||||
newEnv := append(os.Environ(), setPS1, setKube) |
||||
|
||||
cmd.Env = newEnv |
||||
|
||||
return cmd.Run() |
||||
} |
Loading…
Reference in new issue