From 341e6f4f45c1280f9dec2d6f3fb1c48e5411c49d Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Mon, 23 Apr 2018 15:42:19 -0700 Subject: [PATCH] feat(cmd): add --all-namespaces to list --- cmd/helm/delete.go | 2 +- cmd/helm/get.go | 2 +- cmd/helm/get_hooks.go | 2 +- cmd/helm/get_manifest.go | 2 +- cmd/helm/get_values.go | 2 +- cmd/helm/helm.go | 16 +++++++++------ cmd/helm/history.go | 2 +- cmd/helm/install.go | 2 +- cmd/helm/list.go | 39 ++++++++++++++++++------------------- cmd/helm/release_testing.go | 2 +- cmd/helm/rollback.go | 2 +- cmd/helm/status.go | 2 +- cmd/helm/upgrade.go | 2 +- 13 files changed, 40 insertions(+), 37 deletions(-) diff --git a/cmd/helm/delete.go b/cmd/helm/delete.go index 08f965520..20d29b203 100755 --- a/cmd/helm/delete.go +++ b/cmd/helm/delete.go @@ -61,7 +61,7 @@ func newDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command { if len(args) == 0 { return errors.New("command 'delete' requires a release name") } - del.client = ensureHelmClient(del.client) + del.client = ensureHelmClient(del.client, false) for i := 0; i < len(args); i++ { del.name = args[i] diff --git a/cmd/helm/get.go b/cmd/helm/get.go index 8e6ff8cc0..3d2b32bc1 100644 --- a/cmd/helm/get.go +++ b/cmd/helm/get.go @@ -62,7 +62,7 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command { return errReleaseRequired } get.release = args[0] - get.client = ensureHelmClient(get.client) + get.client = ensureHelmClient(get.client, false) return get.run() }, } diff --git a/cmd/helm/get_hooks.go b/cmd/helm/get_hooks.go index c245589a6..5024c991f 100644 --- a/cmd/helm/get_hooks.go +++ b/cmd/helm/get_hooks.go @@ -52,7 +52,7 @@ func newGetHooksCmd(client helm.Interface, out io.Writer) *cobra.Command { return errReleaseRequired } ghc.release = args[0] - ghc.client = ensureHelmClient(ghc.client) + ghc.client = ensureHelmClient(ghc.client, false) return ghc.run() }, } diff --git a/cmd/helm/get_manifest.go b/cmd/helm/get_manifest.go index 59e92417e..66bc0e2e8 100644 --- a/cmd/helm/get_manifest.go +++ b/cmd/helm/get_manifest.go @@ -54,7 +54,7 @@ func newGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command { return errReleaseRequired } get.release = args[0] - get.client = ensureHelmClient(get.client) + get.client = ensureHelmClient(get.client, false) return get.run() }, } diff --git a/cmd/helm/get_values.go b/cmd/helm/get_values.go index 292a6ca98..7571e5dae 100644 --- a/cmd/helm/get_values.go +++ b/cmd/helm/get_values.go @@ -52,7 +52,7 @@ func newGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command { return errReleaseRequired } get.release = args[0] - get.client = ensureHelmClient(get.client) + get.client = ensureHelmClient(get.client, false) return get.run() }, } diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 89f85a15c..77f74d935 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -151,14 +151,14 @@ func checkArgsLength(argsReceived int, requiredArgs ...string) error { } // ensureHelmClient returns a new helm client impl. if h is not nil. -func ensureHelmClient(h helm.Interface) helm.Interface { +func ensureHelmClient(h helm.Interface, allNamespaces bool) helm.Interface { if h != nil { return h } - return newClient() + return newClient(allNamespaces) } -func newClient() helm.Interface { +func newClient(allNamespaces bool) helm.Interface { kc := kube.New(kubeConfig()) kc.Log = logf @@ -167,13 +167,17 @@ func newClient() helm.Interface { // TODO return error log.Fatal(err) } + var namespace string + if !allNamespaces { + namespace = getNamespace() + } // TODO add other backends - cfgmaps := driver.NewSecrets(clientset.CoreV1().Secrets(getNamespace())) - cfgmaps.Log = logf + d := driver.NewSecrets(clientset.CoreV1().Secrets(namespace)) + d.Log = logf return helm.NewClient( helm.KubeClient(kc), - helm.Driver(cfgmaps), + helm.Driver(d), helm.Discovery(clientset.Discovery()), ) } diff --git a/cmd/helm/history.go b/cmd/helm/history.go index 90efd9db9..2e3c27da2 100644 --- a/cmd/helm/history.go +++ b/cmd/helm/history.go @@ -77,7 +77,7 @@ func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command { if len(args) == 0 { return errReleaseRequired } - his.helmc = ensureHelmClient(his.helmc) + his.helmc = ensureHelmClient(his.helmc, false) his.rls = args[0] return his.run() }, diff --git a/cmd/helm/install.go b/cmd/helm/install.go index d203dfd5f..cf11da45e 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -176,7 +176,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command { return err } inst.chartPath = cp - inst.client = ensureHelmClient(inst.client) + inst.client = ensureHelmClient(inst.client, false) return inst.run() }, } diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 98b9486e4..ab2915b76 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -57,22 +57,23 @@ flag with the '--offset' flag allows you to page through results. ` type listCmd struct { - filter string - short bool - limit int - offset string - byDate bool - sortDesc bool - out io.Writer - all bool - deleted bool - deleting bool - deployed bool - failed bool - superseded bool - pending bool - client helm.Interface - colWidth uint + filter string + short bool + limit int + offset string + byDate bool + sortDesc bool + out io.Writer + all bool + deleted bool + deleting bool + deployed bool + failed bool + superseded bool + pending bool + client helm.Interface + colWidth uint + allNamespaces bool } func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { @@ -90,7 +91,7 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { if len(args) > 0 { list.filter = strings.Join(args, " ") } - list.client = ensureHelmClient(list.client) + list.client = ensureHelmClient(list.client, list.allNamespaces) return list.run() }, } @@ -108,9 +109,7 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { f.BoolVar(&list.failed, "failed", false, "show failed releases") f.BoolVar(&list.pending, "pending", false, "show pending releases") f.UintVar(&list.colWidth, "col-width", 60, "specifies the max column width of output") - - // TODO: Do we want this as a feature of 'helm list'? - //f.BoolVar(&list.superseded, "history", true, "show historical releases") + f.BoolVar(&list.allNamespaces, "all-namespaces", false, "list releases across all namespaces") return cmd } diff --git a/cmd/helm/release_testing.go b/cmd/helm/release_testing.go index 73c716c69..f09bc9ae0 100644 --- a/cmd/helm/release_testing.go +++ b/cmd/helm/release_testing.go @@ -57,7 +57,7 @@ func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command { } rlsTest.name = args[0] - rlsTest.client = ensureHelmClient(rlsTest.client) + rlsTest.client = ensureHelmClient(rlsTest.client, false) return rlsTest.run() }, } diff --git a/cmd/helm/rollback.go b/cmd/helm/rollback.go index 2db26be53..145011f36 100644 --- a/cmd/helm/rollback.go +++ b/cmd/helm/rollback.go @@ -70,7 +70,7 @@ func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command { } rollback.revision = int(v64) - rollback.client = ensureHelmClient(rollback.client) + rollback.client = ensureHelmClient(rollback.client, false) return rollback.run() }, } diff --git a/cmd/helm/status.go b/cmd/helm/status.go index 4c7c4f31e..15dde5929 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -67,7 +67,7 @@ func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command { return errReleaseRequired } status.release = args[0] - status.client = ensureHelmClient(status.client) + status.client = ensureHelmClient(status.client, false) return status.run() }, } diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index abb7fd7c4..6f2611886 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -106,7 +106,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command { upgrade.release = args[0] upgrade.chart = args[1] - upgrade.client = ensureHelmClient(upgrade.client) + upgrade.client = ensureHelmClient(upgrade.client, false) return upgrade.run() },