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>
pull/6479/head
Matthew Fisher 6 years ago
parent d95a6246a4
commit 4971ed5077
No known key found for this signature in database
GPG Key ID: 92AA783CBAAE8E3B

@ -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 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 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 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 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 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 return results, nil
} }
results = filterList(results)
// Unfortunately, we have to sort before truncating, which can incur substantial overhead // Unfortunately, we have to sort before truncating, which can incur substantial overhead
l.sort(results) 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. // setStateMask calculates the state mask based on parameters.
func (l *List) SetStateMask() { func (l *List) SetStateMask() {
if l.All { if l.All {

Loading…
Cancel
Save