From fc40bc8d16223134bfefbd4bff86d69b0da4794b Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 29 Mar 2016 16:15:23 -0700 Subject: [PATCH 1/3] fix(cli): use kubectl builder consistently --- cmd/helm/server.go | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/cmd/helm/server.go b/cmd/helm/server.go index f33649c71..6aae6b8f4 100644 --- a/cmd/helm/server.go +++ b/cmd/helm/server.go @@ -123,11 +123,12 @@ func dmCmd() cli.Command { } 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) + + dryRun := c.Bool("dry-run") + runner := buildKubectlRunner(dryRun) i := client.NewInstaller() i.Manager["Image"] = manImg @@ -144,7 +145,7 @@ func installServer(c *cli.Context) error { func uninstallServer(c *cli.Context) error { dryRun := c.Bool("dry-run") - runner := getKubectlRunner(dryRun) + runner := buildKubectlRunner(dryRun) out, err := client.Uninstall(runner) if err != nil { @@ -156,12 +157,9 @@ func uninstallServer(c *cli.Context) error { func statusServer(c *cli.Context) error { dryRun := c.Bool("dry-run") - client := kubectl.Client - if dryRun { - client = kubectl.PrintRunner{} - } + runner := buildKubectlRunner(dryRun) - out, err := client.GetByKind("pods", "", "dm") + out, err := runner.GetByKind("pods", "", "dm") if err != nil { return err } @@ -169,23 +167,20 @@ func statusServer(c *cli.Context) error { return nil } -func getKubectlRunner(dryRun bool) kubectl.Runner { - if dryRun { - return &kubectl.PrintRunner{} - } - return &kubectl.RealRunner{} -} - func targetServer(c *cli.Context) error { dryRun := c.Bool("dry-run") - client := kubectl.Client - if dryRun { - client = kubectl.PrintRunner{} - } - out, err := client.ClusterInfo() + runner := buildKubectlRunner(dryRun) + out, err := runner.ClusterInfo() if err != nil { return fmt.Errorf("%s (%s)", out, err) } format.Msg(string(out)) return nil } + +func buildKubectlRunner(dryRun bool) kubectl.Runner { + if dryRun { + return &kubectl.PrintRunner{} + } + return &kubectl.RealRunner{} +} From 84e7abca89d4b4fe71db886fd3e985f70fbc2342 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 29 Mar 2016 16:20:56 -0700 Subject: [PATCH 2/3] feat(cli) add kubectl path option --- cmd/helm/helm.go | 7 ++++++- cmd/helm/server.go | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index ece993dc3..42e084e90 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -70,10 +70,15 @@ func main() { app.Flags = []cli.Flag{ cli.StringFlag{ Name: "host,u", - Usage: "The URL of the DM server.", + Usage: "The URL of the DM server", EnvVar: "HELM_HOST", Value: "https://localhost:8000/", }, + cli.StringFlag{ + Name: "kubectl", + Usage: "The path to the kubectl binary", + EnvVar: "KUBECTL", + }, cli.IntFlag{ Name: "timeout", Usage: "Time in seconds to wait for response", diff --git a/cmd/helm/server.go b/cmd/helm/server.go index 6aae6b8f4..0409bc9f1 100644 --- a/cmd/helm/server.go +++ b/cmd/helm/server.go @@ -128,7 +128,8 @@ func installServer(c *cli.Context) error { manImg := c.String("manager-image") dryRun := c.Bool("dry-run") - runner := buildKubectlRunner(dryRun) + kubectlPath := c.String("kubectl") + runner := buildKubectlRunner(kubectlPath, dryRun) i := client.NewInstaller() i.Manager["Image"] = manImg @@ -145,7 +146,8 @@ func installServer(c *cli.Context) error { func uninstallServer(c *cli.Context) error { dryRun := c.Bool("dry-run") - runner := buildKubectlRunner(dryRun) + kubectlPath := c.String("kubectl") + runner := buildKubectlRunner(kubectlPath, dryRun) out, err := client.Uninstall(runner) if err != nil { @@ -157,7 +159,8 @@ func uninstallServer(c *cli.Context) error { func statusServer(c *cli.Context) error { dryRun := c.Bool("dry-run") - runner := buildKubectlRunner(dryRun) + kubectlPath := c.String("kubectl") + runner := buildKubectlRunner(kubectlPath, dryRun) out, err := runner.GetByKind("pods", "", "dm") if err != nil { @@ -169,7 +172,9 @@ func statusServer(c *cli.Context) error { func targetServer(c *cli.Context) error { dryRun := c.Bool("dry-run") - runner := buildKubectlRunner(dryRun) + kubectlPath := c.String("kubectl") + runner := buildKubectlRunner(kubectlPath, dryRun) + out, err := runner.ClusterInfo() if err != nil { return fmt.Errorf("%s (%s)", out, err) @@ -178,9 +183,13 @@ func targetServer(c *cli.Context) error { return nil } -func buildKubectlRunner(dryRun bool) kubectl.Runner { +func buildKubectlRunner(kubectlPath string, dryRun bool) kubectl.Runner { if dryRun { return &kubectl.PrintRunner{} } + // TODO: Refactor out kubectl.Path global + if kubectlPath != "" { + kubectl.Path = kubectlPath + } return &kubectl.RealRunner{} } From c6af169577e5cb88cb5e0f9ce6a21f88d80baedf Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 29 Mar 2016 16:33:08 -0700 Subject: [PATCH 3/3] fix(cli): use global option string for kubectl --- cmd/helm/server.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/helm/server.go b/cmd/helm/server.go index 0409bc9f1..ffd0f876e 100644 --- a/cmd/helm/server.go +++ b/cmd/helm/server.go @@ -128,7 +128,7 @@ func installServer(c *cli.Context) error { manImg := c.String("manager-image") dryRun := c.Bool("dry-run") - kubectlPath := c.String("kubectl") + kubectlPath := c.GlobalString("kubectl") runner := buildKubectlRunner(kubectlPath, dryRun) i := client.NewInstaller() @@ -146,7 +146,7 @@ func installServer(c *cli.Context) error { func uninstallServer(c *cli.Context) error { dryRun := c.Bool("dry-run") - kubectlPath := c.String("kubectl") + kubectlPath := c.GlobalString("kubectl") runner := buildKubectlRunner(kubectlPath, dryRun) out, err := client.Uninstall(runner) @@ -159,7 +159,7 @@ func uninstallServer(c *cli.Context) error { func statusServer(c *cli.Context) error { dryRun := c.Bool("dry-run") - kubectlPath := c.String("kubectl") + kubectlPath := c.GlobalString("kubectl") runner := buildKubectlRunner(kubectlPath, dryRun) out, err := runner.GetByKind("pods", "", "dm") @@ -172,7 +172,7 @@ func statusServer(c *cli.Context) error { func targetServer(c *cli.Context) error { dryRun := c.Bool("dry-run") - kubectlPath := c.String("kubectl") + kubectlPath := c.GlobalString("kubectl") runner := buildKubectlRunner(kubectlPath, dryRun) out, err := runner.ClusterInfo()