Block recursive bash invocation
In theory, we can execute 'k3d bash' again within an cluster shell. I can't think of any practical value for allowing this capability. On the contrary, this can lead to confusion to the user. This patch adds a simple mechanism to detect and block recursive bash invocation.
This commit is contained in:
parent
2971dd6845
commit
8aaf70f4bf
11
cli/shell.go
11
cli/shell.go
@ -12,6 +12,11 @@ func bashShell(cluster string, command string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subShell := os.ExpandEnv("$__K3D_CLUSTER__")
|
||||||
|
if len(subShell) > 0 {
|
||||||
|
return fmt.Errorf("Error: Already in subshell of cluster %s", subShell)
|
||||||
|
}
|
||||||
|
|
||||||
bashPath, err := exec.LookPath("bash")
|
bashPath, err := exec.LookPath("bash")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -34,7 +39,11 @@ func bashShell(cluster string, command string) error {
|
|||||||
|
|
||||||
// Set up KUBECONFIG
|
// Set up KUBECONFIG
|
||||||
setKube := fmt.Sprintf("KUBECONFIG=%s", kubeConfigPath)
|
setKube := fmt.Sprintf("KUBECONFIG=%s", kubeConfigPath)
|
||||||
newEnv := append(os.Environ(), setPS1, setKube)
|
|
||||||
|
// Declare subshell
|
||||||
|
subShell = fmt.Sprintf("__K3D_CLUSTER__=%s", cluster)
|
||||||
|
|
||||||
|
newEnv := append(os.Environ(), setPS1, setKube, subShell)
|
||||||
|
|
||||||
cmd.Env = newEnv
|
cmd.Env = newEnv
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user