Merge pull request #6133 from bacongobbler/fixup-rollback-argument-logic

fix(rollback): fix revision argument not being handled
pull/6124/head
Matthew Fisher 5 years ago committed by GitHub
commit d360705c83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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