added ability to handle custom release descriptions to tiller

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
pull/3825/head
Arash Deshmeh 7 years ago
parent 8389fe1d58
commit a32868e48b

@ -250,7 +250,11 @@ func (s *ReleaseServer) performRelease(r *release.Release, req *services.Install
}
r.Info.Status.Code = release.Status_DEPLOYED
r.Info.Description = "Install complete"
if req.Description == "" {
r.Info.Description = "Install complete"
} else {
r.Info.Description = req.Description
}
// This is a tricky case. The release has been created, but the result
// cannot be recorded. The truest thing to tell the user is that the
// release was created. However, the user will not be able to do anything

@ -495,3 +495,23 @@ func TestInstallRelease_WrongKubeVersion(t *testing.T) {
t.Errorf("Expected %q to contain %q", err.Error(), expect)
}
}
func TestInstallRelease_Description(t *testing.T) {
c := helm.NewContext()
rs := rsFixture()
rs.env.Releases.Create(releaseStub())
customDescription := "foo"
req := &services.InstallReleaseRequest{
Chart: chartStub(),
Description: customDescription,
}
res, err := rs.InstallRelease(c, req)
if err != nil {
t.Errorf("Failed install: %s", err)
}
if desc := res.Release.Info.Description; desc != customDescription {
t.Errorf("Expected description %q. Got %q", customDescription, desc)
}
}

@ -86,6 +86,11 @@ func (s *ReleaseServer) prepareRollback(req *services.RollbackReleaseRequest) (*
return nil, nil, err
}
description := req.Description
if req.Description == "" {
description = fmt.Sprintf("Rollback to %d", previousVersion)
}
// Store a new release object with previous release's configuration
targetRelease := &release.Release{
Name: req.Name,
@ -101,7 +106,7 @@ func (s *ReleaseServer) prepareRollback(req *services.RollbackReleaseRequest) (*
},
// Because we lose the reference to previous version elsewhere, we set the
// message here, and only override it later if we experience failure.
Description: fmt.Sprintf("Rollback to %d", previousVersion),
Description: description,
},
Version: currentRelease.Version + 1,
Manifest: previousRelease.Manifest,

@ -252,3 +252,35 @@ func TestRollbackReleaseFailure(t *testing.T) {
t.Errorf("Expected SUPERSEDED status on previous Release version. Got %v", oldStatus)
}
}
func TestRollbackReleaseWithCustomDescription(t *testing.T) {
c := helm.NewContext()
rs := rsFixture()
rel := releaseStub()
rs.env.Releases.Create(rel)
upgradedRel := upgradeReleaseVersion(rel)
rs.env.Releases.Update(rel)
rs.env.Releases.Create(upgradedRel)
customDescription := "foo"
req := &services.RollbackReleaseRequest{
Name: rel.Name,
Description: customDescription,
}
res, err := rs.RollbackRelease(c, req)
if err != nil {
t.Fatalf("Failed rollback: %s", err)
}
if res.Release.Name == "" {
t.Errorf("Expected release name.")
}
if res.Release.Name != rel.Name {
t.Errorf("Updated release name does not match previous release name. Expected %s, got %s", rel.Name, res.Release.Name)
}
if res.Release.Info.Description != customDescription {
t.Errorf("Expected Description to be %q, got %q", customDescription, res.Release.Info.Description)
}
}

@ -97,7 +97,11 @@ func (s *ReleaseServer) UninstallRelease(c ctx.Context, req *services.UninstallR
}
rel.Info.Status.Code = release.Status_DELETED
rel.Info.Description = "Deletion complete"
if req.Description == "" {
rel.Info.Description = "Deletion complete"
} else {
rel.Info.Description = req.Description
}
if req.Purge {
s.Log("purge requested for %s", req.Name)

@ -176,3 +176,24 @@ func TestUninstallReleaseNoHooks(t *testing.T) {
t.Errorf("Expected LastRun to be zero, got %d.", res.Release.Hooks[0].LastRun.Seconds)
}
}
func TestUninstallReleaseCustomDescription(t *testing.T) {
c := helm.NewContext()
rs := rsFixture()
rs.env.Releases.Create(releaseStub())
customDescription := "foo"
req := &services.UninstallReleaseRequest{
Name: "angry-panda",
Description: "foo",
}
res, err := rs.UninstallRelease(c, req)
if err != nil {
t.Errorf("Failed uninstall: %s", err)
}
if res.Release.Info.Description != customDescription {
t.Errorf("Expected description to be %q, got %q", customDescription, res.Release.Info.Description)
}
}

@ -243,7 +243,11 @@ func (s *ReleaseServer) performUpdateForce(req *services.UpdateReleaseRequest) (
}
newRelease.Info.Status.Code = release.Status_DEPLOYED
newRelease.Info.Description = "Upgrade complete"
if req.Description == "" {
newRelease.Info.Description = "Upgrade complete"
} else {
newRelease.Info.Description = req.Description
}
s.recordRelease(newRelease, true)
return res, nil
@ -287,7 +291,11 @@ func (s *ReleaseServer) performUpdate(originalRelease, updatedRelease *release.R
s.recordRelease(originalRelease, true)
updatedRelease.Info.Status.Code = release.Status_DEPLOYED
updatedRelease.Info.Description = "Upgrade complete"
if req.Description == "" {
updatedRelease.Info.Description = "Upgrade complete"
} else {
updatedRelease.Info.Description = req.Description
}
return res, nil
}

@ -432,6 +432,55 @@ func TestUpdateReleaseNoChanges(t *testing.T) {
}
}
func TestUpdateReleaseCustomDescription(t *testing.T) {
c := helm.NewContext()
rs := rsFixture()
rel := releaseStub()
rs.env.Releases.Create(rel)
customDescription := "foo"
req := &services.UpdateReleaseRequest{
Name: rel.Name,
Chart: rel.GetChart(),
Description: customDescription,
}
res, err := rs.UpdateRelease(c, req)
if err != nil {
t.Fatalf("Failed updated: %s", err)
}
if res.Release.Info.Description != customDescription {
t.Errorf("Expected release description to be %q, got %q", customDescription, res.Release.Info.Description)
}
compareStoredAndReturnedRelease(t, *rs, *res)
}
func TestUpdateReleaseCustomDescription_Force(t *testing.T) {
c := helm.NewContext()
rs := rsFixture()
rel := releaseStub()
rs.env.Releases.Create(rel)
customDescription := "foo"
req := &services.UpdateReleaseRequest{
Name: rel.Name,
Chart: rel.GetChart(),
Force: true,
Description: customDescription,
}
res, err := rs.UpdateRelease(c, req)
if err != nil {
t.Fatalf("Failed updated: %s", err)
}
if res.Release.Info.Description != customDescription {
t.Errorf("Expected release description to be %q, got %q", customDescription, res.Release.Info.Description)
}
compareStoredAndReturnedRelease(t, *rs, *res)
}
func compareStoredAndReturnedRelease(t *testing.T, rs ReleaseServer, res services.UpdateReleaseResponse) *release.Release {
storedRelease, err := rs.env.Releases.Get(res.Release.Name, res.Release.Version)
if err != nil {

Loading…
Cancel
Save