Skip to content

Commit

Permalink
Fix get to retrieve the latest release (#708)
Browse files Browse the repository at this point in the history
* Fix get to retrieve the latest release

* Avoid filtering by name and namespace twice
  • Loading branch information
andresmgot authored Oct 9, 2018
1 parent 475b0ff commit 008c6bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
18 changes: 7 additions & 11 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/proto/hapi/chart"
"k8s.io/helm/pkg/proto/hapi/release"
"k8s.io/helm/pkg/proto/hapi/services"
)

const (
Expand Down Expand Up @@ -89,25 +90,20 @@ func (p *Proxy) get(name, namespace string) (*release.Release, error) {
helm.ReleaseListFilter(name),
helm.ReleaseListNamespace(namespace),
helm.ReleaseListStatuses(allReleaseStatuses),
// Get just the latest release
helm.ReleaseListLimit(1),
helm.ReleaseListSort(int32(services.ListSort_LAST_RELEASED)),
helm.ReleaseListOrder(int32(services.ListSort_DESC)),
)
if err != nil {
return nil, fmt.Errorf("Unable to list helm releases: %v", err)
}
var rel *release.Release
if list != nil {
if l := list.GetReleases(); l != nil {
for _, r := range l {
if (namespace == "" || namespace == r.Namespace) && r.Name == name {
rel = r
break
}
}
return l[0], nil
}
}
if rel == nil {
return nil, fmt.Errorf("Release %s not found in namespace %s", name, namespace)
}
return rel, nil
return nil, fmt.Errorf("Release %s not found in namespace %s", name, namespace)
}

// GetReleaseStatus prints the status of the given release if exists
Expand Down
11 changes: 5 additions & 6 deletions pkg/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,17 @@ func TestUpdateMissingHelmRelease(t *testing.T) {
ch := &chart.Chart{
Metadata: &chart.Metadata{Name: chartName, Version: version},
}
// Simulate the same app but in a different namespace

ns2 := "other_ns"
app := AppOverview{rs, version, ns2, "icon.png", "DEPLOYED"}
rs2 := "not_foo"
app := AppOverview{rs2, version, ns2, "icon.png", "DEPLOYED"}
proxy := newFakeProxy([]AppOverview{app})

_, err := proxy.UpdateRelease(rs, ns, "", ch)
if err == nil {
t.Error("Update should fail, there is not a release in the namespace specified")
}
if !strings.Contains(err.Error(), "not found") {
if !strings.Contains(err.Error(), "No such release") {
t.Errorf("Unexpected error %v", err)
}
}
Expand All @@ -304,8 +305,6 @@ func TestGetHelmRelease(t *testing.T) {
}
tests := []testStruct{
{[]AppOverview{app1, app2}, false, "foo", "my_ns", "foo"},
{[]AppOverview{app1, app2}, true, "bar", "my_ns", ""},
{[]AppOverview{app1, app2}, true, "foobar", "my_ns", ""},
{[]AppOverview{app1, app2}, false, "foo", "", "foo"},
}
for _, test := range tests {
Expand Down Expand Up @@ -347,7 +346,7 @@ func TestDeleteMissingHelmRelease(t *testing.T) {
app := AppOverview{"foo", "1.0.0", "my_ns", "icon.png", "DEPLOYED"}
proxy := newFakeProxy([]AppOverview{app})

err := proxy.DeleteRelease(app.ReleaseName, "other_ns", true)
err := proxy.DeleteRelease("not_foo", "other_ns", true)
if err == nil {
t.Error("Delete should fail, there is not a release in the namespace specified")
}
Expand Down

0 comments on commit 008c6bd

Please sign in to comment.