From 8f747a1cd5d3f40a0d55707818b240a428db76e3 Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Thu, 3 Mar 2016 17:48:02 -0700 Subject: [PATCH] feat(*): add helm dm status command Allows a user to inspec their dm pods and state in the running Kubernetes cluster. This resolves issue #301. --- cmd/helm/dm.go | 25 +++++++++++++++++++++++-- pkg/kubectl/command.go | 1 + pkg/kubectl/get.go | 12 ++++++++++-- pkg/kubectl/get_test.go | 12 ++++++++++++ pkg/kubectl/kubectl_test.go | 4 ++++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/cmd/helm/dm.go b/cmd/helm/dm.go index 3d2c48c0a..f821ea731 100644 --- a/cmd/helm/dm.go +++ b/cmd/helm/dm.go @@ -62,9 +62,16 @@ func dmCmd() cli.Command { Name: "status", Usage: "Show status of DM.", ArgsUsage: "", + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "dry-run", + Usage: "Only display the underlying kubectl commands.", + }, + }, Action: func(c *cli.Context) { - format.Err("Not yet implemented") - os.Exit(1) + if err := status(c.Bool("dry-run")); err != nil { + os.Exit(1) + } }, }, { @@ -110,6 +117,20 @@ func uninstall(dryRun bool) error { return nil } +func status(dryRun bool) error { + client := kubectl.Client + if dryRun { + client = kubectl.PrintRunner{} + } + + out, err := client.GetByKind("pods", "", "dm") + if err != nil { + return err + } + format.Msg(string(out)) + return nil +} + func getKubectlRunner(dryRun bool) kubectl.Runner { if dryRun { return &kubectl.PrintRunner{} diff --git a/pkg/kubectl/command.go b/pkg/kubectl/command.go index b36e0ad33..4754d7a86 100644 --- a/pkg/kubectl/command.go +++ b/pkg/kubectl/command.go @@ -17,6 +17,7 @@ func command(args ...string) *cmd { } func assignStdin(cmd *cmd, in []byte) { + fmt.Println(string(in)) cmd.Stdin = bytes.NewBuffer(in) } diff --git a/pkg/kubectl/get.go b/pkg/kubectl/get.go index d80dd385d..16e94d10f 100644 --- a/pkg/kubectl/get.go +++ b/pkg/kubectl/get.go @@ -15,7 +15,11 @@ func (r RealRunner) Get(stdin []byte, ns string) ([]byte, error) { // GetByKind gets a named thing by kind. func (r RealRunner) GetByKind(kind, name, ns string) (string, error) { - args := []string{"get", kind, name} + args := []string{"get", kind} + + if name != "" { + args = append([]string{name}, args...) + } if ns != "" { args = append([]string{"--namespace=" + ns}, args...) @@ -40,7 +44,11 @@ func (r PrintRunner) Get(stdin []byte, ns string) ([]byte, error) { // GetByKind gets a named thing by kind. func (r PrintRunner) GetByKind(kind, name, ns string) (string, error) { - args := []string{"get", kind, name} + args := []string{"get", kind} + + if name != "" { + args = append([]string{name}, args...) + } if ns != "" { args = append([]string{"--namespace=" + ns}, args...) diff --git a/pkg/kubectl/get_test.go b/pkg/kubectl/get_test.go index 532724a20..8c855cfe9 100644 --- a/pkg/kubectl/get_test.go +++ b/pkg/kubectl/get_test.go @@ -15,3 +15,15 @@ func TestGet(t *testing.T) { t.Errorf("%s != %s", string(out), expects) } } + +func TestGetByKind(t *testing.T) { + Client = TestRunner{ + out: []byte("running the GetByKind command"), + } + + expects := "running the GetByKind command" + out, _ := Client.GetByKind("pods", "", "") + if out != expects { + t.Errorf("%s != %s", out, expects) + } +} diff --git a/pkg/kubectl/kubectl_test.go b/pkg/kubectl/kubectl_test.go index 453667330..2e1d4c528 100644 --- a/pkg/kubectl/kubectl_test.go +++ b/pkg/kubectl/kubectl_test.go @@ -10,3 +10,7 @@ type TestRunner struct { func (r TestRunner) Get(stdin []byte, ns string) ([]byte, error) { return r.out, r.err } + +func (r TestRunner) GetByKind(kind, name, ns string) (string, error) { + return string(r.out), r.err +}