Skip to content

Commit

Permalink
Merge pull request #230 from openshift/revert-211-new-shell-elevate
Browse files Browse the repository at this point in the history
Revert "OSD-18058 : Adding a new interactive shell session when we do debug with elevate command "
  • Loading branch information
openshift-ci[bot] authored Oct 18, 2023
2 parents 9a80b11 + 0fefbf2 commit 3ec5991
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
13 changes: 2 additions & 11 deletions pkg/elevate/elevate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"os/exec"
"strings"

logger "github.com/sirupsen/logrus"
"k8s.io/client-go/tools/clientcmd/api"
Expand Down Expand Up @@ -62,19 +61,12 @@ func RunElevate(argv []string) error {

logger.Debug("Adding impersonation RBAC allow permissions to kubeconfig")

elevateCmd := "oc " + strings.Join(argv[1:], " ")

shell := "/bin/bash"

if len(argv) > 3 {
shell = argv[4]
}
elevateCmd := argv[1:]

logger.Debugln("Executing command with temporary kubeconfig as backplane-cluster-admin")
ocCmd := ExecCmd("oc", elevateCmd...)

ocCmd := ExecCmd(shell, "-c", elevateCmd)
ocCmd.Env = append(ocCmd.Env, os.Environ()...)
ocCmd.Stdin = os.Stdin
ocCmd.Stderr = os.Stderr
ocCmd.Stdout = os.Stdout

Expand All @@ -83,7 +75,6 @@ func RunElevate(argv []string) error {
}

err = ocCmd.Run()

kubeconfigPath, _ := os.LookupEnv("KUBECONFIG")
defer func() {
logger.Debugln("Command error; Cleaning up temporary kubeconfig")
Expand Down
6 changes: 3 additions & 3 deletions pkg/elevate/elevate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestAddElevationReasonToRawKubeconfig(t *testing.T) {
}

func TestRunElevate(t *testing.T) {
t.Run("It returns an error if we cannot load the kubeconfig", func(t *testing.T) {
t.Run("It errors if we cannot load the kubeconfig", func(t *testing.T) {
ExecCmd = exec.Command
OsRemove = os.Remove
ReadKubeConfigRaw = func() (api.Config, error) {
Expand All @@ -120,7 +120,7 @@ func TestRunElevate(t *testing.T) {
}
})

t.Run("It returns an error if kubeconfig has no current context", func(t *testing.T) {
t.Run("It errors if kubeconfig has no current context", func(t *testing.T) {
ExecCmd = exec.Command
OsRemove = os.Remove
ReadKubeConfigRaw = func() (api.Config, error) {
Expand All @@ -131,7 +131,7 @@ func TestRunElevate(t *testing.T) {
}
})

t.Run("It returns an error if the exec command has errors", func(t *testing.T) {
t.Run("It errors if the exec command errors", func(t *testing.T) {
ExecCmd = fakeExecCommandError
OsRemove = os.Remove
ReadKubeConfigRaw = func() (api.Config, error) {
Expand Down

0 comments on commit 3ec5991

Please sign in to comment.