mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Merge pull request #69150 from soltysh/issue69144
Fix panic in kubectl rollout commands
This commit is contained in:
commit
34860dafe2
@ -81,6 +81,7 @@ func NewCmdRolloutHistory(f cmdutil.Factory, streams genericclioptions.IOStreams
|
||||
Example: history_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.Run())
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
@ -118,7 +119,7 @@ func (o *RolloutHistoryOptions) Complete(f cmdutil.Factory, cmd *cobra.Command,
|
||||
|
||||
func (o *RolloutHistoryOptions) Validate() error {
|
||||
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||
return fmt.Errorf("Required resource not specified.")
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
if o.Revision < 0 {
|
||||
return fmt.Errorf("revision must be a positive integer: %v", o.Revision)
|
||||
|
@ -34,9 +34,9 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||
)
|
||||
|
||||
// PauseConfig is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
||||
// PauseOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
||||
// referencing the cmd.Flags()
|
||||
type PauseConfig struct {
|
||||
type PauseOptions struct {
|
||||
PrintFlags *genericclioptions.PrintFlags
|
||||
ToPrinter func(string) (printers.ResourcePrinter, error)
|
||||
|
||||
@ -66,7 +66,7 @@ var (
|
||||
)
|
||||
|
||||
func NewCmdRolloutPause(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||
o := &PauseConfig{
|
||||
o := &PauseOptions{
|
||||
PrintFlags: genericclioptions.NewPrintFlags("paused").WithTypeSetter(scheme.Scheme),
|
||||
IOStreams: streams,
|
||||
}
|
||||
@ -80,16 +80,9 @@ func NewCmdRolloutPause(f cmdutil.Factory, streams genericclioptions.IOStreams)
|
||||
Long: pause_long,
|
||||
Example: pause_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
allErrs := []error{}
|
||||
err := o.Complete(f, cmd, args)
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
err = o.RunPause()
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
cmdutil.CheckErr(utilerrors.Flatten(utilerrors.NewAggregate(allErrs)))
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.RunPause())
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
}
|
||||
@ -101,15 +94,12 @@ func NewCmdRolloutPause(f cmdutil.Factory, streams genericclioptions.IOStreams)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o *PauseConfig) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||
return cmdutil.UsageErrorf(cmd, "%s", cmd.Use)
|
||||
}
|
||||
|
||||
func (o *PauseOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
o.Pauser = polymorphichelpers.ObjectPauserFn
|
||||
|
||||
var err error
|
||||
if o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace(); err != nil {
|
||||
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -124,7 +114,14 @@ func (o *PauseConfig) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o PauseConfig) RunPause() error {
|
||||
func (o *PauseOptions) Validate() error {
|
||||
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o PauseOptions) RunPause() error {
|
||||
r := o.Builder().
|
||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||
|
@ -83,16 +83,9 @@ func NewCmdRolloutResume(f cmdutil.Factory, streams genericclioptions.IOStreams)
|
||||
Long: resume_long,
|
||||
Example: resume_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
allErrs := []error{}
|
||||
err := o.Complete(f, cmd, args)
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
err = o.RunResume()
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
cmdutil.CheckErr(utilerrors.Flatten(utilerrors.NewAggregate(allErrs)))
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.RunResume())
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
}
|
||||
@ -104,10 +97,6 @@ func NewCmdRolloutResume(f cmdutil.Factory, streams genericclioptions.IOStreams)
|
||||
}
|
||||
|
||||
func (o *ResumeOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||
return cmdutil.UsageErrorf(cmd, "%s", cmd.Use)
|
||||
}
|
||||
|
||||
o.Resources = args
|
||||
|
||||
o.Resumer = polymorphichelpers.ObjectResumerFn
|
||||
@ -128,6 +117,13 @@ func (o *ResumeOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *ResumeOptions) Validate() error {
|
||||
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o ResumeOptions) RunResume() error {
|
||||
r := o.Builder().
|
||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||
|
@ -102,7 +102,7 @@ func NewCmdRolloutStatus(f cmdutil.Factory, streams genericclioptions.IOStreams)
|
||||
Example: status_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(f, args))
|
||||
cmdutil.CheckErr(o.Validate(cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.Run())
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
@ -142,9 +142,9 @@ func (o *RolloutStatusOptions) Complete(f cmdutil.Factory, args []string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *RolloutStatusOptions) Validate(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.FilenameOptions.Filenames) {
|
||||
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
|
||||
func (o *RolloutStatusOptions) Validate() error {
|
||||
if len(o.BuilderArgs) == 0 && cmdutil.IsFilenameSliceEmpty(o.FilenameOptions.Filenames) {
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
|
||||
if o.Revision < 0 {
|
||||
|
@ -17,10 +17,11 @@ limitations under the License.
|
||||
package rollout
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/kubernetes/pkg/kubectl/polymorphichelpers"
|
||||
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions/resource"
|
||||
@ -84,16 +85,9 @@ func NewCmdRolloutUndo(f cmdutil.Factory, streams genericclioptions.IOStreams) *
|
||||
Long: undo_long,
|
||||
Example: undo_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
allErrs := []error{}
|
||||
err := o.Complete(f, cmd, args)
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
err = o.RunUndo()
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
cmdutil.CheckErr(utilerrors.Flatten(utilerrors.NewAggregate(allErrs)))
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.RunUndo())
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
}
|
||||
@ -107,10 +101,6 @@ func NewCmdRolloutUndo(f cmdutil.Factory, streams genericclioptions.IOStreams) *
|
||||
}
|
||||
|
||||
func (o *UndoOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
|
||||
}
|
||||
|
||||
o.Resources = args
|
||||
o.DryRun = cmdutil.GetDryRunFlag(cmd)
|
||||
|
||||
@ -133,6 +123,13 @@ func (o *UndoOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str
|
||||
return err
|
||||
}
|
||||
|
||||
func (o *UndoOptions) Validate() error {
|
||||
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||
return fmt.Errorf("required resource not specified")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *UndoOptions) RunUndo() error {
|
||||
r := o.Builder().
|
||||
WithScheme(legacyscheme.Scheme).
|
||||
|
Loading…
Reference in New Issue
Block a user