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 pods
32 lines
567 B
Go
32 lines
567 B
Go
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()
|
|
}
|