Skip to content

Commit

Permalink
fix: unexpected error for incorrect kubectl command (#67)
Browse files Browse the repository at this point in the history
Closes #46 

Signed-off-by: sharan <[email protected]>
  • Loading branch information
rustiever authored Nov 6, 2023
1 parent 3a1ed71 commit 9d66076
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/kube/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
var _log = logv2.GetLogger()

func isInteractive(s string) bool {

switch {
case strings.Index(s, "exec") >= 0:
case strings.Index(s, "logs") >= 0:
Expand Down Expand Up @@ -50,13 +49,16 @@ func NewIOExecutor(rw io.ReadWriter, rows, cols uint16, args []string, event *au
}

var execArgs []string
for _, arg := range args {

// appending kubectl commands to execute
for _, arg := range strings.Split(s, " ") {
if strings.TrimSpace(arg) != "" {
execArgs = append(execArgs, arg)
}
}

for _, arg := range strings.Split(s, " ") {
// appending default flags to execArgs
for _, arg := range args {
if strings.TrimSpace(arg) != "" {
execArgs = append(execArgs, arg)
}
Expand All @@ -70,7 +72,6 @@ func NewIOExecutor(rw io.ReadWriter, rows, cols uint16, args []string, event *au
cmd.Env = append(cmd.Env, "KUBE_EDITOR=vim")

f, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: rows, Cols: cols})

if err != nil {
rw.Write([]byte(err.Error()))
rw.Write([]byte{'\r', '\n'})
Expand Down Expand Up @@ -99,7 +100,7 @@ func NewIOExecutor(rw io.ReadWriter, rows, cols uint16, args []string, event *au

_log.Debugw("executing non interative kubectl", "args", execArgs)

if len(execArgs) > 3 && execArgs[2] == "config" {
if len(execArgs) > 3 && execArgs[0] == "config" {
// filter raw/flattern argument to avoid displaying cert data
for _, s := range execArgs {
if s == "--raw" || s == "--flatten" {
Expand Down

0 comments on commit 9d66076

Please sign in to comment.