github.com/aaronmell/helm@v3.0.0-beta.2+incompatible/cmd/helm/rollback.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "fmt" 21 "io" 22 "strconv" 23 "time" 24 25 "github.com/spf13/cobra" 26 27 "helm.sh/helm/cmd/helm/require" 28 "helm.sh/helm/pkg/action" 29 ) 30 31 const rollbackDesc = ` 32 This command rolls back a release to a previous revision. 33 34 The first argument of the rollback command is the name of a release, and the 35 second is a revision (version) number. If this argument is omitted, it will 36 roll back to the previous release. 37 38 To see revision numbers, run 'helm history RELEASE'. 39 ` 40 41 func newRollbackCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { 42 client := action.NewRollback(cfg) 43 44 cmd := &cobra.Command{ 45 Use: "rollback <RELEASE> [REVISION]", 46 Short: "roll back a release to a previous revision", 47 Long: rollbackDesc, 48 Args: require.MinimumNArgs(1), 49 RunE: func(cmd *cobra.Command, args []string) error { 50 if len(args) > 1 { 51 ver, err := strconv.Atoi(args[1]) 52 if err != nil { 53 return fmt.Errorf("could not convert revision to a number: %v", err) 54 } 55 client.Version = ver 56 } 57 58 if err := client.Run(args[0]); err != nil { 59 return err 60 } 61 62 fmt.Fprintf(out, "Rollback was a success! Happy Helming!\n") 63 return nil 64 }, 65 } 66 67 f := cmd.Flags() 68 f.BoolVar(&client.DryRun, "dry-run", false, "simulate a rollback") 69 f.BoolVar(&client.Recreate, "recreate-pods", false, "performs pods restart for the resource if applicable") 70 f.BoolVar(&client.Force, "force", false, "force resource update through delete/recreate if needed") 71 f.BoolVar(&client.DisableHooks, "no-hooks", false, "prevent hooks from running during rollback") 72 f.DurationVar(&client.Timeout, "timeout", 300*time.Second, "time to wait for any individual Kubernetes operation (like Jobs for hooks)") 73 f.BoolVar(&client.Wait, "wait", false, "if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready state before marking the release as successful. It will wait for as long as --timeout") 74 75 return cmd 76 }