diff --git a/cmd/helm/dm.go b/cmd/helm/dm.go index 75630253cdd6bc07f947c149b83b697d59df4c40..9ba93bec93121fa02bc0620cf65298d47e35acd6 100644 --- a/cmd/helm/dm.go +++ b/cmd/helm/dm.go @@ -78,9 +78,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) + } }, }, { @@ -126,6 +133,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 43d437135b4376acfce56e6bac3f055a5e155179..2698bb6a81c07bdc5aa5cf70acac60e98d9601df 100644 --- a/pkg/kubectl/command.go +++ b/pkg/kubectl/command.go @@ -33,6 +33,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 ec5921dc5832f936b1bb8dcbe93b7d097d823632..9b2e138527b2c9b1c04d2075fab763218c3194b5 100644 --- a/pkg/kubectl/get.go +++ b/pkg/kubectl/get.go @@ -29,9 +29,13 @@ func (r RealRunner) Get(stdin []byte, ns string) ([]byte, error) { return cmd.CombinedOutput() } -// GetByKind gets a named thing by kind. +// GetByKind gets resources by kind, name(optional), and namespace(optional) 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...) @@ -54,9 +58,13 @@ func (r PrintRunner) Get(stdin []byte, ns string) ([]byte, error) { return []byte(cmd.String()), nil } -// GetByKind gets a named thing by kind. +// GetByKind gets resources by kind, name(optional), and namespace(optional) 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 429ae5ebb5ed34d874713a853f52c3c65c63b1e9..e82f7b6e16ea2e1a892adcd8bd359e813b29be9a 100644 --- a/pkg/kubectl/get_test.go +++ b/pkg/kubectl/get_test.go @@ -31,3 +31,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 f4625330caf5fd8bcfd30f796b3fd71ab454b7db..4b7579577b7ffcd476d2ea6fef7dfaae2222d711 100644 --- a/pkg/kubectl/kubectl_test.go +++ b/pkg/kubectl/kubectl_test.go @@ -26,3 +26,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 +}