github.com/appscode/helm@v3.0.0-alpha.1+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  	"time"
    23  
    24  	"github.com/spf13/cobra"
    25  
    26  	"helm.sh/helm/cmd/helm/require"
    27  	"helm.sh/helm/pkg/action"
    28  )
    29  
    30  const rollbackDesc = `
    31  This command rolls back a release to a previous revision.
    32  
    33  The first argument of the rollback command is the name of a release, and the
    34  second is a revision (version) number. To see revision numbers, run
    35  'helm history RELEASE'.
    36  `
    37  
    38  func newRollbackCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
    39  	client := action.NewRollback(cfg)
    40  
    41  	cmd := &cobra.Command{
    42  		Use:   "rollback [RELEASE] [REVISION]",
    43  		Short: "roll back a release to a previous revision",
    44  		Long:  rollbackDesc,
    45  		Args:  require.ExactArgs(2),
    46  		RunE: func(cmd *cobra.Command, args []string) error {
    47  			_, err := client.Run(args[0])
    48  			if err != nil {
    49  				return err
    50  			}
    51  
    52  			fmt.Fprintf(out, "Rollback was a success! Happy Helming!\n")
    53  
    54  			return nil
    55  		},
    56  	}
    57  
    58  	f := cmd.Flags()
    59  	f.IntVarP(&client.Version, "version", "v", 0, "revision number to rollback to (default: rollback to previous release)")
    60  	f.BoolVar(&client.DryRun, "dry-run", false, "simulate a rollback")
    61  	f.BoolVar(&client.Recreate, "recreate-pods", false, "performs pods restart for the resource if applicable")
    62  	f.BoolVar(&client.Force, "force", false, "force resource update through delete/recreate if needed")
    63  	f.BoolVar(&client.DisableHooks, "no-hooks", false, "prevent hooks from running during rollback")
    64  	f.DurationVar(&client.Timeout, "timeout", 300*time.Second, "time to wait for any individual Kubernetes operation (like Jobs for hooks)")
    65  	f.BoolVar(&client.Wait, "wait", false, "if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful. It will wait for as long as --timeout")
    66  
    67  	return cmd
    68  }