From 2a880fd57c12da908c07692a23205b2bb97dc2b9 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Mon, 15 Sep 2025 14:27:17 -0600 Subject: [PATCH] fix: make helm list show all by default Signed-off-by: Terry Howe --- pkg/action/list.go | 6 ++-- pkg/action/list_test.go | 7 ++-- pkg/cmd/list.go | 22 +++++++------ pkg/cmd/list_test.go | 32 +++++++++---------- .../output/list-all-date-reversed.txt | 10 ++++++ pkg/cmd/testdata/output/list-all-date.txt | 9 ++++++ pkg/cmd/testdata/output/list-all-max.txt | 2 ++ .../testdata/output/list-all-no-headers.txt | 8 +++++ pkg/cmd/testdata/output/list-all-offset.txt | 8 +++++ pkg/cmd/testdata/output/list-all-reverse.txt | 9 ++++++ .../testdata/output/list-all-short-json.txt | 1 + .../testdata/output/list-all-short-yaml.txt | 8 +++++ pkg/cmd/testdata/output/list-all-short.txt | 8 +++++ 13 files changed, 98 insertions(+), 32 deletions(-) create mode 100644 pkg/cmd/testdata/output/list-all-date-reversed.txt create mode 100644 pkg/cmd/testdata/output/list-all-date.txt create mode 100644 pkg/cmd/testdata/output/list-all-max.txt create mode 100644 pkg/cmd/testdata/output/list-all-no-headers.txt create mode 100644 pkg/cmd/testdata/output/list-all-offset.txt create mode 100644 pkg/cmd/testdata/output/list-all-reverse.txt create mode 100644 pkg/cmd/testdata/output/list-all-short-json.txt create mode 100644 pkg/cmd/testdata/output/list-all-short-yaml.txt create mode 100644 pkg/cmd/testdata/output/list-all-short.txt diff --git a/pkg/action/list.go b/pkg/action/list.go index c6d6f2037..b2128c8b7 100644 --- a/pkg/action/list.go +++ b/pkg/action/list.go @@ -139,7 +139,7 @@ type List struct { // NewList constructs a new *List func NewList(cfg *Configuration) *List { return &List{ - StateMask: ListDeployed | ListFailed, + StateMask: ListAll, cfg: cfg, } } @@ -315,9 +315,9 @@ func (l *List) SetStateMask() { state |= ListSuperseded } - // Apply a default + // Apply a default - now defaults to ListAll instead of just deployed and failed if state == 0 { - state = ListDeployed | ListFailed + state = ListAll } l.StateMask = state diff --git a/pkg/action/list_test.go b/pkg/action/list_test.go index 75737d635..0fddfd98d 100644 --- a/pkg/action/list_test.go +++ b/pkg/action/list_test.go @@ -174,11 +174,12 @@ func TestList_StateMask(t *testing.T) { err = lister.cfg.Releases.Update(one) is.NoError(err) + // With the new default (ListAll), we should see all 3 releases by default res, err := lister.Run() is.NoError(err) - is.Len(res, 2) - is.Equal("three", res[0].Name) - is.Equal("two", res[1].Name) + is.Len(res, 3) + is.Equal("one", res[0].Name) + is.Equal("three", res[1].Name) lister.StateMask = ListUninstalled res, err = lister.Run() diff --git a/pkg/cmd/list.go b/pkg/cmd/list.go index 55d828036..fd424427b 100644 --- a/pkg/cmd/list.go +++ b/pkg/cmd/list.go @@ -36,9 +36,12 @@ import ( var listHelp = ` This command lists all of the releases for a specified namespace (uses current namespace context if namespace not specified). -By default, it lists only releases that are deployed or failed. Flags like -'--uninstalled' and '--all' will alter this behavior. Such flags can be combined: -'--uninstalled --failed'. +By default, it lists all releases in any status including deployed, failed, +pending-upgrade, pending-install, pending-rollback, uninstalled, uninstalling, +superseded, and unknown. Individual status filters like '--deployed', '--failed', +'--pending', '--uninstalled', '--superseded', and '--uninstalling' can be used +to show only releases in specific states. Such flags can be combined: +'--deployed --failed'. By default, items are sorted alphabetically. Use the '-d' flag to sort by release date. @@ -117,13 +120,12 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.StringVar(&client.TimeFormat, "time-format", "", `format time using golang time formatter. Example: --time-format "2006-01-02 15:04:05Z0700"`) f.BoolVarP(&client.ByDate, "date", "d", false, "sort by release date") f.BoolVarP(&client.SortReverse, "reverse", "r", false, "reverse the sort order") - f.BoolVarP(&client.All, "all", "a", false, "show all releases without any filter applied") - f.BoolVar(&client.Uninstalled, "uninstalled", false, "show uninstalled releases (if 'helm uninstall --keep-history' was used)") - f.BoolVar(&client.Superseded, "superseded", false, "show superseded releases") - f.BoolVar(&client.Uninstalling, "uninstalling", false, "show releases that are currently being uninstalled") - f.BoolVar(&client.Deployed, "deployed", false, "show deployed releases. If no other is specified, this will be automatically enabled") - f.BoolVar(&client.Failed, "failed", false, "show failed releases") - f.BoolVar(&client.Pending, "pending", false, "show pending releases") + f.BoolVar(&client.Uninstalled, "uninstalled", false, "show only uninstalled releases (if 'helm uninstall --keep-history' was used)") + f.BoolVar(&client.Superseded, "superseded", false, "show only superseded releases") + f.BoolVar(&client.Uninstalling, "uninstalling", false, "show only releases that are currently being uninstalled") + f.BoolVar(&client.Deployed, "deployed", false, "show only deployed releases") + f.BoolVar(&client.Failed, "failed", false, "show only failed releases") + f.BoolVar(&client.Pending, "pending", false, "show only pending releases") f.BoolVarP(&client.AllNamespaces, "all-namespaces", "A", false, "list releases across all namespaces") f.IntVarP(&client.Limit, "max", "m", 256, "maximum number of releases to fetch") f.IntVar(&client.Offset, "offset", 0, "next release index in the list, used to offset from start value") diff --git a/pkg/cmd/list_test.go b/pkg/cmd/list_test.go index 22a948fff..9098d2551 100644 --- a/pkg/cmd/list_test.go +++ b/pkg/cmd/list_test.go @@ -146,22 +146,17 @@ func TestListCmd(t *testing.T) { tests := []cmdTestCase{{ name: "list releases", cmd: "list", - golden: "output/list.txt", + golden: "output/list-all.txt", rels: releaseFixture, }, { name: "list without headers", cmd: "list --no-headers", - golden: "output/list-no-headers.txt", - rels: releaseFixture, - }, { - name: "list all releases", - cmd: "list --all", - golden: "output/list-all.txt", + golden: "output/list-all-no-headers.txt", rels: releaseFixture, }, { name: "list releases sorted by release date", cmd: "list --date", - golden: "output/list-date.txt", + golden: "output/list-all-date.txt", rels: releaseFixture, }, { name: "list failed releases", @@ -171,17 +166,17 @@ func TestListCmd(t *testing.T) { }, { name: "list filtered releases", cmd: "list --filter='.*'", - golden: "output/list-filter.txt", + golden: "output/list-all.txt", rels: releaseFixture, }, { name: "list releases, limited to one release", cmd: "list --max 1", - golden: "output/list-max.txt", + golden: "output/list-all-max.txt", rels: releaseFixture, }, { name: "list releases, offset by one", cmd: "list --offset 1", - golden: "output/list-offset.txt", + golden: "output/list-all-offset.txt", rels: releaseFixture, }, { name: "list pending releases", @@ -191,27 +186,32 @@ func TestListCmd(t *testing.T) { }, { name: "list releases in reverse order", cmd: "list --reverse", - golden: "output/list-reverse.txt", + golden: "output/list-all-reverse.txt", rels: releaseFixture, }, { name: "list releases sorted by reversed release date", cmd: "list --date --reverse", - golden: "output/list-date-reversed.txt", + golden: "output/list-all-date-reversed.txt", rels: releaseFixture, }, { name: "list releases in short output format", cmd: "list --short", - golden: "output/list-short.txt", + golden: "output/list-all-short.txt", rels: releaseFixture, }, { name: "list releases in short output format", cmd: "list --short --output yaml", - golden: "output/list-short-yaml.txt", + golden: "output/list-all-short-yaml.txt", rels: releaseFixture, }, { name: "list releases in short output format", cmd: "list --short --output json", - golden: "output/list-short-json.txt", + golden: "output/list-all-short-json.txt", + rels: releaseFixture, + }, { + name: "list deployed and failed releases only", + cmd: "list --deployed --failed", + golden: "output/list.txt", rels: releaseFixture, }, { name: "list superseded releases", diff --git a/pkg/cmd/testdata/output/list-all-date-reversed.txt b/pkg/cmd/testdata/output/list-all-date-reversed.txt new file mode 100644 index 000000000..ac659b702 --- /dev/null +++ b/pkg/cmd/testdata/output/list-all-date-reversed.txt @@ -0,0 +1,10 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION +iguana default 2 2016-01-16 00:00:04 +0000 UTC deployed chickadee-1.0.0 0.0.1 +hummingbird default 1 2016-01-16 00:00:03 +0000 UTC deployed chickadee-1.0.0 0.0.1 +rocket default 1 2016-01-16 00:00:02 +0000 UTC failed chickadee-1.0.0 0.0.1 +gamora default 1 2016-01-16 00:00:01 +0000 UTC superseded chickadee-1.0.0 0.0.1 +groot default 1 2016-01-16 00:00:01 +0000 UTC uninstalled chickadee-1.0.0 0.0.1 +starlord default 2 2016-01-16 00:00:01 +0000 UTC deployed chickadee-1.0.0 0.0.1 +thanos default 1 2016-01-16 00:00:01 +0000 UTC pending-install chickadee-1.0.0 0.0.1 +drax default 1 2016-01-16 00:00:01 +0000 UTC uninstalling chickadee-1.0.0 0.0.1 + diff --git a/pkg/cmd/testdata/output/list-all-date.txt b/pkg/cmd/testdata/output/list-all-date.txt new file mode 100644 index 000000000..09b3e57d1 --- /dev/null +++ b/pkg/cmd/testdata/output/list-all-date.txt @@ -0,0 +1,9 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION +starlord default 2 2016-01-16 00:00:01 +0000 UTC deployed chickadee-1.0.0 0.0.1 +groot default 1 2016-01-16 00:00:01 +0000 UTC uninstalled chickadee-1.0.0 0.0.1 +gamora default 1 2016-01-16 00:00:01 +0000 UTC superseded chickadee-1.0.0 0.0.1 +drax default 1 2016-01-16 00:00:01 +0000 UTC uninstalling chickadee-1.0.0 0.0.1 +thanos default 1 2016-01-16 00:00:01 +0000 UTC pending-install chickadee-1.0.0 0.0.1 +rocket default 1 2016-01-16 00:00:02 +0000 UTC failed chickadee-1.0.0 0.0.1 +hummingbird default 1 2016-01-16 00:00:03 +0000 UTC deployed chickadee-1.0.0 0.0.1 +iguana default 2 2016-01-16 00:00:04 +0000 UTC deployed chickadee-1.0.0 0.0.1 diff --git a/pkg/cmd/testdata/output/list-all-max.txt b/pkg/cmd/testdata/output/list-all-max.txt new file mode 100644 index 000000000..922896391 --- /dev/null +++ b/pkg/cmd/testdata/output/list-all-max.txt @@ -0,0 +1,2 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION +drax default 1 2016-01-16 00:00:01 +0000 UTC uninstalling chickadee-1.0.0 0.0.1 diff --git a/pkg/cmd/testdata/output/list-all-no-headers.txt b/pkg/cmd/testdata/output/list-all-no-headers.txt new file mode 100644 index 000000000..33581d8c5 --- /dev/null +++ b/pkg/cmd/testdata/output/list-all-no-headers.txt @@ -0,0 +1,8 @@ +drax default 1 2016-01-16 00:00:01 +0000 UTC uninstalling chickadee-1.0.0 0.0.1 +gamora default 1 2016-01-16 00:00:01 +0000 UTC superseded chickadee-1.0.0 0.0.1 +groot default 1 2016-01-16 00:00:01 +0000 UTC uninstalled chickadee-1.0.0 0.0.1 +hummingbird default 1 2016-01-16 00:00:03 +0000 UTC deployed chickadee-1.0.0 0.0.1 +iguana default 2 2016-01-16 00:00:04 +0000 UTC deployed chickadee-1.0.0 0.0.1 +rocket default 1 2016-01-16 00:00:02 +0000 UTC failed chickadee-1.0.0 0.0.1 +starlord default 2 2016-01-16 00:00:01 +0000 UTC deployed chickadee-1.0.0 0.0.1 +thanos default 1 2016-01-16 00:00:01 +0000 UTC pending-install chickadee-1.0.0 0.0.1 diff --git a/pkg/cmd/testdata/output/list-all-offset.txt b/pkg/cmd/testdata/output/list-all-offset.txt new file mode 100644 index 000000000..e17fd7b00 --- /dev/null +++ b/pkg/cmd/testdata/output/list-all-offset.txt @@ -0,0 +1,8 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION +gamora default 1 2016-01-16 00:00:01 +0000 UTC superseded chickadee-1.0.0 0.0.1 +groot default 1 2016-01-16 00:00:01 +0000 UTC uninstalled chickadee-1.0.0 0.0.1 +hummingbird default 1 2016-01-16 00:00:03 +0000 UTC deployed chickadee-1.0.0 0.0.1 +iguana default 2 2016-01-16 00:00:04 +0000 UTC deployed chickadee-1.0.0 0.0.1 +rocket default 1 2016-01-16 00:00:02 +0000 UTC failed chickadee-1.0.0 0.0.1 +starlord default 2 2016-01-16 00:00:01 +0000 UTC deployed chickadee-1.0.0 0.0.1 +thanos default 1 2016-01-16 00:00:01 +0000 UTC pending-install chickadee-1.0.0 0.0.1 diff --git a/pkg/cmd/testdata/output/list-all-reverse.txt b/pkg/cmd/testdata/output/list-all-reverse.txt new file mode 100644 index 000000000..31bb3de96 --- /dev/null +++ b/pkg/cmd/testdata/output/list-all-reverse.txt @@ -0,0 +1,9 @@ +NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION +thanos default 1 2016-01-16 00:00:01 +0000 UTC pending-install chickadee-1.0.0 0.0.1 +starlord default 2 2016-01-16 00:00:01 +0000 UTC deployed chickadee-1.0.0 0.0.1 +rocket default 1 2016-01-16 00:00:02 +0000 UTC failed chickadee-1.0.0 0.0.1 +iguana default 2 2016-01-16 00:00:04 +0000 UTC deployed chickadee-1.0.0 0.0.1 +hummingbird default 1 2016-01-16 00:00:03 +0000 UTC deployed chickadee-1.0.0 0.0.1 +groot default 1 2016-01-16 00:00:01 +0000 UTC uninstalled chickadee-1.0.0 0.0.1 +gamora default 1 2016-01-16 00:00:01 +0000 UTC superseded chickadee-1.0.0 0.0.1 +drax default 1 2016-01-16 00:00:01 +0000 UTC uninstalling chickadee-1.0.0 0.0.1 diff --git a/pkg/cmd/testdata/output/list-all-short-json.txt b/pkg/cmd/testdata/output/list-all-short-json.txt new file mode 100644 index 000000000..6dac52c43 --- /dev/null +++ b/pkg/cmd/testdata/output/list-all-short-json.txt @@ -0,0 +1 @@ +["drax","gamora","groot","hummingbird","iguana","rocket","starlord","thanos"] diff --git a/pkg/cmd/testdata/output/list-all-short-yaml.txt b/pkg/cmd/testdata/output/list-all-short-yaml.txt new file mode 100644 index 000000000..2ae0e88ad --- /dev/null +++ b/pkg/cmd/testdata/output/list-all-short-yaml.txt @@ -0,0 +1,8 @@ +- drax +- gamora +- groot +- hummingbird +- iguana +- rocket +- starlord +- thanos diff --git a/pkg/cmd/testdata/output/list-all-short.txt b/pkg/cmd/testdata/output/list-all-short.txt new file mode 100644 index 000000000..52871d8b4 --- /dev/null +++ b/pkg/cmd/testdata/output/list-all-short.txt @@ -0,0 +1,8 @@ +drax +gamora +groot +hummingbird +iguana +rocket +starlord +thanos