diff --git a/cmd/helm/install.go b/cmd/helm/dm.go similarity index 51% rename from cmd/helm/install.go rename to cmd/helm/dm.go index 1d44be082..a1e60e3a5 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/dm.go @@ -11,15 +11,8 @@ import ( var ErrAlreadyInstalled error = errors.New("Already Installed") func install(dryRun bool) error { - var runner kubectl.Runner - if dryRun { - runner = &kubectl.PrintRunner{} - } else { - runner = &kubectl.RealRunner{} - if dm.IsInstalled(runner) { - return ErrAlreadyInstalled - } - } + runner := getKubectlRunner(dryRun) + out, err := dm.Install(runner) if err != nil { format.Error("Error installing: %s %s", out, err) @@ -27,3 +20,21 @@ func install(dryRun bool) error { format.Msg(out) return nil } + +func uninstall(dryRun bool) error { + runner := getKubectlRunner(dryRun) + + out, err := dm.Uninstall(runner) + if err != nil { + format.Error("Error uninstalling: %s %s", out, err) + } + format.Msg(out) + return nil +} + +func getKubectlRunner(dryRun bool) kubectl.Runner { + if dryRun { + return &kubectl.PrintRunner{} + } + return &kubectl.RealRunner{} +} diff --git a/cmd/doctor.go b/cmd/helm/doctor.go similarity index 100% rename from cmd/doctor.go rename to cmd/helm/doctor.go diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 0b6816c86..bbae7554b 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -32,6 +32,71 @@ func main() { func commands() []cli.Command { return []cli.Command{ + { + Name: "dm", + Usage: "Manage DM on Kubernetes", + Subcommands: []cli.Command{ + { + Name: "install", + Usage: "Install DM on Kubernetes.", + Description: ``, + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "dry-run", + Usage: "Show what would be installed, but don't install anything.", + }, + }, + Action: func(c *cli.Context) { + if err := install(c.Bool("dry-run")); err != nil { + format.Error("%s (Run 'helm doctor' for more information)", err) + os.Exit(1) + } + }, + }, + { + Name: "uninstall", + Usage: "Uninstall the DM from Kubernetes.", + Description: ``, + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "dry-run", + Usage: "Show what would be installed, but don't install anything.", + }, + }, + Action: func(c *cli.Context) { + if err := uninstall(c.Bool("dry-run")); err != nil { + format.Error("%s (Run 'helm doctor' for more information)", err) + os.Exit(1) + } + }, + }, + { + Name: "status", + Usage: "Show status of DM.", + Action: func(c *cli.Context) { + format.Error("Not yet implemented") + os.Exit(1) + }, + }, + { + Name: "target", + Usage: "Displays information about cluster.", + ArgsUsage: "", + Action: func(c *cli.Context) { + if err := target(c.Bool("dry-run")); err != nil { + format.Error("%s (Is the cluster running?)", err) + os.Exit(1) + } + }, + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "dry-run", + Usage: "Only display the underlying kubectl commands.", + }, + }, + }, + }, + }, { Name: "init", Usage: "Initialize the client and install DM on Kubernetes.", @@ -49,23 +114,6 @@ func commands() []cli.Command { } }, }, - { - Name: "target", - Usage: "Displays information about cluster.", - ArgsUsage: "", - Action: func(c *cli.Context) { - if err := target(c.Bool("dry-run")); err != nil { - format.Error("%s (Is the cluster running?)", err) - os.Exit(1) - } - }, - Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "dry-run", - Usage: "Only display the underlying kubectl commands.", - }, - }, - }, { Name: "doctor", Usage: "Run a series of checks for necessary prerequisites.", diff --git a/dm/uninstall.go b/dm/uninstall.go new file mode 100644 index 000000000..277ff1c10 --- /dev/null +++ b/dm/uninstall.go @@ -0,0 +1,14 @@ +package dm + +import ( + "github.com/deis/helm-dm/kubectl" +) + +// uninstall uses kubectl to uninstall the base DM. +// +// Returns the string output received from the operation, and an error if the +// command failed. +func Uninstall(runner kubectl.Runner) (string, error) { + o, err := runner.Delete("dm", "Namespace", "dm") + return string(o), err +}