From 9d660763123abd23ecd62f3e73643b9d1ef4519b Mon Sep 17 00:00:00 2001 From: Sharan Date: Mon, 6 Nov 2023 11:03:02 +0530 Subject: [PATCH] fix: unexpected error for incorrect kubectl command (#67) Closes #46 Signed-off-by: sharan --- pkg/kube/executor.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/kube/executor.go b/pkg/kube/executor.go index 25e5a59..98407cd 100644 --- a/pkg/kube/executor.go +++ b/pkg/kube/executor.go @@ -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: @@ -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) } @@ -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'}) @@ -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" {