mirror of https://github.com/helm/helm
Merge pull request #616 from adamreese/ref/remove-kubectl
ref(init): refactor init command to use kube clientpull/618/head
commit
f3b225fe3a
@ -1,32 +0,0 @@
|
|||||||
package kubectl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type cmd struct {
|
|
||||||
*exec.Cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
func command(args ...string) *cmd {
|
|
||||||
return &cmd{exec.Command(Path, args...)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func assignStdin(cmd *cmd, in []byte) {
|
|
||||||
cmd.Stdin = bytes.NewBuffer(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cmd) String() string {
|
|
||||||
var stdin string
|
|
||||||
|
|
||||||
if c.Stdin != nil {
|
|
||||||
b, _ := ioutil.ReadAll(c.Stdin)
|
|
||||||
stdin = fmt.Sprintf("< %s", string(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("[CMD] %s %s", strings.Join(c.Args, " "), stdin)
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package kubectl
|
|
||||||
|
|
||||||
// Create uploads a chart to Kubernetes
|
|
||||||
func (r RealRunner) Create(stdin []byte) ([]byte, error) {
|
|
||||||
args := []string{"create", "-f", "-"}
|
|
||||||
|
|
||||||
cmd := command(args...)
|
|
||||||
assignStdin(cmd, stdin)
|
|
||||||
|
|
||||||
return cmd.CombinedOutput()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create returns the commands to kubectl
|
|
||||||
func (r PrintRunner) Create(stdin []byte) ([]byte, error) {
|
|
||||||
args := []string{"create", "-f", "-"}
|
|
||||||
|
|
||||||
cmd := command(args...)
|
|
||||||
assignStdin(cmd, stdin)
|
|
||||||
|
|
||||||
return []byte(cmd.String()), nil
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package kubectl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestPrintCreate(t *testing.T) {
|
|
||||||
var client Runner = PrintRunner{}
|
|
||||||
|
|
||||||
expected := `[CMD] kubectl create -f - < some stdin data`
|
|
||||||
|
|
||||||
out, err := client.Create([]byte("some stdin data"))
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
actual := string(out)
|
|
||||||
|
|
||||||
if expected != actual {
|
|
||||||
t.Fatalf("actual %s != expected %s", actual, expected)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package kubectl
|
|
||||||
|
|
||||||
// Path is the path of the kubectl binary
|
|
||||||
var Path = "kubectl"
|
|
||||||
|
|
||||||
// Runner is an interface to wrap kubectl convenience methods
|
|
||||||
type Runner interface {
|
|
||||||
// Create uploads a chart to Kubernetes
|
|
||||||
Create(stdin []byte) ([]byte, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RealRunner implements Runner to execute kubectl commands
|
|
||||||
type RealRunner struct{}
|
|
||||||
|
|
||||||
// PrintRunner implements Runner to return a []byte of the command to be executed
|
|
||||||
type PrintRunner struct{}
|
|
||||||
|
|
||||||
// Client stores the instance of Runner
|
|
||||||
var Client Runner = RealRunner{}
|
|
@ -1,12 +0,0 @@
|
|||||||
package kubectl
|
|
||||||
|
|
||||||
type TestRunner struct {
|
|
||||||
Runner
|
|
||||||
|
|
||||||
out []byte
|
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r TestRunner) Create(stdin []byte, ns string) ([]byte, error) {
|
|
||||||
return r.out, r.err
|
|
||||||
}
|
|
Loading…
Reference in new issue