Repository: kubernetes/kubernetes
File: staging/src/k8s.io/kubectl/pkg/cmd/rollout/rollout_undo.go (Go)

Code before:
	Namespace        string
	LabelSelector    string
	EnforceNamespace bool
	RESTClientGetter genericclioptions.RESTClientGetter

	resource.FilenameOptions
	genericiooptions.IOStreams
}

var (
	undoLong = templates.LongDesc(i18n.T(`
		Roll back to a previous rollout.`))

	undoExample = templates.Examples(`
		# Roll back to the previous deployment
		kubectl rollout undo deployment/abc

		# Roll back to daemonset revision 3
		kubectl rollout undo daemonset/abc --to-revision=3

		# Roll back to the previous deployment with dry-run
		kubectl rollout undo --dry-run=server deployment/abc`)

	warningRollbackApplyManagedResource = "Warning: resource %[1]s was previously managed with 'kubectl apply'. " +
		"Rolling back will not update the %[2]s annotation, which may cause unexpected behavior on future 'kubectl apply' operations. " +
		"Consider using 'kubectl apply' with your previous configuration file instead of 'kubectl rollout undo'.\n"
)

// NewRolloutUndoOptions returns an initialized UndoOptions instance
func NewRolloutUndoOptions(streams genericiooptions.IOStreams) *UndoOptions {
	return &UndoOptions{
		PrintFlags: genericclioptions.NewPrintFlags("rolled back").WithTypeSetter(scheme.Scheme),
		IOStreams:  streams,
		ToRevision: int64(0),
	}
}

// NewCmdRolloutUndo returns a Command instance for the 'rollout undo' sub command
func NewCmdRolloutUndo(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
	o := NewRolloutUndoOptions(streams)

	validArgs := []string{"deployment", "daemonset", "statefulset"}

	cmd := &cobra.Command{
		Use:                   "undo (TYPE NAME | TYPE/NAME) [flags]",
		DisableFlagsInUseLine: true,
		Short:                 i18n.T("Undo a previous rollout"),
		Long:                  undoLong,
		Example:               undoExample,
		ValidArgsFunction:     completion.SpecifiedResourceTypeAndNameCompletionFunc(f, validArgs),
		Run: func(cmd *cobra.Command, args []string) {

Review comment (suggestion):
```suggestion
		"Consider using 'kubectl apply' with your previous configuration file instead.\n"
```

Code after:
	Namespace        string
	LabelSelector    string
	EnforceNamespace bool
	RESTClientGetter genericclioptions.RESTClientGetter
	CmdBaseName      string

	resource.FilenameOptions
	genericiooptions.IOStreams
}

var (
	undoLong = templates.LongDesc(i18n.T(`
		Roll back to a previous rollout.`))

	undoExample = templates.Examples(`
		# Roll back to the previous deployment
		kubectl rollout undo deployment/abc

		# Roll back to daemonset revision 3
		kubectl rollout undo daemonset/abc --to-revision=3

		# Roll back to the previous deployment with dry-run
		kubectl rollout undo --dry-run=server deployment/abc`)

	warningRollbackApplyManagedResource = "Warning: resource %[1]s was previously managed with '%[3]s apply'. " +
		"Rolling back will not update the %[2]s annotation, which may cause unexpected behavior on future '%[3]s apply' operations. " +
		"Consider using '%[3]s apply' with your previous configuration file instead.\n"
)

// NewRolloutUndoOptions returns an initialized UndoOptions instance
func NewRolloutUndoOptions(streams genericiooptions.IOStreams) *UndoOptions {
	return &UndoOptions{
		PrintFlags: genericclioptions.NewPrintFlags("rolled back").WithTypeSetter(scheme.Scheme),
		IOStreams:  streams,
		ToRevision: int64(0),
	}
}

// NewCmdRolloutUndo returns a Command instance for the 'rollout undo' sub command
func NewCmdRolloutUndo(parent string, f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
	o := NewRolloutUndoOptions(streams)
	o.CmdBaseName = parent

	validArgs := []string{"deployment", "daemonset", "statefulset"}

	cmd := &cobra.Command{
		Use:                   "undo (TYPE NAME | TYPE/NAME) [flags]",
		DisableFlagsInUseLine: true,
		Short:                 i18n.T("Undo a previous rollout"),
		Long:                  undoLong,
		Example:               undoExample,