From 4dceb78de16e9e340495586deb2b8ff92de0bd20 Mon Sep 17 00:00:00 2001 From: Jordan Brockopp Date: Fri, 21 Feb 2020 15:07:20 -0600 Subject: [PATCH] fix: print version without config (#31) --- cmd/vela-kubernetes/command.go | 29 +++++------------------------ cmd/vela-kubernetes/command_test.go | 11 +---------- cmd/vela-kubernetes/plugin.go | 2 +- 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/cmd/vela-kubernetes/command.go b/cmd/vela-kubernetes/command.go index 737673d..319a791 100644 --- a/cmd/vela-kubernetes/command.go +++ b/cmd/vela-kubernetes/command.go @@ -32,28 +32,9 @@ func execCmd(e *exec.Cmd) error { } // versionCmd is a helper function to output -// the client and server version information -// for the configured context. -func versionCmd(c *Config) *exec.Cmd { - logrus.Trace("creating kubectl version command from plugin configuration") - - // variable to store flags for command - var flags []string - - // check if config namespace is provided - if len(c.Namespace) > 0 { - // add flag for namespace from provided config namespace - flags = append(flags, fmt.Sprintf("--namespace=%s", c.Namespace)) - } - - // check if config context is provided - if len(c.Context) > 0 { - // add flag for context from provided config context - flags = append(flags, fmt.Sprintf("--context=%s", c.Context)) - } - - // add flag for version kubectl command - flags = append(flags, "version") - - return exec.Command(kubectlBin, flags...) +// the client and server version information. +func versionCmd() *exec.Cmd { + logrus.Trace("creating kubectl version command") + + return exec.Command(kubectlBin, "version") } diff --git a/cmd/vela-kubernetes/command_test.go b/cmd/vela-kubernetes/command_test.go index 89001f4..142ba44 100644 --- a/cmd/vela-kubernetes/command_test.go +++ b/cmd/vela-kubernetes/command_test.go @@ -5,7 +5,6 @@ package main import ( - "fmt" "os/exec" "reflect" "testing" @@ -23,20 +22,12 @@ func TestKubernetes_execCmd(t *testing.T) { func TestKubernetes_versionCmd(t *testing.T) { // setup types - c := &Config{ - File: "file", - Context: "context", - Namespace: "namespace", - } - want := exec.Command( kubectlBin, - fmt.Sprintf("--namespace=%s", c.Namespace), - fmt.Sprintf("--context=%s", c.Context), "version", ) - got := versionCmd(c) + got := versionCmd() if !reflect.DeepEqual(got, want) { t.Errorf("versionCmd is %v, want %v", got, want) diff --git a/cmd/vela-kubernetes/plugin.go b/cmd/vela-kubernetes/plugin.go index eea3d92..94732fd 100644 --- a/cmd/vela-kubernetes/plugin.go +++ b/cmd/vela-kubernetes/plugin.go @@ -40,7 +40,7 @@ func (p *Plugin) Exec() error { } // output kubectl version for troubleshooting - err = execCmd(versionCmd(p.Config)) + err = execCmd(versionCmd()) if err != nil { return err }