fix(rollback): fix revision argument not being handled

The revision argument that was mandatory to `helm rollback` was being ignored.

The only way to roll back to an older revision was to run `helm rollback RELEASE <insert anything here> --version REVISION`.

This change respects that argument and removes the `--version` flag, which was redundant.

Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
pull/6133/head
Matthew Fisher 5 years ago
parent 3cf6f0c8ef
commit d40ed3b5ad
No known key found for this signature in database
GPG Key ID: 92AA783CBAAE8E3B

@ -19,6 +19,7 @@ package main
import (
"fmt"
"io"
"strconv"
"time"
"github.com/spf13/cobra"
@ -31,32 +32,39 @@ const rollbackDesc = `
This command rolls back a release to a previous revision.
The first argument of the rollback command is the name of a release, and the
second is a revision (version) number. To see revision numbers, run
'helm history RELEASE'.
second is a revision (version) number. If this argument is omitted, it will
roll back to the previous release.
To see revision numbers, run 'helm history RELEASE'.
`
func newRollbackCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
client := action.NewRollback(cfg)
cmd := &cobra.Command{
Use: "rollback [RELEASE] [REVISION]",
Use: "rollback <RELEASE> [REVISION]",
Short: "roll back a release to a previous revision",
Long: rollbackDesc,
Args: require.ExactArgs(2),
Args: require.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
_, err := client.Run(args[0])
if err != nil {
if len(args) > 1 {
ver, err := strconv.Atoi(args[1])
if err != nil {
return fmt.Errorf("could not convert revision to a number: %v", err)
}
client.Version = ver
}
if _, err := client.Run(args[0]); err != nil {
return err
}
fmt.Fprintf(out, "Rollback was a success! Happy Helming!\n")
return nil
},
}
f := cmd.Flags()
f.IntVar(&client.Version, "version", 0, "revision number to rollback to (default: rollback to previous release)")
f.BoolVar(&client.DryRun, "dry-run", false, "simulate a rollback")
f.BoolVar(&client.Recreate, "recreate-pods", false, "performs pods restart for the resource if applicable")
f.BoolVar(&client.Force, "force", false, "force resource update through delete/recreate if needed")

@ -55,8 +55,13 @@ func TestRollbackCmd(t *testing.T) {
golden: "output/rollback-wait.txt",
rels: rels,
}, {
name: "rollback a release without revision",
cmd: "rollback funny-honey",
name: "rollback a release without revision",
cmd: "rollback funny-honey",
golden: "output/rollback-no-revision.txt",
rels: rels,
}, {
name: "rollback a release without release name",
cmd: "rollback",
golden: "output/rollback-no-args.txt",
rels: rels,
wantError: true,

@ -1,3 +1,3 @@
Error: "helm rollback" requires 2 arguments
Error: "helm rollback" requires at least 1 argument
Usage: helm rollback [RELEASE] [REVISION] [flags]
Usage: helm rollback <RELEASE> [REVISION] [flags]

@ -0,0 +1 @@
Rollback was a success! Happy Helming!
Loading…
Cancel
Save