feat(cmd): add --all-namespaces to list

pull/3948/head
Adam Reese 6 years ago
parent d6afa4a403
commit 341e6f4f45
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -61,7 +61,7 @@ func newDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command {
if len(args) == 0 { if len(args) == 0 {
return errors.New("command 'delete' requires a release name") 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++ { for i := 0; i < len(args); i++ {
del.name = args[i] del.name = args[i]

@ -62,7 +62,7 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
return errReleaseRequired return errReleaseRequired
} }
get.release = args[0] get.release = args[0]
get.client = ensureHelmClient(get.client) get.client = ensureHelmClient(get.client, false)
return get.run() return get.run()
}, },
} }

@ -52,7 +52,7 @@ func newGetHooksCmd(client helm.Interface, out io.Writer) *cobra.Command {
return errReleaseRequired return errReleaseRequired
} }
ghc.release = args[0] ghc.release = args[0]
ghc.client = ensureHelmClient(ghc.client) ghc.client = ensureHelmClient(ghc.client, false)
return ghc.run() return ghc.run()
}, },
} }

@ -54,7 +54,7 @@ func newGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command {
return errReleaseRequired return errReleaseRequired
} }
get.release = args[0] get.release = args[0]
get.client = ensureHelmClient(get.client) get.client = ensureHelmClient(get.client, false)
return get.run() return get.run()
}, },
} }

@ -52,7 +52,7 @@ func newGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command {
return errReleaseRequired return errReleaseRequired
} }
get.release = args[0] get.release = args[0]
get.client = ensureHelmClient(get.client) get.client = ensureHelmClient(get.client, false)
return get.run() return get.run()
}, },
} }

@ -151,14 +151,14 @@ func checkArgsLength(argsReceived int, requiredArgs ...string) error {
} }
// ensureHelmClient returns a new helm client impl. if h is not nil. // 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 { if h != nil {
return h return h
} }
return newClient() return newClient(allNamespaces)
} }
func newClient() helm.Interface { func newClient(allNamespaces bool) helm.Interface {
kc := kube.New(kubeConfig()) kc := kube.New(kubeConfig())
kc.Log = logf kc.Log = logf
@ -167,13 +167,17 @@ func newClient() helm.Interface {
// TODO return error // TODO return error
log.Fatal(err) log.Fatal(err)
} }
var namespace string
if !allNamespaces {
namespace = getNamespace()
}
// TODO add other backends // TODO add other backends
cfgmaps := driver.NewSecrets(clientset.CoreV1().Secrets(getNamespace())) d := driver.NewSecrets(clientset.CoreV1().Secrets(namespace))
cfgmaps.Log = logf d.Log = logf
return helm.NewClient( return helm.NewClient(
helm.KubeClient(kc), helm.KubeClient(kc),
helm.Driver(cfgmaps), helm.Driver(d),
helm.Discovery(clientset.Discovery()), helm.Discovery(clientset.Discovery()),
) )
} }

@ -77,7 +77,7 @@ func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command {
if len(args) == 0 { if len(args) == 0 {
return errReleaseRequired return errReleaseRequired
} }
his.helmc = ensureHelmClient(his.helmc) his.helmc = ensureHelmClient(his.helmc, false)
his.rls = args[0] his.rls = args[0]
return his.run() return his.run()
}, },

@ -176,7 +176,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command {
return err return err
} }
inst.chartPath = cp inst.chartPath = cp
inst.client = ensureHelmClient(inst.client) inst.client = ensureHelmClient(inst.client, false)
return inst.run() return inst.run()
}, },
} }

@ -57,22 +57,23 @@ flag with the '--offset' flag allows you to page through results.
` `
type listCmd struct { type listCmd struct {
filter string filter string
short bool short bool
limit int limit int
offset string offset string
byDate bool byDate bool
sortDesc bool sortDesc bool
out io.Writer out io.Writer
all bool all bool
deleted bool deleted bool
deleting bool deleting bool
deployed bool deployed bool
failed bool failed bool
superseded bool superseded bool
pending bool pending bool
client helm.Interface client helm.Interface
colWidth uint colWidth uint
allNamespaces bool
} }
func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { 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 { if len(args) > 0 {
list.filter = strings.Join(args, " ") list.filter = strings.Join(args, " ")
} }
list.client = ensureHelmClient(list.client) list.client = ensureHelmClient(list.client, list.allNamespaces)
return list.run() 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.failed, "failed", false, "show failed releases")
f.BoolVar(&list.pending, "pending", false, "show pending releases") f.BoolVar(&list.pending, "pending", false, "show pending releases")
f.UintVar(&list.colWidth, "col-width", 60, "specifies the max column width of output") f.UintVar(&list.colWidth, "col-width", 60, "specifies the max column width of output")
f.BoolVar(&list.allNamespaces, "all-namespaces", false, "list releases across all namespaces")
// TODO: Do we want this as a feature of 'helm list'?
//f.BoolVar(&list.superseded, "history", true, "show historical releases")
return cmd return cmd
} }

@ -57,7 +57,7 @@ func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command {
} }
rlsTest.name = args[0] rlsTest.name = args[0]
rlsTest.client = ensureHelmClient(rlsTest.client) rlsTest.client = ensureHelmClient(rlsTest.client, false)
return rlsTest.run() return rlsTest.run()
}, },
} }

@ -70,7 +70,7 @@ func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command {
} }
rollback.revision = int(v64) rollback.revision = int(v64)
rollback.client = ensureHelmClient(rollback.client) rollback.client = ensureHelmClient(rollback.client, false)
return rollback.run() return rollback.run()
}, },
} }

@ -67,7 +67,7 @@ func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command {
return errReleaseRequired return errReleaseRequired
} }
status.release = args[0] status.release = args[0]
status.client = ensureHelmClient(status.client) status.client = ensureHelmClient(status.client, false)
return status.run() return status.run()
}, },
} }

@ -106,7 +106,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command {
upgrade.release = args[0] upgrade.release = args[0]
upgrade.chart = args[1] upgrade.chart = args[1]
upgrade.client = ensureHelmClient(upgrade.client) upgrade.client = ensureHelmClient(upgrade.client, false)
return upgrade.run() return upgrade.run()
}, },

Loading…
Cancel
Save