feat(dm-delete): add dm-delete command

pull/291/head
Adam Reese 9 years ago
parent a3166a9cdc
commit 1e37113c39

@ -11,15 +11,8 @@ import (
var ErrAlreadyInstalled error = errors.New("Already Installed") var ErrAlreadyInstalled error = errors.New("Already Installed")
func install(dryRun bool) error { func install(dryRun bool) error {
var runner kubectl.Runner runner := getKubectlRunner(dryRun)
if dryRun {
runner = &kubectl.PrintRunner{}
} else {
runner = &kubectl.RealRunner{}
if dm.IsInstalled(runner) {
return ErrAlreadyInstalled
}
}
out, err := dm.Install(runner) out, err := dm.Install(runner)
if err != nil { if err != nil {
format.Error("Error installing: %s %s", out, err) format.Error("Error installing: %s %s", out, err)
@ -27,3 +20,21 @@ func install(dryRun bool) error {
format.Msg(out) format.Msg(out)
return nil 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{}
}

@ -32,6 +32,71 @@ func main() {
func commands() []cli.Command { func commands() []cli.Command {
return []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", Name: "init",
Usage: "Initialize the client and install DM on Kubernetes.", 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", Name: "doctor",
Usage: "Run a series of checks for necessary prerequisites.", Usage: "Run a series of checks for necessary prerequisites.",

@ -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
}
Loading…
Cancel
Save