mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #65880 from juanvallejo/jvallejo/fix-template-printer-rollout-cmds
Automatic merge from submit-queue (batch tested with PRs 64226, 65880). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. wire PrintFlags through rollout commands Binds PrintFlags to rollout commands. Adds tests ensuring --template printing is supported by rollout cmds. Fixes https://github.com/kubernetes/kubernetes/issues/65778 **Release note**: ```release-note NONE ``` cc @soltysh @deads2k
This commit is contained in:
commit
24ee75e265
@ -56,10 +56,10 @@ func NewCmdRollout(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobr
|
|||||||
Run: cmdutil.DefaultSubCommandRun(streams.Out),
|
Run: cmdutil.DefaultSubCommandRun(streams.Out),
|
||||||
}
|
}
|
||||||
// subcommands
|
// subcommands
|
||||||
cmd.AddCommand(NewCmdRolloutHistory(f, streams.Out))
|
cmd.AddCommand(NewCmdRolloutHistory(f, streams))
|
||||||
cmd.AddCommand(NewCmdRolloutPause(f, streams))
|
cmd.AddCommand(NewCmdRolloutPause(f, streams))
|
||||||
cmd.AddCommand(NewCmdRolloutResume(f, streams))
|
cmd.AddCommand(NewCmdRolloutResume(f, streams))
|
||||||
cmd.AddCommand(NewCmdRolloutUndo(f, streams.Out))
|
cmd.AddCommand(NewCmdRolloutUndo(f, streams))
|
||||||
cmd.AddCommand(NewCmdRolloutStatus(f, streams))
|
cmd.AddCommand(NewCmdRolloutStatus(f, streams))
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -18,16 +18,18 @@ package rollout
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/polymorphichelpers"
|
"k8s.io/kubernetes/pkg/kubectl/polymorphichelpers"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -42,8 +44,33 @@ var (
|
|||||||
kubectl rollout history daemonset/abc --revision=3`)
|
kubectl rollout history daemonset/abc --revision=3`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCmdRolloutHistory(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
type RolloutHistoryOptions struct {
|
||||||
options := &resource.FilenameOptions{}
|
PrintFlags *genericclioptions.PrintFlags
|
||||||
|
ToPrinter func(string) (printers.ResourcePrinter, error)
|
||||||
|
|
||||||
|
Revision int64
|
||||||
|
|
||||||
|
Builder func() *resource.Builder
|
||||||
|
Resources []string
|
||||||
|
Namespace string
|
||||||
|
EnforceNamespace bool
|
||||||
|
|
||||||
|
HistoryViewer polymorphichelpers.HistoryViewerFunc
|
||||||
|
RESTClientGetter genericclioptions.RESTClientGetter
|
||||||
|
|
||||||
|
resource.FilenameOptions
|
||||||
|
genericclioptions.IOStreams
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRolloutHistoryOptions(streams genericclioptions.IOStreams) *RolloutHistoryOptions {
|
||||||
|
return &RolloutHistoryOptions{
|
||||||
|
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme),
|
||||||
|
IOStreams: streams,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCmdRolloutHistory(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
|
o := NewRolloutHistoryOptions(streams)
|
||||||
|
|
||||||
validArgs := []string{"deployment", "daemonset", "statefulset"}
|
validArgs := []string{"deployment", "daemonset", "statefulset"}
|
||||||
|
|
||||||
@ -54,42 +81,65 @@ func NewCmdRolloutHistory(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
Long: history_long,
|
Long: history_long,
|
||||||
Example: history_example,
|
Example: history_example,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmdutil.CheckErr(RunHistory(f, cmd, out, args, options))
|
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||||
|
cmdutil.CheckErr(o.Run())
|
||||||
},
|
},
|
||||||
ValidArgs: validArgs,
|
ValidArgs: validArgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().Int64("revision", 0, "See the details, including podTemplate of the revision specified")
|
cmd.Flags().Int64Var(&o.Revision, "revision", o.Revision, "See the details, including podTemplate of the revision specified")
|
||||||
|
|
||||||
usage := "identifying the resource to get from a server."
|
usage := "identifying the resource to get from a server."
|
||||||
cmdutil.AddFilenameOptionFlags(cmd, options, usage)
|
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
||||||
|
|
||||||
|
o.PrintFlags.AddFlags(cmd)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunHistory(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []string, options *resource.FilenameOptions) error {
|
func (o *RolloutHistoryOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(options.Filenames) {
|
o.Resources = args
|
||||||
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
|
|
||||||
}
|
|
||||||
revision := cmdutil.GetFlagInt64(cmd, "revision")
|
|
||||||
if revision < 0 {
|
|
||||||
return fmt.Errorf("revision must be a positive integer: %v", revision)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
|
var err error
|
||||||
if err != nil {
|
if o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
r := f.NewBuilder().
|
o.ToPrinter = func(operation string) (printers.ResourcePrinter, error) {
|
||||||
|
o.PrintFlags.NamePrintFlags.Operation = operation
|
||||||
|
return o.PrintFlags.ToPrinter()
|
||||||
|
}
|
||||||
|
|
||||||
|
o.HistoryViewer = polymorphichelpers.HistoryViewerFn
|
||||||
|
o.RESTClientGetter = f
|
||||||
|
o.Builder = f.NewBuilder
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *RolloutHistoryOptions) Validate() error {
|
||||||
|
if len(o.Resources) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||||
|
return fmt.Errorf("Required resource not specified.")
|
||||||
|
}
|
||||||
|
if o.Revision < 0 {
|
||||||
|
return fmt.Errorf("revision must be a positive integer: %v", o.Revision)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *RolloutHistoryOptions) Run() error {
|
||||||
|
|
||||||
|
r := o.Builder().
|
||||||
WithScheme(legacyscheme.Scheme).
|
WithScheme(legacyscheme.Scheme).
|
||||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||||
FilenameParam(enforceNamespace, options).
|
FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
|
||||||
ResourceTypeOrNameArgs(true, args...).
|
ResourceTypeOrNameArgs(true, o.Resources...).
|
||||||
ContinueOnError().
|
ContinueOnError().
|
||||||
Latest().
|
Latest().
|
||||||
Flatten().
|
Flatten().
|
||||||
Do()
|
Do()
|
||||||
err = r.Err()
|
if err := r.Err(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,22 +147,27 @@ func RunHistory(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []str
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
mapping := info.ResourceMapping()
|
mapping := info.ResourceMapping()
|
||||||
historyViewer, err := polymorphichelpers.HistoryViewerFn(f, mapping)
|
historyViewer, err := o.HistoryViewer(o.RESTClientGetter, mapping)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
historyInfo, err := historyViewer.ViewHistory(info.Namespace, info.Name, revision)
|
historyInfo, err := historyViewer.ViewHistory(info.Namespace, info.Name, o.Revision)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
header := fmt.Sprintf("%s %q", mapping.Resource.Resource, info.Name)
|
withRevision := ""
|
||||||
if revision > 0 {
|
if o.Revision > 0 {
|
||||||
header = fmt.Sprintf("%s with revision #%d", header, revision)
|
withRevision = fmt.Sprintf("with revision #%d", o.Revision)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "%s\n", header)
|
|
||||||
fmt.Fprintf(out, "%s\n", historyInfo)
|
printer, err := o.ToPrinter(fmt.Sprintf("%s\n%s", withRevision, historyInfo))
|
||||||
return nil
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -38,13 +38,16 @@ import (
|
|||||||
// PauseConfig is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
// PauseConfig 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()
|
// referencing the cmd.Flags()
|
||||||
type PauseConfig struct {
|
type PauseConfig struct {
|
||||||
resource.FilenameOptions
|
|
||||||
PrintFlags *genericclioptions.PrintFlags
|
PrintFlags *genericclioptions.PrintFlags
|
||||||
ToPrinter func(string) (printers.ResourcePrinter, error)
|
ToPrinter func(string) (printers.ResourcePrinter, error)
|
||||||
|
|
||||||
Pauser polymorphichelpers.ObjectPauserFunc
|
Pauser polymorphichelpers.ObjectPauserFunc
|
||||||
Infos []*resource.Info
|
Builder func() *resource.Builder
|
||||||
|
Namespace string
|
||||||
|
EnforceNamespace bool
|
||||||
|
Resources []string
|
||||||
|
|
||||||
|
resource.FilenameOptions
|
||||||
genericclioptions.IOStreams
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +82,7 @@ func NewCmdRolloutPause(f cmdutil.Factory, streams genericclioptions.IOStreams)
|
|||||||
Example: pause_example,
|
Example: pause_example,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
allErrs := []error{}
|
allErrs := []error{}
|
||||||
err := o.CompletePause(f, cmd, args)
|
err := o.Complete(f, cmd, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
allErrs = append(allErrs, err)
|
allErrs = append(allErrs, err)
|
||||||
}
|
}
|
||||||
@ -92,53 +95,64 @@ func NewCmdRolloutPause(f cmdutil.Factory, streams genericclioptions.IOStreams)
|
|||||||
ValidArgs: validArgs,
|
ValidArgs: validArgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
o.PrintFlags.AddFlags(cmd)
|
||||||
|
|
||||||
usage := "identifying the resource to get from a server."
|
usage := "identifying the resource to get from a server."
|
||||||
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *PauseConfig) CompletePause(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
func (o *PauseConfig) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||||
return cmdutil.UsageErrorf(cmd, "%s", cmd.Use)
|
return cmdutil.UsageErrorf(cmd, "%s", cmd.Use)
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Pauser = polymorphichelpers.ObjectPauserFn
|
o.Pauser = polymorphichelpers.ObjectPauserFn
|
||||||
|
|
||||||
cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
|
var err error
|
||||||
if err != nil {
|
if o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
r := f.NewBuilder().
|
o.Resources = args
|
||||||
WithScheme(legacyscheme.Scheme).
|
o.Builder = f.NewBuilder
|
||||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
|
||||||
FilenameParam(enforceNamespace, &o.FilenameOptions).
|
|
||||||
ResourceTypeOrNameArgs(true, args...).
|
|
||||||
ContinueOnError().
|
|
||||||
Latest().
|
|
||||||
Flatten().
|
|
||||||
Do()
|
|
||||||
err = r.Err()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
o.ToPrinter = func(operation string) (printers.ResourcePrinter, error) {
|
o.ToPrinter = func(operation string) (printers.ResourcePrinter, error) {
|
||||||
o.PrintFlags.NamePrintFlags.Operation = operation
|
o.PrintFlags.NamePrintFlags.Operation = operation
|
||||||
return o.PrintFlags.ToPrinter()
|
return o.PrintFlags.ToPrinter()
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Infos, err = r.Infos()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o PauseConfig) RunPause() error {
|
func (o PauseConfig) RunPause() error {
|
||||||
|
r := o.Builder().
|
||||||
|
WithScheme(legacyscheme.Scheme).
|
||||||
|
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||||
|
FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
|
||||||
|
ResourceTypeOrNameArgs(true, o.Resources...).
|
||||||
|
ContinueOnError().
|
||||||
|
Latest().
|
||||||
|
Flatten().
|
||||||
|
Do()
|
||||||
|
if err := r.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
allErrs := []error{}
|
allErrs := []error{}
|
||||||
for _, patch := range set.CalculatePatches(o.Infos, cmdutil.InternalVersionJSONEncoder(), set.PatchFn(o.Pauser)) {
|
infos, err := r.Infos()
|
||||||
|
if err != nil {
|
||||||
|
// restore previous command behavior where
|
||||||
|
// an error caused by retrieving infos due to
|
||||||
|
// at least a single broken object did not result
|
||||||
|
// in an immediate return, but rather an overall
|
||||||
|
// aggregation of errors.
|
||||||
|
allErrs = append(allErrs, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, patch := range set.CalculatePatches(infos, cmdutil.InternalVersionJSONEncoder(), set.PatchFn(o.Pauser)) {
|
||||||
info := patch.Info
|
info := patch.Info
|
||||||
|
|
||||||
if patch.Err != nil {
|
if patch.Err != nil {
|
||||||
resourceString := info.Mapping.Resource.Resource
|
resourceString := info.Mapping.Resource.Resource
|
||||||
if len(info.Mapping.Resource.Group) > 0 {
|
if len(info.Mapping.Resource.Group) > 0 {
|
||||||
|
@ -35,16 +35,20 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ResumeConfig is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
// ResumeOptions 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()
|
// referencing the cmd.Flags()
|
||||||
type ResumeConfig struct {
|
type ResumeOptions struct {
|
||||||
resource.FilenameOptions
|
|
||||||
PrintFlags *genericclioptions.PrintFlags
|
PrintFlags *genericclioptions.PrintFlags
|
||||||
ToPrinter func(string) (printers.ResourcePrinter, error)
|
ToPrinter func(string) (printers.ResourcePrinter, error)
|
||||||
|
|
||||||
Resumer polymorphichelpers.ObjectResumerFunc
|
Resources []string
|
||||||
Infos []*resource.Info
|
|
||||||
|
|
||||||
|
Builder func() *resource.Builder
|
||||||
|
Resumer polymorphichelpers.ObjectResumerFunc
|
||||||
|
Namespace string
|
||||||
|
EnforceNamespace bool
|
||||||
|
|
||||||
|
resource.FilenameOptions
|
||||||
genericclioptions.IOStreams
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,11 +65,15 @@ var (
|
|||||||
kubectl rollout resume deployment/nginx`)
|
kubectl rollout resume deployment/nginx`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCmdRolloutResume(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
func NewRolloutResumeOptions(streams genericclioptions.IOStreams) *ResumeOptions {
|
||||||
o := &ResumeConfig{
|
return &ResumeOptions{
|
||||||
PrintFlags: genericclioptions.NewPrintFlags("resumed").WithTypeSetter(scheme.Scheme),
|
PrintFlags: genericclioptions.NewPrintFlags("resumed").WithTypeSetter(scheme.Scheme),
|
||||||
IOStreams: streams,
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCmdRolloutResume(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
|
o := NewRolloutResumeOptions(streams)
|
||||||
|
|
||||||
validArgs := []string{"deployment"}
|
validArgs := []string{"deployment"}
|
||||||
|
|
||||||
@ -77,7 +85,7 @@ func NewCmdRolloutResume(f cmdutil.Factory, streams genericclioptions.IOStreams)
|
|||||||
Example: resume_example,
|
Example: resume_example,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
allErrs := []error{}
|
allErrs := []error{}
|
||||||
err := o.CompleteResume(f, cmd, args)
|
err := o.Complete(f, cmd, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
allErrs = append(allErrs, err)
|
allErrs = append(allErrs, err)
|
||||||
}
|
}
|
||||||
@ -92,17 +100,21 @@ func NewCmdRolloutResume(f cmdutil.Factory, streams genericclioptions.IOStreams)
|
|||||||
|
|
||||||
usage := "identifying the resource to get from a server."
|
usage := "identifying the resource to get from a server."
|
||||||
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
||||||
|
o.PrintFlags.AddFlags(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ResumeConfig) CompleteResume(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
func (o *ResumeOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||||
return cmdutil.UsageErrorf(cmd, "%s", cmd.Use)
|
return cmdutil.UsageErrorf(cmd, "%s", cmd.Use)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
o.Resources = args
|
||||||
|
|
||||||
o.Resumer = polymorphichelpers.ObjectResumerFn
|
o.Resumer = polymorphichelpers.ObjectResumerFn
|
||||||
|
|
||||||
cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
|
var err error
|
||||||
|
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -112,36 +124,37 @@ func (o *ResumeConfig) CompleteResume(f cmdutil.Factory, cmd *cobra.Command, arg
|
|||||||
return o.PrintFlags.ToPrinter()
|
return o.PrintFlags.ToPrinter()
|
||||||
}
|
}
|
||||||
|
|
||||||
r := f.NewBuilder().
|
o.Builder = f.NewBuilder
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o ResumeOptions) RunResume() error {
|
||||||
|
r := o.Builder().
|
||||||
WithScheme(legacyscheme.Scheme).
|
WithScheme(legacyscheme.Scheme).
|
||||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||||
FilenameParam(enforceNamespace, &o.FilenameOptions).
|
FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
|
||||||
ResourceTypeOrNameArgs(true, args...).
|
ResourceTypeOrNameArgs(true, o.Resources...).
|
||||||
ContinueOnError().
|
ContinueOnError().
|
||||||
Latest().
|
Latest().
|
||||||
Flatten().
|
Flatten().
|
||||||
Do()
|
Do()
|
||||||
err = r.Err()
|
if err := r.Err(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = r.Visit(func(info *resource.Info, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
o.Infos = append(o.Infos, info)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o ResumeConfig) RunResume() error {
|
|
||||||
allErrs := []error{}
|
allErrs := []error{}
|
||||||
for _, patch := range set.CalculatePatches(o.Infos, cmdutil.InternalVersionJSONEncoder(), set.PatchFn(o.Resumer)) {
|
infos, err := r.Infos()
|
||||||
|
if err != nil {
|
||||||
|
// restore previous command behavior where
|
||||||
|
// an error caused by retrieving infos due to
|
||||||
|
// at least a single broken object did not result
|
||||||
|
// in an immediate return, but rather an overall
|
||||||
|
// aggregation of errors.
|
||||||
|
allErrs = append(allErrs, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, patch := range set.CalculatePatches(infos, cmdutil.InternalVersionJSONEncoder(), set.PatchFn(o.Resumer)) {
|
||||||
info := patch.Info
|
info := patch.Info
|
||||||
|
|
||||||
if patch.Err != nil {
|
if patch.Err != nil {
|
||||||
@ -162,6 +175,7 @@ func (o ResumeConfig) RunResume() error {
|
|||||||
if err = printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out); err != nil {
|
if err = printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out); err != nil {
|
||||||
allErrs = append(allErrs, err)
|
allErrs = append(allErrs, err)
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err := resource.NewHelper(info.Client, info.Mapping).Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch)
|
obj, err := resource.NewHelper(info.Client, info.Mapping).Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch)
|
||||||
|
@ -23,13 +23,13 @@ import (
|
|||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
|
||||||
"k8s.io/kubernetes/pkg/kubectl"
|
"k8s.io/kubernetes/pkg/kubectl"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/polymorphichelpers"
|
"k8s.io/kubernetes/pkg/kubectl/polymorphichelpers"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||||
"k8s.io/kubernetes/pkg/util/interrupt"
|
"k8s.io/kubernetes/pkg/util/interrupt"
|
||||||
)
|
)
|
||||||
@ -51,8 +51,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type RolloutStatusOptions struct {
|
type RolloutStatusOptions struct {
|
||||||
FilenameOptions *resource.FilenameOptions
|
PrintFlags *genericclioptions.PrintFlags
|
||||||
genericclioptions.IOStreams
|
|
||||||
|
|
||||||
Namespace string
|
Namespace string
|
||||||
EnforceNamespace bool
|
EnforceNamespace bool
|
||||||
@ -62,12 +61,15 @@ type RolloutStatusOptions struct {
|
|||||||
Revision int64
|
Revision int64
|
||||||
|
|
||||||
StatusViewer func(*meta.RESTMapping) (kubectl.StatusViewer, error)
|
StatusViewer func(*meta.RESTMapping) (kubectl.StatusViewer, error)
|
||||||
|
Builder func() *resource.Builder
|
||||||
|
|
||||||
Builder *resource.Builder
|
FilenameOptions *resource.FilenameOptions
|
||||||
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRolloutStatusOptions(streams genericclioptions.IOStreams) *RolloutStatusOptions {
|
func NewRolloutStatusOptions(streams genericclioptions.IOStreams) *RolloutStatusOptions {
|
||||||
return &RolloutStatusOptions{
|
return &RolloutStatusOptions{
|
||||||
|
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme),
|
||||||
FilenameOptions: &resource.FilenameOptions{},
|
FilenameOptions: &resource.FilenameOptions{},
|
||||||
IOStreams: streams,
|
IOStreams: streams,
|
||||||
Watch: true,
|
Watch: true,
|
||||||
@ -97,11 +99,12 @@ func NewCmdRolloutStatus(f cmdutil.Factory, streams genericclioptions.IOStreams)
|
|||||||
cmdutil.AddFilenameOptionFlags(cmd, o.FilenameOptions, usage)
|
cmdutil.AddFilenameOptionFlags(cmd, o.FilenameOptions, usage)
|
||||||
cmd.Flags().BoolVarP(&o.Watch, "watch", "w", o.Watch, "Watch the status of the rollout until it's done.")
|
cmd.Flags().BoolVarP(&o.Watch, "watch", "w", o.Watch, "Watch the status of the rollout until it's done.")
|
||||||
cmd.Flags().Int64Var(&o.Revision, "revision", o.Revision, "Pin to a specific revision for showing its status. Defaults to 0 (last revision).")
|
cmd.Flags().Int64Var(&o.Revision, "revision", o.Revision, "Pin to a specific revision for showing its status. Defaults to 0 (last revision).")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *RolloutStatusOptions) Complete(f cmdutil.Factory, args []string) error {
|
func (o *RolloutStatusOptions) Complete(f cmdutil.Factory, args []string) error {
|
||||||
o.Builder = f.NewBuilder()
|
o.Builder = f.NewBuilder
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
|
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
|
||||||
@ -120,12 +123,17 @@ func (o *RolloutStatusOptions) Validate(cmd *cobra.Command, args []string) error
|
|||||||
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.FilenameOptions.Filenames) {
|
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.FilenameOptions.Filenames) {
|
||||||
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
|
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.Revision < 0 {
|
||||||
|
return fmt.Errorf("revision must be a positive integer: %v", o.Revision)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *RolloutStatusOptions) Run() error {
|
func (o *RolloutStatusOptions) Run() error {
|
||||||
r := o.Builder.
|
r := o.Builder().
|
||||||
WithScheme(legacyscheme.Scheme).
|
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||||
NamespaceParam(o.Namespace).DefaultNamespace().
|
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||||
FilenameParam(o.EnforceNamespace, o.FilenameOptions).
|
FilenameParam(o.EnforceNamespace, o.FilenameOptions).
|
||||||
ResourceTypeOrNameArgs(true, o.BuilderArgs...).
|
ResourceTypeOrNameArgs(true, o.BuilderArgs...).
|
||||||
@ -161,13 +169,8 @@ func (o *RolloutStatusOptions) Run() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
revision := o.Revision
|
|
||||||
if revision < 0 {
|
|
||||||
return fmt.Errorf("revision must be a positive integer: %v", revision)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if deployment's has finished the rollout
|
// check if deployment's has finished the rollout
|
||||||
status, done, err := statusViewer.Status(info.Namespace, info.Name, revision)
|
status, done, err := statusViewer.Status(info.Namespace, info.Name, o.Revision)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -192,7 +195,7 @@ func (o *RolloutStatusOptions) Run() error {
|
|||||||
return intr.Run(func() error {
|
return intr.Run(func() error {
|
||||||
_, err := watch.Until(0, w, func(e watch.Event) (bool, error) {
|
_, err := watch.Until(0, w, func(e watch.Event) (bool, error) {
|
||||||
// print deployment's status
|
// print deployment's status
|
||||||
status, done, err := statusViewer.Status(info.Namespace, info.Name, revision)
|
status, done, err := statusViewer.Status(info.Namespace, info.Name, o.Revision)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,11 @@ limitations under the License.
|
|||||||
package rollout
|
package rollout
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/polymorphichelpers"
|
"k8s.io/kubernetes/pkg/kubectl/polymorphichelpers"
|
||||||
|
|
||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
"k8s.io/kubernetes/pkg/kubectl"
|
|
||||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||||
@ -37,17 +34,19 @@ import (
|
|||||||
// UndoOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
// UndoOptions 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()
|
// referencing the cmd.Flags()
|
||||||
type UndoOptions struct {
|
type UndoOptions struct {
|
||||||
resource.FilenameOptions
|
|
||||||
|
|
||||||
PrintFlags *genericclioptions.PrintFlags
|
PrintFlags *genericclioptions.PrintFlags
|
||||||
ToPrinter func(string) (printers.ResourcePrinter, error)
|
ToPrinter func(string) (printers.ResourcePrinter, error)
|
||||||
|
|
||||||
Rollbackers []kubectl.Rollbacker
|
Builder func() *resource.Builder
|
||||||
Infos []*resource.Info
|
ToRevision int64
|
||||||
ToRevision int64
|
DryRun bool
|
||||||
DryRun bool
|
Resources []string
|
||||||
|
Namespace string
|
||||||
|
EnforceNamespace bool
|
||||||
|
RESTClientGetter genericclioptions.RESTClientGetter
|
||||||
|
|
||||||
Out io.Writer
|
resource.FilenameOptions
|
||||||
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -65,11 +64,16 @@ var (
|
|||||||
kubectl rollout undo --dry-run=true deployment/abc`)
|
kubectl rollout undo --dry-run=true deployment/abc`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCmdRolloutUndo(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
func NewRolloutUndoOptions(streams genericclioptions.IOStreams) *UndoOptions {
|
||||||
o := &UndoOptions{
|
return &UndoOptions{
|
||||||
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme),
|
PrintFlags: genericclioptions.NewPrintFlags("rolled back").WithTypeSetter(scheme.Scheme),
|
||||||
|
IOStreams: streams,
|
||||||
ToRevision: int64(0),
|
ToRevision: int64(0),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCmdRolloutUndo(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
|
o := NewRolloutUndoOptions(streams)
|
||||||
|
|
||||||
validArgs := []string{"deployment", "daemonset", "statefulset"}
|
validArgs := []string{"deployment", "daemonset", "statefulset"}
|
||||||
|
|
||||||
@ -81,7 +85,7 @@ func NewCmdRolloutUndo(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
Example: undo_example,
|
Example: undo_example,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
allErrs := []error{}
|
allErrs := []error{}
|
||||||
err := o.CompleteUndo(f, cmd, out, args)
|
err := o.Complete(f, cmd, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
allErrs = append(allErrs, err)
|
allErrs = append(allErrs, err)
|
||||||
}
|
}
|
||||||
@ -98,19 +102,20 @@ func NewCmdRolloutUndo(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
usage := "identifying the resource to get from a server."
|
usage := "identifying the resource to get from a server."
|
||||||
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
|
||||||
cmdutil.AddDryRunFlag(cmd)
|
cmdutil.AddDryRunFlag(cmd)
|
||||||
|
o.PrintFlags.AddFlags(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *UndoOptions) CompleteUndo(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []string) error {
|
func (o *UndoOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(o.Filenames) {
|
||||||
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
|
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Out = out
|
o.Resources = args
|
||||||
o.DryRun = cmdutil.GetDryRunFlag(cmd)
|
o.DryRun = cmdutil.GetDryRunFlag(cmd)
|
||||||
|
|
||||||
cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
|
var err error
|
||||||
if err != nil {
|
if o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,49 +127,47 @@ func (o *UndoOptions) CompleteUndo(f cmdutil.Factory, cmd *cobra.Command, out io
|
|||||||
return o.PrintFlags.ToPrinter()
|
return o.PrintFlags.ToPrinter()
|
||||||
}
|
}
|
||||||
|
|
||||||
r := f.NewBuilder().
|
o.RESTClientGetter = f
|
||||||
WithScheme(legacyscheme.Scheme).
|
o.Builder = f.NewBuilder
|
||||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
|
||||||
FilenameParam(enforceNamespace, &o.FilenameOptions).
|
|
||||||
ResourceTypeOrNameArgs(true, args...).
|
|
||||||
ContinueOnError().
|
|
||||||
Latest().
|
|
||||||
Flatten().
|
|
||||||
Do()
|
|
||||||
err = r.Err()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = r.Visit(func(info *resource.Info, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
rollbacker, err := polymorphichelpers.RollbackerFn(f, info.ResourceMapping())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
o.Infos = append(o.Infos, info)
|
|
||||||
o.Rollbackers = append(o.Rollbackers, rollbacker)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *UndoOptions) RunUndo() error {
|
func (o *UndoOptions) RunUndo() error {
|
||||||
allErrs := []error{}
|
r := o.Builder().
|
||||||
for ix, info := range o.Infos {
|
WithScheme(legacyscheme.Scheme).
|
||||||
result, err := o.Rollbackers[ix].Rollback(info.Object, nil, o.ToRevision, o.DryRun)
|
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||||
|
FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
|
||||||
|
ResourceTypeOrNameArgs(true, o.Resources...).
|
||||||
|
ContinueOnError().
|
||||||
|
Latest().
|
||||||
|
Flatten().
|
||||||
|
Do()
|
||||||
|
if err := r.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err := r.Visit(func(info *resource.Info, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
allErrs = append(allErrs, cmdutil.AddSourceToErr("undoing", info.Source, err))
|
return err
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
rollbacker, err := polymorphichelpers.RollbackerFn(o.RESTClientGetter, info.ResourceMapping())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := rollbacker.Rollback(info.Object, nil, o.ToRevision, o.DryRun)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
printer, err := o.ToPrinter(result)
|
printer, err := o.ToPrinter(result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
allErrs = append(allErrs, err)
|
return err
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out)
|
|
||||||
}
|
return printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out)
|
||||||
return utilerrors.NewAggregate(allErrs)
|
})
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (f *PrintFlags) ToPrinter() (printers.ResourcePrinter, error) {
|
|||||||
// to honoring the --template argument.
|
// to honoring the --template argument.
|
||||||
if f.TemplatePrinterFlags != nil && f.TemplatePrinterFlags.TemplateArgument != nil &&
|
if f.TemplatePrinterFlags != nil && f.TemplatePrinterFlags.TemplateArgument != nil &&
|
||||||
len(*f.TemplatePrinterFlags.TemplateArgument) > 0 &&
|
len(*f.TemplatePrinterFlags.TemplateArgument) > 0 &&
|
||||||
(len(outputFormat) == 0 || (f.outputDefaulted && !f.outputFlag.Changed)) {
|
(len(outputFormat) == 0 || (f.outputDefaulted && f.outputFlag != nil && !f.outputFlag.Changed)) {
|
||||||
outputFormat = "go-template"
|
outputFormat = "go-template"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ run_template_output_tests() {
|
|||||||
kube::test::if_has_string "${output_message}" 'cm:'
|
kube::test::if_has_string "${output_message}" 'cm:'
|
||||||
|
|
||||||
# check that "create deployment" command supports --template output
|
# check that "create deployment" command supports --template output
|
||||||
output_message=$(kubectl "${kube_flags[@]}" create deployment deploy --dry-run --image=nginx --template="{{ .metadata.name }}:")
|
output_message=$(kubectl "${kube_flags[@]}" create deployment deploy --image=nginx --template="{{ .metadata.name }}:")
|
||||||
kube::test::if_has_string "${output_message}" 'deploy:'
|
kube::test::if_has_string "${output_message}" 'deploy:'
|
||||||
|
|
||||||
# check that "create job" command supports --template output
|
# check that "create job" command supports --template output
|
||||||
@ -209,6 +209,22 @@ EOF
|
|||||||
output_message=$(kubectl "${kube_flags[@]}" config view)
|
output_message=$(kubectl "${kube_flags[@]}" config view)
|
||||||
kube::test::if_has_string "${output_message}" 'kind: Config'
|
kube::test::if_has_string "${output_message}" 'kind: Config'
|
||||||
|
|
||||||
|
# check that "rollout pause" supports --template output
|
||||||
|
output_message=$(kubectl "${kube_flags[@]}" rollout pause deploy/deploy --template="{{ .metadata.name }}:")
|
||||||
|
kube::test::if_has_string "${output_message}" 'deploy:'
|
||||||
|
|
||||||
|
# check that "rollout history" supports --template output
|
||||||
|
output_message=$(kubectl "${kube_flags[@]}" rollout history deploy/deploy --template="{{ .metadata.name }}:")
|
||||||
|
kube::test::if_has_string "${output_message}" 'deploy:'
|
||||||
|
|
||||||
|
# check that "rollout resume" supports --template output
|
||||||
|
output_message=$(kubectl "${kube_flags[@]}" rollout resume deploy/deploy --template="{{ .metadata.name }}:")
|
||||||
|
kube::test::if_has_string "${output_message}" 'deploy:'
|
||||||
|
|
||||||
|
# check that "rollout undo" supports --template output
|
||||||
|
output_message=$(kubectl "${kube_flags[@]}" rollout undo deploy/deploy --template="{{ .metadata.name }}:")
|
||||||
|
kube::test::if_has_string "${output_message}" 'deploy:'
|
||||||
|
|
||||||
# check that "config view" command supports --template output
|
# check that "config view" command supports --template output
|
||||||
# and that commands that set a default output (yaml in this case),
|
# and that commands that set a default output (yaml in this case),
|
||||||
# default to "go-template" as their output format when a --template
|
# default to "go-template" as their output format when a --template
|
||||||
@ -227,6 +243,7 @@ EOF
|
|||||||
kubectl delete rc cassandra "${kube_flags[@]}"
|
kubectl delete rc cassandra "${kube_flags[@]}"
|
||||||
kubectl delete clusterrole myclusterrole "${kube_flags[@]}"
|
kubectl delete clusterrole myclusterrole "${kube_flags[@]}"
|
||||||
kubectl delete clusterrolebinding foo "${kube_flags[@]}"
|
kubectl delete clusterrolebinding foo "${kube_flags[@]}"
|
||||||
|
kubectl delete deployment deploy "${kube_flags[@]}"
|
||||||
|
|
||||||
set +o nounset
|
set +o nounset
|
||||||
set +o errexit
|
set +o errexit
|
||||||
|
Loading…
Reference in New Issue
Block a user