Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(helm): filter helm list to print latest release #3335

Merged
merged 1 commit into from
Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion cmd/helm/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (l *listCmd) run() error {
fmt.Fprintf(l.out, "\tnext: %s\n", res.Next)
}

rels := res.Releases
rels := filterList(res.Releases)

if l.short {
for _, r := range rels {
Expand All @@ -168,6 +168,30 @@ func (l *listCmd) run() error {
return nil
}

// filterList returns a list scrubbed of old releases.
func filterList(rels []*release.Release) []*release.Release {
idx := map[string]int32{}

for _, r := range rels {
name, version := r.GetName(), r.GetVersion()
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.GetName()] == r.GetVersion() {
uniq = append(uniq, r)
}
}
return uniq
}

// statusCodes gets the list of status codes that are to be included in the results.
func (l *listCmd) statusCodes() []release.Status_Code {
if l.all {
Expand Down
8 changes: 8 additions & 0 deletions cmd/helm/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ func TestListCmd(t *testing.T) {
},
expected: "thomas-guide\nwild-idea\ncrazy-maps",
},
{
name: "with old releases",
resp: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_FAILED}),
},
expected: "thomas-guide",
},
}

var buf bytes.Buffer
Expand Down