mirror of
https://github.com/helm/helm.git
synced 2026-08-09 01:21:20 +00:00
fix(list): scrub list returned from .List()
This way only the latest release is displayed with `helm list`. Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
This commit is contained in:
1
cmd/helm/testdata/output/list-all.txt
vendored
1
cmd/helm/testdata/output/list-all.txt
vendored
@@ -5,6 +5,5 @@ groot default 1 2016-01-16 00:00:01 +0000 UTC uninstalled chi
|
||||
hummingbird default 1 2016-01-16 00:00:03 +0000 UTC deployed chickadee-1.0.0
|
||||
iguana default 2 2016-01-16 00:00:04 +0000 UTC deployed chickadee-1.0.0
|
||||
rocket default 1 2016-01-16 00:00:02 +0000 UTC failed chickadee-1.0.0
|
||||
starlord default 1 2016-01-16 00:00:01 +0000 UTC superseded chickadee-1.0.0
|
||||
starlord default 2 2016-01-16 00:00:01 +0000 UTC deployed chickadee-1.0.0
|
||||
thanos default 1 2016-01-16 00:00:01 +0000 UTC pending-install chickadee-1.0.0
|
||||
|
||||
@@ -171,6 +171,8 @@ func (l *List) Run() ([]*release.Release, error) {
|
||||
return results, nil
|
||||
}
|
||||
|
||||
results = filterList(results)
|
||||
|
||||
// Unfortunately, we have to sort before truncating, which can incur substantial overhead
|
||||
l.sort(results)
|
||||
|
||||
@@ -218,6 +220,30 @@ func (l *List) sort(rels []*release.Release) {
|
||||
}
|
||||
}
|
||||
|
||||
// filterList returns a list scrubbed of old releases.
|
||||
func filterList(rels []*release.Release) []*release.Release {
|
||||
idx := map[string]int{}
|
||||
|
||||
for _, r := range rels {
|
||||
name, version := r.Name, r.Version
|
||||
if max, ok := idx[name]; ok {
|
||||
// check if we have a greater version already
|
||||
if max > version {
|
||||
continue
|
||||
}
|
||||
}
|
||||
idx[name] = version
|
||||
}
|
||||
|
||||
uniq := make([]*release.Release, 0, len(idx))
|
||||
for _, r := range rels {
|
||||
if idx[r.Name] == r.Version {
|
||||
uniq = append(uniq, r)
|
||||
}
|
||||
}
|
||||
return uniq
|
||||
}
|
||||
|
||||
// setStateMask calculates the state mask based on parameters.
|
||||
func (l *List) SetStateMask() {
|
||||
if l.All {
|
||||
|
||||
Reference in New Issue
Block a user