diff --git a/Makefile b/Makefile index 94307ab20..badddd90c 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ endif BIN_DIR := bin DIST_DIR := _dist -GO_PACKAGES := cmd/helm dm +GO_PACKAGES := cmd/helm dm deploy format kubectl MAIN_GO := github.com/deis/helm-dm/cmd/helm HELM_BIN := helm-dm PATH_WITH_HELM = PATH="$(shell pwd)/$(BIN_DIR)/helm:$(PATH)" @@ -47,7 +47,7 @@ quicktest: $(PATH_WITH_HELM) go test -short $(addprefix ./,$(GO_PACKAGES)) test: test-style - $(PATH_WITH_HELM) go test -v ./ $(addprefix ./,$(GO_PACKAGES)) + $(PATH_WITH_HELM) go test -v $(addprefix ./,$(GO_PACKAGES)) test-style: @if [ $(shell gofmt -e -l -s *.go $(GO_PACKAGES)) ]; then \ diff --git a/cmd/helm/create.go b/cmd/helm/create.go index 95bd3016f..177f5e25b 100644 --- a/cmd/helm/create.go +++ b/cmd/helm/create.go @@ -1,7 +1,7 @@ package main import ( - "fmt" + "errors" "github.com/codegangsta/cli" "github.com/kubernetes/deployment-manager/chart" @@ -10,7 +10,7 @@ import ( func create(c *cli.Context) error { args := c.Args() if len(args) < 1 { - return fmt.Errorf("'helm create' requires a chart name as an argument.") + return errors.New("'helm create' requires a chart name as an argument") } cf := &chart.Chartfile{ diff --git a/cmd/helm/deploy.go b/cmd/helm/deploy.go index 14447fa85..12c5f2c97 100644 --- a/cmd/helm/deploy.go +++ b/cmd/helm/deploy.go @@ -13,13 +13,13 @@ import ( func deploy(c *cli.Context) error { args := c.Args() if len(args) < 1 { - format.Error("First argument, filename, is required. Try 'helm deploy --help'") + format.Err("First argument, filename, is required. Try 'helm deploy --help'") os.Exit(1) } props, err := parseProperties(c.String("properties")) if err != nil { - format.Error("Failed to parse properties: %s", err) + format.Err("Failed to parse properties: %s", err) os.Exit(1) } @@ -36,7 +36,6 @@ func deploy(c *cli.Context) error { } return doDeploy(d, c.GlobalString("host"), c.Bool("dry-run")) - return nil } func doDeploy(cfg *dep.Deployment, host string, dry bool) error { diff --git a/cmd/helm/dm.go b/cmd/helm/dm.go index a1e60e3a5..c5069900a 100644 --- a/cmd/helm/dm.go +++ b/cmd/helm/dm.go @@ -8,14 +8,15 @@ import ( "github.com/deis/helm-dm/kubectl" ) -var ErrAlreadyInstalled error = errors.New("Already Installed") +// ErrAlreadyInstalled indicates that DM is already installed. +var ErrAlreadyInstalled = errors.New("Already Installed") func install(dryRun bool) error { runner := getKubectlRunner(dryRun) out, err := dm.Install(runner) if err != nil { - format.Error("Error installing: %s %s", out, err) + format.Err("Error installing: %s %s", out, err) } format.Msg(out) return nil diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 8ae38aa87..a08514c2a 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -47,7 +47,7 @@ func commands() []cli.Command { }, Action: func(c *cli.Context) { if err := install(c.Bool("dry-run")); err != nil { - format.Error("%s (Run 'helm doctor' for more information)", err) + format.Err("%s (Run 'helm doctor' for more information)", err) os.Exit(1) } }, @@ -64,7 +64,7 @@ func commands() []cli.Command { }, Action: func(c *cli.Context) { if err := uninstall(c.Bool("dry-run")); err != nil { - format.Error("%s (Run 'helm doctor' for more information)", err) + format.Err("%s (Run 'helm doctor' for more information)", err) os.Exit(1) } }, @@ -73,7 +73,7 @@ func commands() []cli.Command { Name: "status", Usage: "Show status of DM.", Action: func(c *cli.Context) { - format.Error("Not yet implemented") + format.Err("Not yet implemented") os.Exit(1) }, }, @@ -83,7 +83,7 @@ func commands() []cli.Command { ArgsUsage: "", Action: func(c *cli.Context) { if err := target(c.Bool("dry-run")); err != nil { - format.Error("%s (Is the cluster running?)", err) + format.Err("%s (Is the cluster running?)", err) os.Exit(1) } }, @@ -108,7 +108,7 @@ func commands() []cli.Command { }, Action: func(c *cli.Context) { if err := install(c.Bool("dry-run")); err != nil { - format.Error("%s (Run 'helm doctor' for more information)", err) + format.Err("%s (Run 'helm doctor' for more information)", err) os.Exit(1) } }, @@ -119,7 +119,7 @@ func commands() []cli.Command { ArgsUsage: "", Action: func(c *cli.Context) { if err := doctor(); err != nil { - format.Error("%s", err) + format.Err("%s", err) os.Exit(1) } }, diff --git a/cmd/helm/list.go b/cmd/helm/list.go index b5eb7446d..eadb25757 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -14,7 +14,7 @@ func listCmd() cli.Command { Usage: "Lists the deployments in the cluster", Action: func(c *cli.Context) { if err := list(c.GlobalString("host")); err != nil { - format.Error("%s (Is the cluster running?)", err) + format.Err("%s (Is the cluster running?)", err) os.Exit(1) } }, diff --git a/cmd/helm/pack.go b/cmd/helm/pack.go index dea528f61..04ab391cf 100644 --- a/cmd/helm/pack.go +++ b/cmd/helm/pack.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "os" @@ -12,7 +13,7 @@ import ( func pack(cxt *cli.Context) error { args := cxt.Args() if len(args) < 1 { - return fmt.Errorf("'helm package' requires a path to a chart directory as an argument.") + return errors.New("'helm package' requires a path to a chart directory as an argument") } dir := args[0] diff --git a/deploy/deploy.go b/deploy/deploy.go index 53d88bd0d..41a9188d9 100644 --- a/deploy/deploy.go +++ b/deploy/deploy.go @@ -78,6 +78,7 @@ func (d *Deployment) Prepare() error { return nil } +// Chart retrieves the chart from teh deployment. func (d *Deployment) Chart() *chart.Chart { return d.lchart } diff --git a/dm/client.go b/dm/client.go index 8f49669ea..301d1f564 100644 --- a/dm/client.go +++ b/dm/client.go @@ -14,7 +14,7 @@ import ( ) // The default HTTP timeout -var DefaultHTTPTimeout time.Duration = time.Second * 10 +var DefaultHTTPTimeout = time.Second * 10 // Client is a DM client. type Client struct { @@ -50,7 +50,7 @@ func (c *Client) url(path string) string { func (c *Client) CallService(path, method, action string, dest interface{}, reader io.ReadCloser) error { u := c.url(path) - resp, err := c.callHttp(u, method, action, reader) + resp, err := c.callHTTP(u, method, action, reader) if err != nil { return err } @@ -69,8 +69,8 @@ func (c *Client) CallService(path, method, action string, dest interface{}, read return nil } -// callHttp is a low-level primative for executing HTTP operations. -func (c *Client) callHttp(path, method, action string, reader io.ReadCloser) (string, error) { +// callHTTP is a low-level primative for executing HTTP operations. +func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (string, error) { request, err := http.NewRequest(method, path, reader) request.Header.Add("Content-Type", "application/json") @@ -99,6 +99,7 @@ func (c *Client) callHttp(path, method, action string, reader io.ReadCloser) (st return string(body), nil } +// ListDeployments lists the deployments in DM. func (c *Client) ListDeployments() error { var d interface{} if err := c.CallService("deployments", "GET", "foo", &d, nil); err != nil { @@ -109,6 +110,7 @@ func (c *Client) ListDeployments() error { return nil } +// DeployChart sends a chart to DM for deploying. func (c *Client) DeployChart(filename, deployname string) error { f, err := os.Open(filename) if err != nil { diff --git a/dm/install.go b/dm/install.go index ad2aabb75..f2a70163d 100644 --- a/dm/install.go +++ b/dm/install.go @@ -20,7 +20,7 @@ func IsInstalled(runner kubectl.Runner) bool { // 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) + format.Err("Installation not found: %s %s", out, err) return false } return true diff --git a/dm/transport.go b/dm/transport.go index 588f7f96d..345cbfa61 100644 --- a/dm/transport.go +++ b/dm/transport.go @@ -15,6 +15,7 @@ type debugTransport struct { http.RoundTripper } +// NewDebugTransport returns a debugging implementation of a RoundTripper. func NewDebugTransport(rt http.RoundTripper) http.RoundTripper { return debugTransport{ RoundTripper: rt, diff --git a/format/messages.go b/format/messages.go index dcf26736a..59de3e6cb 100644 --- a/format/messages.go +++ b/format/messages.go @@ -7,16 +7,19 @@ import ( // This is all just placeholder. -func Error(msg string, v ...interface{}) { +// Err prints an error message to Stderr. +func Err(msg string, v ...interface{}) { msg = "[ERROR] " + msg + "\n" fmt.Fprintf(os.Stderr, msg, v...) } +// Info prints an informational message to Stdout. func Info(msg string, v ...interface{}) { msg = "[INFO] " + msg + "\n" fmt.Fprintf(os.Stdout, msg, v...) } +// Msg prints a raw message to Stdout. func Msg(msg string, v ...interface{}) { fmt.Fprintf(os.Stdout, msg, v...) } diff --git a/kubectl/get.go b/kubectl/get.go index 6bdc0e433..d80dd385d 100644 --- a/kubectl/get.go +++ b/kubectl/get.go @@ -13,6 +13,7 @@ func (r RealRunner) Get(stdin []byte, ns string) ([]byte, error) { return cmd.CombinedOutput() } +// GetByKind gets a named thing by kind. func (r RealRunner) GetByKind(kind, name, ns string) (string, error) { args := []string{"get", kind, name} @@ -37,6 +38,7 @@ func (r PrintRunner) Get(stdin []byte, ns string) ([]byte, error) { return []byte(cmd.String()), nil } +// GetByKind gets a named thing by kind. func (r PrintRunner) GetByKind(kind, name, ns string) (string, error) { args := []string{"get", kind, name}