Commit 6860c47d authored by Adam Reese's avatar Adam Reese Committed by GitHub

Merge pull request #1248 from adamreese/feat/rollback-version

feat(*): add rollback to a release version
parents 47e425ba 1db7bd64
......@@ -183,7 +183,6 @@ message UpdateReleaseRequest {
hapi.chart.Config values = 3;
// dry_run, if true, will run through the release logic, but neither create
bool dry_run = 4;
// DisableHooks causes the server to skip running any hooks for the upgrade.
bool disable_hooks = 5;
}
......@@ -200,6 +199,8 @@ message RollbackReleaseRequest {
bool dry_run = 2;
// DisableHooks causes the server to skip running any hooks for the rollback
bool disable_hooks = 3;
// Version is the version of the release to deploy.
int32 version = 4;
}
// RollbackReleaseResponse is the response to an update request.
......
......@@ -73,7 +73,7 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
},
}
cmd.PersistentFlags().Int32Var(&get.version, "version", 0, "get the named release with version")
cmd.PersistentFlags().Int32Var(&get.version, "revision", 0, "get the named release with revision")
cmd.AddCommand(newGetValuesCmd(nil, out))
cmd.AddCommand(newGetManifestCmd(nil, out))
......@@ -81,7 +81,7 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
return cmd
}
var getTemplate = `VERSION: {{.Release.Version}}
var getTemplate = `REVISION: {{.Release.Version}}
RELEASED: {{.ReleaseDate}}
CHART: {{.Release.Chart.Metadata.Name}}-{{.Release.Chart.Metadata.Version}}
USER-SUPPLIED VALUES:
......
......@@ -29,7 +29,7 @@ func TestGetCmd(t *testing.T) {
name: "get with a release",
resp: releaseMock(&releaseOptions{name: "thomas-guide"}),
args: []string{"thomas-guide"},
expected: "VERSION: 1\nRELEASED: (.*)\nCHART: foo-0.1.0-beta.1\nUSER-SUPPLIED VALUES:\nname: \"value\"\nCOMPUTED VALUES:\nname: value\n\nHOOKS:\n---\n# pre-install-hook\n" + mockHookTemplate + "\nMANIFEST:",
expected: "REVISION: 1\nRELEASED: (.*)\nCHART: foo-0.1.0-beta.1\nUSER-SUPPLIED VALUES:\nname: \"value\"\nCOMPUTED VALUES:\nname: value\n\nHOOKS:\n---\n# pre-install-hook\n" + mockHookTemplate + "\nMANIFEST:",
},
{
name: "get requires release name arg",
......
......@@ -191,7 +191,7 @@ func (l *listCmd) statusCodes() []release.Status_Code {
func formatList(rels []*release.Release) string {
table := uitable.New()
table.MaxColWidth = 30
table.AddRow("NAME", "VERSION", "UPDATED", "STATUS", "CHART")
table.AddRow("NAME", "REVISION", "UPDATED", "STATUS", "CHART")
for _, r := range rels {
c := fmt.Sprintf("%s-%s", r.Chart.Metadata.Name, r.Chart.Metadata.Version)
t := timeconv.String(r.Info.LastDeployed)
......
......@@ -45,7 +45,7 @@ func TestListCmd(t *testing.T) {
resp: []*release.Release{
releaseMock(&releaseOptions{name: "atlas"}),
},
expected: "NAME \tVERSION\tUPDATED \tSTATUS \tCHART \natlas\t1 \t(.*)\tDEPLOYED\tfoo-0.1.0-beta.1\n",
expected: "NAME \tREVISION\tUPDATED \tSTATUS \tCHART \natlas\t1 \t(.*)\tDEPLOYED\tfoo-0.1.0-beta.1\n",
},
{
name: "with a release, multiple flags",
......
......@@ -26,12 +26,13 @@ import (
)
const rollbackDesc = `
This command rolls back a release to the previous version.
This command rolls back a release to the previous revision.
The argument of the rollback command is the name of a release.
`
type rollbackCmd struct {
name string
version int32
dryRun bool
disableHooks bool
out io.Writer
......@@ -46,7 +47,7 @@ func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "rollback [RELEASE]",
Short: "roll back a release to the previous version",
Short: "roll back a release to a previous revision",
Long: rollbackDesc,
PersistentPreRunE: setupConnection,
RunE: func(cmd *cobra.Command, args []string) error {
......@@ -60,13 +61,19 @@ func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command {
}
f := cmd.Flags()
f.Int32Var(&rollback.version, "revision", 0, "revision to deploy")
f.BoolVar(&rollback.dryRun, "dry-run", false, "simulate a rollback")
f.BoolVar(&rollback.disableHooks, "no-hooks", false, "prevent hooks from running during rollback")
return cmd
}
func (r *rollbackCmd) run() error {
_, err := r.client.RollbackRelease(r.name, helm.RollbackDryRun(r.dryRun), helm.RollbackDisableHooks(r.disableHooks))
_, err := r.client.RollbackRelease(
r.name,
helm.RollbackDryRun(r.dryRun),
helm.RollbackDisableHooks(r.disableHooks),
helm.RollbackVersion(r.version),
)
if err != nil {
return prettyError(err)
}
......
......@@ -29,7 +29,12 @@ func TestRollbackCmd(t *testing.T) {
{
name: "rollback a release",
args: []string{"funny-honey"},
resp: nil,
flags: []string{"revision", "1"},
expected: "Rollback was a success! Happy Helming!",
},
{
name: "rollback a release without version",
args: []string{"funny-honey"},
expected: "Rollback was a success! Happy Helming!",
},
}
......
......@@ -60,7 +60,7 @@ func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command {
},
}
cmd.PersistentFlags().Int32Var(&status.version, "version", 0, "If set, display the status of the named release with version")
cmd.PersistentFlags().Int32Var(&status.version, "revision", 0, "If set, display the status of the named release with revision")
return cmd
}
......
......@@ -461,7 +461,17 @@ func (s *releaseServer) prepareRollback(req *services.RollbackReleaseRequest) (*
return nil, nil, err
}
previousRelease, err := s.env.Releases.Get(req.Name, currentRelease.Version-1)
v := req.Version
if v == 0 {
v = currentRelease.Version - 1
}
if v < 1 {
return nil, nil, errors.New("cannot rollback to version < 1")
}
log.Printf("rolling back %s to version %d", req.Name, v)
previousRelease, err := s.env.Releases.Get(req.Name, v)
if err != nil {
return nil, nil, err
}
......
......@@ -664,6 +664,27 @@ func TestRollbackReleaseNoHooks(t *testing.T) {
}
}
func TestRollbackWithReleaseVersion(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)
req := &services.RollbackReleaseRequest{
Name: rel.Name,
DisableHooks: true,
Version: 1,
}
_, err := rs.RollbackRelease(c, req)
if err != nil {
t.Fatalf("Failed rollback: %s", err)
}
}
func TestRollbackRelease(t *testing.T) {
c := helm.NewContext()
rs := rsFixture()
......
......@@ -196,6 +196,13 @@ func RollbackDryRun(dry bool) RollbackOption {
}
}
// RollbackVersion sets the version of the release to deploy.
func RollbackVersion(ver int32) RollbackOption {
return func(opts *options) {
opts.rollbackReq.Version = ver
}
}
// UpgradeDisableHooks will disable hooks for an upgrade operation.
func UpgradeDisableHooks(disable bool) UpdateOption {
return func(opts *options) {
......@@ -333,7 +340,7 @@ func (o *options) rpcRollbackRelease(rlsName string, rlc rls.ReleaseServiceClien
o.rollbackReq.DryRun = o.dryRun
o.rollbackReq.Name = rlsName
return rlc.RollbackRelease(context.TODO(), &o.rollbackReq)
return rlc.RollbackRelease(NewContext(), &o.rollbackReq)
}
// Executes tiller.GetReleaseStatus RPC.
......
This diff is collapsed.
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