Skip to content

Commit

Permalink
fix: print version without config (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp authored Feb 21, 2020
1 parent 6bcb55d commit 4dceb78
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
29 changes: 5 additions & 24 deletions cmd/vela-kubernetes/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
11 changes: 1 addition & 10 deletions cmd/vela-kubernetes/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package main

import (
"fmt"
"os/exec"
"reflect"
"testing"
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/vela-kubernetes/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 4dceb78

Please sign in to comment.