From 084c0da59a0c098a8ffe475a19db19c9bc0e2883 Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Thu, 24 Mar 2016 14:21:45 -0600 Subject: [PATCH 1/3] feat(cli): move 'helm dm' to 'helm server' --- cmd/helm/{dm.go => server.go} | 39 +++++++++++++++++++++++++---------- cmd/helm/target.go | 37 --------------------------------- 2 files changed, 28 insertions(+), 48 deletions(-) rename cmd/helm/{dm.go => server.go} (80%) delete mode 100644 cmd/helm/target.go diff --git a/cmd/helm/dm.go b/cmd/helm/server.go similarity index 80% rename from cmd/helm/dm.go rename to cmd/helm/server.go index 9b5d8065c..df794f178 100644 --- a/cmd/helm/dm.go +++ b/cmd/helm/server.go @@ -18,6 +18,7 @@ package main import ( "errors" + "fmt" "os" "github.com/codegangsta/cli" @@ -26,7 +27,7 @@ import ( "github.com/kubernetes/helm/pkg/kubectl" ) -// ErrAlreadyInstalled indicates that DM is already installed. +// ErrAlreadyInstalled indicates that Helm Server is already installed. var ErrAlreadyInstalled = errors.New("Already Installed") func init() { @@ -35,14 +36,17 @@ func init() { func dmCmd() cli.Command { return cli.Command{ - Name: "dm", - Usage: "Manage DM on Kubernetes", + Name: "server", + Usage: "Manage Helm server-side components", Subcommands: []cli.Command{ { - Name: "install", - Usage: "Install DM on Kubernetes.", - ArgsUsage: "", - Description: ``, + Name: "install", + Usage: "Install Helm server components on Kubernetes.", + ArgsUsage: "", + Description: `Use kubectl to install Helm components in their own namespace on Kubernetes. + + Make sure your Kubernetes environment is pointed to the cluster on which you + wish to install.`, Flags: []cli.Flag{ cli.BoolFlag{ Name: "dry-run", @@ -77,13 +81,13 @@ func dmCmd() cli.Command { }, { Name: "uninstall", - Usage: "Uninstall the DM from Kubernetes.", + Usage: "Uninstall the Helm server-side from Kubernetes.", ArgsUsage: "", Description: ``, Flags: []cli.Flag{ cli.BoolFlag{ Name: "dry-run", - Usage: "Show what would be installed, but don't install anything.", + Usage: "Show what would be uninstalled, but don't remove anything.", }, }, Action: func(c *cli.Context) { @@ -95,7 +99,7 @@ func dmCmd() cli.Command { }, { Name: "status", - Usage: "Show status of DM.", + Usage: "Show status of Helm server-side components.", ArgsUsage: "", Flags: []cli.Flag{ cli.BoolFlag{ @@ -111,7 +115,7 @@ func dmCmd() cli.Command { }, { Name: "target", - Usage: "Displays information about cluster.", + Usage: "Displays information about the Kubernetes cluster.", ArgsUsage: "", Action: func(c *cli.Context) { if err := target(c.Bool("dry-run")); err != nil { @@ -177,3 +181,16 @@ func getKubectlRunner(dryRun bool) kubectl.Runner { } return &kubectl.RealRunner{} } + +func target(dryRun bool) error { + client := kubectl.Client + if dryRun { + client = kubectl.PrintRunner{} + } + out, err := client.ClusterInfo() + if err != nil { + return fmt.Errorf("%s (%s)", out, err) + } + format.Msg(string(out)) + return nil +} diff --git a/cmd/helm/target.go b/cmd/helm/target.go deleted file mode 100644 index bcf61bb40..000000000 --- a/cmd/helm/target.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "fmt" - - "github.com/kubernetes/helm/pkg/format" - "github.com/kubernetes/helm/pkg/kubectl" -) - -func target(dryRun bool) error { - client := kubectl.Client - if dryRun { - client = kubectl.PrintRunner{} - } - out, err := client.ClusterInfo() - if err != nil { - return fmt.Errorf("%s (%s)", out, err) - } - format.Msg(string(out)) - return nil -} From 14efdee05d04ba7421f25a8d20a9ea47a136782d Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Thu, 24 Mar 2016 14:42:46 -0600 Subject: [PATCH 2/3] fix(cli): switched `server` actions to use `run()` --- cmd/helm/server.go | 51 ++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/cmd/helm/server.go b/cmd/helm/server.go index df794f178..cbb894d27 100644 --- a/cmd/helm/server.go +++ b/cmd/helm/server.go @@ -19,7 +19,6 @@ package main import ( "errors" "fmt" - "os" "github.com/codegangsta/cli" "github.com/kubernetes/helm/pkg/client" @@ -68,16 +67,7 @@ func dmCmd() cli.Command { EnvVar: "HELM_MANAGER_IMAGE", }, }, - Action: func(c *cli.Context) { - dry := c.Bool("dry-run") - ri := c.String("resourcifier-image") - ei := c.String("expandybird-image") - mi := c.String("manager-image") - if err := install(dry, ei, mi, ri); err != nil { - format.Err("%s (Run 'helm doctor' for more information)", err) - os.Exit(1) - } - }, + Action: func(c *cli.Context) { run(c, installServer) }, }, { Name: "uninstall", @@ -90,12 +80,7 @@ func dmCmd() cli.Command { Usage: "Show what would be uninstalled, but don't remove anything.", }, }, - Action: func(c *cli.Context) { - if err := uninstall(c.Bool("dry-run")); err != nil { - format.Err("%s (Run 'helm doctor' for more information)", err) - os.Exit(1) - } - }, + Action: func(c *cli.Context) { run(c, uninstallServer) }, }, { Name: "status", @@ -107,22 +92,13 @@ func dmCmd() cli.Command { Usage: "Only display the underlying kubectl commands.", }, }, - Action: func(c *cli.Context) { - if err := status(c.Bool("dry-run")); err != nil { - os.Exit(1) - } - }, + Action: func(c *cli.Context) { run(c, statusServer) }, }, { Name: "target", Usage: "Displays information about the Kubernetes cluster.", ArgsUsage: "", - Action: func(c *cli.Context) { - if err := target(c.Bool("dry-run")); err != nil { - format.Err("%s (Is the cluster running?)", err) - os.Exit(1) - } - }, + Action: func(c *cli.Context) { run(c, targetServer) }, Flags: []cli.Flag{ cli.BoolFlag{ Name: "dry-run", @@ -134,7 +110,11 @@ func dmCmd() cli.Command { } } -func install(dryRun bool, ebImg, manImg, resImg string) error { +func installServer(c *cli.Context) error { + dryRun := c.Bool("dry-run") + resImg := c.String("resourcifier-image") + ebImg := c.String("expandybird-image") + manImg := c.String("manager-image") runner := getKubectlRunner(dryRun) i := client.NewInstaller() @@ -146,11 +126,14 @@ func install(dryRun bool, ebImg, manImg, resImg string) error { if err != nil { return err } - format.Msg(out) + if debug { + format.Msg(out) + } return nil } -func uninstall(dryRun bool) error { +func uninstallServer(c *cli.Context) error { + dryRun := c.Bool("dry-run") runner := getKubectlRunner(dryRun) out, err := client.Uninstall(runner) @@ -161,7 +144,8 @@ func uninstall(dryRun bool) error { return nil } -func status(dryRun bool) error { +func statusServer(c *cli.Context) error { + dryRun := c.Bool("dry-run") client := kubectl.Client if dryRun { client = kubectl.PrintRunner{} @@ -182,7 +166,8 @@ func getKubectlRunner(dryRun bool) kubectl.Runner { return &kubectl.RealRunner{} } -func target(dryRun bool) error { +func targetServer(c *cli.Context) error { + dryRun := c.Bool("dry-run") client := kubectl.Client if dryRun { client = kubectl.PrintRunner{} From 719c3bdb308a93e02fa21472e98ed388a5aa4abf Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Thu, 24 Mar 2016 15:35:27 -0600 Subject: [PATCH 3/3] fix(cli): improve errors for kubectl failures --- cmd/helm/server.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cmd/helm/server.go b/cmd/helm/server.go index cbb894d27..21e948d92 100644 --- a/cmd/helm/server.go +++ b/cmd/helm/server.go @@ -124,11 +124,9 @@ func installServer(c *cli.Context) error { out, err := i.Install(runner) if err != nil { - return err - } - if debug { - format.Msg(out) + return fmt.Errorf("error installing %s %s", string(out), err) } + format.Msg(out) return nil } @@ -138,7 +136,7 @@ func uninstallServer(c *cli.Context) error { out, err := client.Uninstall(runner) if err != nil { - format.Err("Error uninstalling: %s %s", out, err) + return fmt.Errorf("error uninstalling: %s %s", out, err) } format.Msg(out) return nil