Commit 4f4be2ec authored by Adam Reese's avatar Adam Reese

fix(tiller): delete all revisions with --purge

closes: #1395
parent 4899faa9
......@@ -803,6 +803,15 @@ func (s *releaseServer) execHook(hs []*release.Hook, name, namespace, hook strin
return nil
}
func (s *releaseServer) purgeReleases(rels ...*release.Release) error {
for _, rel := range rels {
if _, err := s.env.Releases.Delete(rel.Name, rel.Version); err != nil {
return err
}
}
return nil
}
func (s *releaseServer) UninstallRelease(c ctx.Context, req *services.UninstallReleaseRequest) (*services.UninstallReleaseResponse, error) {
if !checkClientVersion(c) {
return nil, errIncompatibleVersion
......@@ -829,7 +838,7 @@ func (s *releaseServer) UninstallRelease(c ctx.Context, req *services.UninstallR
// already marked deleted?
if rel.Info.Status.Code == release.Status_DELETED {
if req.Purge {
if _, err := s.env.Releases.Delete(rel.Name, rel.Version); err != nil {
if err := s.purgeReleases(rels...); err != nil {
log.Printf("uninstall: Failed to purge the release: %s", err)
return nil, err
}
......@@ -882,7 +891,7 @@ func (s *releaseServer) UninstallRelease(c ctx.Context, req *services.UninstallR
log.Printf("uninstall: Failed to store updated release: %s", err)
}
} else {
if _, err := s.env.Releases.Delete(rel.Name, rel.Version); err != nil {
if err := s.purgeReleases(rels...); err != nil {
log.Printf("uninstall: Failed to purge the release: %s", err)
}
}
......
......@@ -902,7 +902,11 @@ func TestUninstallRelease(t *testing.T) {
func TestUninstallPurgeRelease(t *testing.T) {
c := helm.NewContext()
rs := rsFixture()
rs.env.Releases.Create(releaseStub())
rel := releaseStub()
rs.env.Releases.Create(rel)
upgradedRel := upgradeReleaseVersion(rel)
rs.env.Releases.Update(rel)
rs.env.Releases.Create(upgradedRel)
req := &services.UninstallReleaseRequest{
Name: "angry-panda",
......@@ -922,13 +926,16 @@ func TestUninstallPurgeRelease(t *testing.T) {
t.Errorf("Expected status code to be DELETED, got %d", res.Release.Info.Status.Code)
}
if res.Release.Hooks[0].LastRun.Seconds == 0 {
t.Error("Expected LastRun to be greater than zero.")
}
if res.Release.Info.Deleted.Seconds <= 0 {
t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Seconds)
}
rels, err := rs.GetHistory(helm.NewContext(), &services.GetHistoryRequest{Name: "angry-panda"})
if err != nil {
t.Fatal(err)
}
if len(rels.Releases) != 0 {
t.Errorf("Expected no releases in storage, got %d", len(rels.Releases))
}
}
func TestUninstallPurgeDeleteRelease(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment