feat(*): install DM

pull/291/head
Matt Butcher 9 years ago
parent 9e1dbeaa48
commit 8d6007a7d1

@ -4,6 +4,7 @@ import (
"os" "os"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/deis/helm-dm/format"
) )
var version = "0.0.1" var version = "0.0.1"
@ -24,7 +25,18 @@ func commands() []cli.Command {
Name: "install", Name: "install",
Usage: "Initialize the client and install DM on Kubernetes.", Usage: "Initialize the client and install DM on Kubernetes.",
Description: ``, Description: ``,
Action: func(c *cli.Context) { install() }, 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(err.Error())
os.Exit(1)
}
},
}, },
{ {
Name: "target", Name: "target",

@ -1,13 +1,25 @@
package main package main
import ( import (
"errors"
"github.com/deis/helm-dm/dm" "github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format" "github.com/deis/helm-dm/format"
"github.com/deis/helm-dm/kubectl" "github.com/deis/helm-dm/kubectl"
) )
func install() error { var ErrAlreadyInstalled error = errors.New("Already Installed")
runner := &kubectl.PrintRunner{}
func install(dryRun bool) error {
var runner kubectl.Runner
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)

@ -1,6 +1,7 @@
package dm package dm
import ( import (
"github.com/deis/helm-dm/format"
"github.com/deis/helm-dm/kubectl" "github.com/deis/helm-dm/kubectl"
) )
@ -13,6 +14,18 @@ func Install(runner kubectl.Runner) (string, error) {
return string(o), err return string(o), err
} }
// IsInstalled checks whether DM has been installed.
func IsInstalled(runner kubectl.Runner) bool {
// Basically, we test "all-or-nothing" here: if this returns without error
// we know that we have both the namespace and the manager API server.
out, err := runner.GetByKind("rc", "manager-rc", "dm")
if err != nil {
format.Error("Installation not found: %s %s", out, err)
return false
}
return true
}
// InstallYAML is the installation YAML for DM. // InstallYAML is the installation YAML for DM.
const InstallYAML = ` const InstallYAML = `
###################################################################### ######################################################################

@ -8,12 +8,12 @@ import (
// This is all just placeholder. // This is all just placeholder.
func Error(msg string, v ...interface{}) { func Error(msg string, v ...interface{}) {
msg = "[ERROR]" + msg + "\n" msg = "[ERROR] " + msg + "\n"
fmt.Fprintf(os.Stderr, msg, v...) fmt.Fprintf(os.Stderr, msg, v...)
} }
func Info(msg string, v ...interface{}) { func Info(msg string, v ...interface{}) {
msg = "[INFO]" + msg + "\n" msg = "[INFO] " + msg + "\n"
fmt.Fprintf(os.Stdout, msg, v...) fmt.Fprintf(os.Stdout, msg, v...)
} }

@ -13,6 +13,17 @@ func (r RealRunner) Get(stdin []byte, ns string) ([]byte, error) {
return cmd.CombinedOutput() return cmd.CombinedOutput()
} }
func (r RealRunner) GetByKind(kind, name, ns string) (string, error) {
args := []string{"get", kind, name}
if ns != "" {
args = append([]string{"--namespace=" + ns}, args...)
}
cmd := command(args...)
o, err := cmd.CombinedOutput()
return string(o), err
}
// Get returns the commands to kubectl // Get returns the commands to kubectl
func (r PrintRunner) Get(stdin []byte, ns string) ([]byte, error) { func (r PrintRunner) Get(stdin []byte, ns string) ([]byte, error) {
args := []string{"get", "-f", "-"} args := []string{"get", "-f", "-"}
@ -25,3 +36,13 @@ func (r PrintRunner) Get(stdin []byte, ns string) ([]byte, error) {
return []byte(cmd.String()), nil return []byte(cmd.String()), nil
} }
func (r PrintRunner) GetByKind(kind, name, ns string) (string, error) {
args := []string{"get", kind, name}
if ns != "" {
args = append([]string{"--namespace=" + ns}, args...)
}
cmd := command(args...)
return cmd.String(), nil
}

@ -13,6 +13,13 @@ type Runner interface {
Delete(string, string, string) ([]byte, error) Delete(string, string, string) ([]byte, error)
// Get returns Kubernetes resources // Get returns Kubernetes resources
Get([]byte, string) ([]byte, error) Get([]byte, string) ([]byte, error)
// GetByKind gets an entry by kind, name, and namespace.
//
// If name is omitted, all entries of that kind are returned.
//
// If NS is omitted, the default NS is assumed.
GetByKind(kind, name, ns string) (string, error)
} }
// RealRunner implements Runner to execute kubectl commands // RealRunner implements Runner to execute kubectl commands

Loading…
Cancel
Save