mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
deprecate and disconnect --output-version
This commit is contained in:
parent
f07112f78a
commit
d3da1d102d
@ -79,9 +79,7 @@ func NewCmdConfigView(out io.Writer, ConfigAccess clientcmd.ConfigAccess) *cobra
|
|||||||
|
|
||||||
printer, _, err := cmdutil.PrinterForCommand(cmd)
|
printer, _, err := cmdutil.PrinterForCommand(cmd)
|
||||||
cmdutil.CheckErr(err)
|
cmdutil.CheckErr(err)
|
||||||
version, err := cmdutil.OutputVersion(cmd, &latest.ExternalVersion)
|
printer = kubectl.NewVersionedPrinter(printer, latest.Scheme, latest.ExternalVersion)
|
||||||
cmdutil.CheckErr(err)
|
|
||||||
printer = kubectl.NewVersionedPrinter(printer, latest.Scheme, version)
|
|
||||||
|
|
||||||
cmdutil.CheckErr(options.Run(out, printer))
|
cmdutil.CheckErr(options.Run(out, printer))
|
||||||
},
|
},
|
||||||
|
@ -80,8 +80,9 @@ func NewCmdConvert(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
cmdutil.AddFilenameOptionFlags(cmd, &options.FilenameOptions, usage)
|
cmdutil.AddFilenameOptionFlags(cmd, &options.FilenameOptions, usage)
|
||||||
cmd.MarkFlagRequired("filename")
|
cmd.MarkFlagRequired("filename")
|
||||||
cmdutil.AddValidateFlags(cmd)
|
cmdutil.AddValidateFlags(cmd)
|
||||||
cmdutil.AddPrinterFlags(cmd)
|
cmdutil.AddNonDeprecatedPrinterFlags(cmd)
|
||||||
cmd.Flags().BoolVar(&options.local, "local", true, "If true, convert will NOT try to contact api-server but run locally.")
|
cmd.Flags().BoolVar(&options.local, "local", true, "If true, convert will NOT try to contact api-server but run locally.")
|
||||||
|
cmd.Flags().String("output-version", "", "Output the formatted object with the given group version (for ex: 'extensions/v1beta1').")
|
||||||
cmdutil.AddInclude3rdPartyFlags(cmd)
|
cmdutil.AddInclude3rdPartyFlags(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -100,9 +101,24 @@ type ConvertOptions struct {
|
|||||||
outputVersion schema.GroupVersion
|
outputVersion schema.GroupVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// outputVersion returns the preferred output version for generic content (JSON, YAML, or templates)
|
||||||
|
// defaultVersion is never mutated. Nil simply allows clean passing in common usage from client.Config
|
||||||
|
func outputVersion(cmd *cobra.Command, defaultVersion *schema.GroupVersion) (schema.GroupVersion, error) {
|
||||||
|
outputVersionString := cmdutil.GetFlagString(cmd, "output-version")
|
||||||
|
if len(outputVersionString) == 0 {
|
||||||
|
if defaultVersion == nil {
|
||||||
|
return schema.GroupVersion{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return *defaultVersion, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return schema.ParseGroupVersion(outputVersionString)
|
||||||
|
}
|
||||||
|
|
||||||
// Complete collects information required to run Convert command from command line.
|
// Complete collects information required to run Convert command from command line.
|
||||||
func (o *ConvertOptions) Complete(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) (err error) {
|
func (o *ConvertOptions) Complete(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) (err error) {
|
||||||
o.outputVersion, err = cmdutil.OutputVersion(cmd, &api.Registry.EnabledVersionsForGroup(api.GroupName)[0])
|
o.outputVersion, err = outputVersion(cmd, &api.Registry.EnabledVersionsForGroup(api.GroupName)[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -117,9 +117,6 @@ func NewCmdEdit(f cmdutil.Factory, out, errOut io.Writer) *cobra.Command {
|
|||||||
cmdutil.AddFilenameOptionFlags(cmd, options, usage)
|
cmdutil.AddFilenameOptionFlags(cmd, options, usage)
|
||||||
cmdutil.AddValidateFlags(cmd)
|
cmdutil.AddValidateFlags(cmd)
|
||||||
cmd.Flags().StringP("output", "o", "yaml", "Output format. One of: yaml|json.")
|
cmd.Flags().StringP("output", "o", "yaml", "Output format. One of: yaml|json.")
|
||||||
cmd.Flags().String("output-version", "", "DEPRECATED: To edit using a specific API version, fully-qualify the resource, version, and group (for example: 'jobs.v1.batch/myjob').")
|
|
||||||
cmd.Flags().MarkDeprecated("output-version", "editing is now done using the resource exactly as fetched from the API. To edit using a specific API version, fully-qualify the resource, version, and group (for example: 'jobs.v1.batch/myjob').")
|
|
||||||
cmd.Flags().MarkHidden("output-version")
|
|
||||||
|
|
||||||
cmd.Flags().Bool("windows-line-endings", gruntime.GOOS == "windows", "Use Windows line-endings (default Unix line-endings)")
|
cmd.Flags().Bool("windows-line-endings", gruntime.GOOS == "windows", "Use Windows line-endings (default Unix line-endings)")
|
||||||
cmdutil.AddApplyAnnotationFlags(cmd)
|
cmdutil.AddApplyAnnotationFlags(cmd)
|
||||||
|
@ -78,14 +78,6 @@ func (f *ring1Factory) Object() (meta.RESTMapper, runtime.ObjectTyper) {
|
|||||||
mapper, err = NewShortcutExpander(mapper, discoveryClient)
|
mapper, err = NewShortcutExpander(mapper, discoveryClient)
|
||||||
CheckErr(err)
|
CheckErr(err)
|
||||||
|
|
||||||
// wrap with output preferences
|
|
||||||
cfg, err := f.clientAccessFactory.ClientConfigForVersion(nil)
|
|
||||||
checkErrWithPrefix("failed to get client config: ", err)
|
|
||||||
cmdApiVersion := schema.GroupVersion{}
|
|
||||||
if cfg.GroupVersion != nil {
|
|
||||||
cmdApiVersion = *cfg.GroupVersion
|
|
||||||
}
|
|
||||||
mapper = kubectl.OutputVersionMapper{RESTMapper: mapper, OutputVersions: []schema.GroupVersion{cmdApiVersion}}
|
|
||||||
return mapper, api.Scheme
|
return mapper, api.Scheme
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,25 +368,15 @@ func (f *ring1Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTM
|
|||||||
|
|
||||||
// Make sure we output versioned data for generic printers
|
// Make sure we output versioned data for generic printers
|
||||||
if generic {
|
if generic {
|
||||||
clientConfig, err := f.clientAccessFactory.ClientConfig()
|
if mapping == nil {
|
||||||
if err != nil {
|
return nil, fmt.Errorf("no serialization format found")
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
version, err := OutputVersion(cmd, clientConfig.GroupVersion)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if version.Empty() && mapping != nil {
|
|
||||||
version = mapping.GroupVersionKind.GroupVersion()
|
|
||||||
}
|
}
|
||||||
|
version := mapping.GroupVersionKind.GroupVersion()
|
||||||
if version.Empty() {
|
if version.Empty() {
|
||||||
return nil, fmt.Errorf("you must specify an output-version when using this output format")
|
return nil, fmt.Errorf("no serialization format found")
|
||||||
}
|
}
|
||||||
|
|
||||||
if mapping != nil {
|
printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, version, mapping.GroupVersionKind.GroupVersion())
|
||||||
printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, version, mapping.GroupVersionKind.GroupVersion())
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Some callers do not have "label-columns" so we can't use the GetFlagStringSlice() helper
|
// Some callers do not have "label-columns" so we can't use the GetFlagStringSlice() helper
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
"k8s.io/kubernetes/pkg/kubectl"
|
"k8s.io/kubernetes/pkg/kubectl"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||||
|
|
||||||
@ -31,8 +30,17 @@ import (
|
|||||||
|
|
||||||
// AddPrinterFlags adds printing related flags to a command (e.g. output format, no headers, template path)
|
// AddPrinterFlags adds printing related flags to a command (e.g. output format, no headers, template path)
|
||||||
func AddPrinterFlags(cmd *cobra.Command) {
|
func AddPrinterFlags(cmd *cobra.Command) {
|
||||||
|
AddNonDeprecatedPrinterFlags(cmd)
|
||||||
|
|
||||||
|
cmd.Flags().String("output-version", "", "DEPRECATED: To use a specific API version, fully-qualify the resource, version, and group (for example: 'jobs.v1.batch/myjob').")
|
||||||
|
cmd.Flags().MarkDeprecated("output-version", "the resource is used exactly as fetched from the API. To get a specific API version, fully-qualify the resource, version, and group (for example: 'jobs.v1.batch/myjob').")
|
||||||
|
cmd.Flags().MarkHidden("output-version")
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddNonDeprecatedPrinterFlags supports the conversion case which must logically have output-version. Once output-version
|
||||||
|
// is completely removed, this function can go away.
|
||||||
|
func AddNonDeprecatedPrinterFlags(cmd *cobra.Command) {
|
||||||
AddOutputFlags(cmd)
|
AddOutputFlags(cmd)
|
||||||
cmd.Flags().String("output-version", "", "Output the formatted object with the given group version (for ex: 'extensions/v1beta1').")
|
|
||||||
AddNoHeadersFlags(cmd)
|
AddNoHeadersFlags(cmd)
|
||||||
cmd.Flags().Bool("show-labels", false, "When printing, show all labels as the last column (default hide labels column)")
|
cmd.Flags().Bool("show-labels", false, "When printing, show all labels as the last column (default hide labels column)")
|
||||||
cmd.Flags().String("template", "", "Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].")
|
cmd.Flags().String("template", "", "Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].")
|
||||||
@ -95,21 +103,6 @@ func ValidateOutputArgs(cmd *cobra.Command) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutputVersion returns the preferred output version for generic content (JSON, YAML, or templates)
|
|
||||||
// defaultVersion is never mutated. Nil simply allows clean passing in common usage from client.Config
|
|
||||||
func OutputVersion(cmd *cobra.Command, defaultVersion *schema.GroupVersion) (schema.GroupVersion, error) {
|
|
||||||
outputVersionString := GetFlagString(cmd, "output-version")
|
|
||||||
if len(outputVersionString) == 0 {
|
|
||||||
if defaultVersion == nil {
|
|
||||||
return schema.GroupVersion{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return *defaultVersion, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return schema.ParseGroupVersion(outputVersionString)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrinterForCommand returns the default printer for this command.
|
// PrinterForCommand returns the default printer for this command.
|
||||||
// Requires that printer flags have been added to cmd (see AddPrinterFlags).
|
// Requires that printer flags have been added to cmd (see AddPrinterFlags).
|
||||||
func PrinterForCommand(cmd *cobra.Command) (kubectl.ResourcePrinter, bool, error) {
|
func PrinterForCommand(cmd *cobra.Command) (kubectl.ResourcePrinter, bool, error) {
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
)
|
)
|
||||||
@ -48,33 +47,6 @@ func makeImageList(spec *api.PodSpec) string {
|
|||||||
return strings.Join(listOfImages(spec), ",")
|
return strings.Join(listOfImages(spec), ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutputVersionMapper is a RESTMapper that will prefer mappings that
|
|
||||||
// correspond to a preferred output version (if feasible)
|
|
||||||
type OutputVersionMapper struct {
|
|
||||||
meta.RESTMapper
|
|
||||||
|
|
||||||
// output versions takes a list of preferred GroupVersions. Only the first
|
|
||||||
// hit for a given group will have effect. This allows different output versions
|
|
||||||
// depending upon the group of the kind being requested
|
|
||||||
OutputVersions []schema.GroupVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
// RESTMapping implements meta.RESTMapper by prepending the output version to the preferred version list.
|
|
||||||
func (m OutputVersionMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error) {
|
|
||||||
for _, preferredVersion := range m.OutputVersions {
|
|
||||||
if gk.Group == preferredVersion.Group {
|
|
||||||
mapping, err := m.RESTMapper.RESTMapping(gk, preferredVersion.Version)
|
|
||||||
if err == nil {
|
|
||||||
return mapping, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return m.RESTMapper.RESTMapping(gk, versions...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResourceShortcuts represents a structure that holds the information how to
|
// ResourceShortcuts represents a structure that holds the information how to
|
||||||
// transition from resource's shortcut to its full name.
|
// transition from resource's shortcut to its full name.
|
||||||
type ResourceShortcuts struct {
|
type ResourceShortcuts struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user