Merge pull request #324 from michelleN/status

feat(*): add helm dm status command
pull/323/merge
Jack Greenfield 9 years ago
commit 3be42cd605

@ -78,9 +78,16 @@ func dmCmd() cli.Command {
Name: "status", Name: "status",
Usage: "Show status of DM.", Usage: "Show status of DM.",
ArgsUsage: "", ArgsUsage: "",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "Only display the underlying kubectl commands.",
},
},
Action: func(c *cli.Context) { Action: func(c *cli.Context) {
format.Err("Not yet implemented") if err := status(c.Bool("dry-run")); err != nil {
os.Exit(1) os.Exit(1)
}
}, },
}, },
{ {
@ -126,6 +133,20 @@ func uninstall(dryRun bool) error {
return nil 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 { func getKubectlRunner(dryRun bool) kubectl.Runner {
if dryRun { if dryRun {
return &kubectl.PrintRunner{} return &kubectl.PrintRunner{}

@ -33,6 +33,7 @@ func command(args ...string) *cmd {
} }
func assignStdin(cmd *cmd, in []byte) { func assignStdin(cmd *cmd, in []byte) {
fmt.Println(string(in))
cmd.Stdin = bytes.NewBuffer(in) cmd.Stdin = bytes.NewBuffer(in)
} }

@ -29,9 +29,13 @@ func (r RealRunner) Get(stdin []byte, ns string) ([]byte, error) {
return cmd.CombinedOutput() 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) { 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 != "" { if ns != "" {
args = append([]string{"--namespace=" + ns}, args...) 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 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) { 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 != "" { if ns != "" {
args = append([]string{"--namespace=" + ns}, args...) args = append([]string{"--namespace=" + ns}, args...)

@ -31,3 +31,15 @@ func TestGet(t *testing.T) {
t.Errorf("%s != %s", string(out), expects) 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)
}
}

@ -26,3 +26,7 @@ type TestRunner struct {
func (r TestRunner) Get(stdin []byte, ns string) ([]byte, error) { func (r TestRunner) Get(stdin []byte, ns string) ([]byte, error) {
return r.out, r.err return r.out, r.err
} }
func (r TestRunner) GetByKind(kind, name, ns string) (string, error) {
return string(r.out), r.err
}

Loading…
Cancel
Save