mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
kubectl: remove unnecessary internal->external conversion before PrintObj
This commit is contained in:
parent
879312205f
commit
68cea87cfd
@ -245,7 +245,7 @@ func (options *CertificateOptions) modifyCertificateCondition(builder *resource.
|
||||
}
|
||||
found++
|
||||
|
||||
return options.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), options.Out)
|
||||
return options.PrintObj(info.Object, options.Out)
|
||||
})
|
||||
if found == 0 {
|
||||
fmt.Fprintf(options.Out, "No resources found\n")
|
||||
|
@ -748,7 +748,7 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
|
||||
fmt.Fprintf(o.ErrOut, "error: %v\n", err)
|
||||
continue
|
||||
}
|
||||
printObj(cmdutil.AsDefaultVersionedOrOriginal(nodeInfo.Object, nodeInfo.Mapping), o.Out)
|
||||
printObj(nodeInfo.Object, o.Out)
|
||||
} else {
|
||||
if !o.DryRun {
|
||||
helper := resource.NewHelper(o.restClient, nodeInfo.Mapping)
|
||||
@ -774,7 +774,7 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
|
||||
fmt.Fprintf(o.ErrOut, "%v\n", err)
|
||||
continue
|
||||
}
|
||||
printObj(cmdutil.AsDefaultVersionedOrOriginal(nodeInfo.Object, nodeInfo.Mapping), o.Out)
|
||||
printObj(nodeInfo.Object, o.Out)
|
||||
}
|
||||
} else {
|
||||
printObj, err := o.ToPrinter("skipped")
|
||||
@ -782,7 +782,7 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
|
||||
fmt.Fprintf(o.ErrOut, "%v\n", err)
|
||||
continue
|
||||
}
|
||||
printObj(cmdutil.AsDefaultVersionedOrOriginal(nodeInfo.Object, nodeInfo.Mapping), o.Out)
|
||||
printObj(nodeInfo.Object, o.Out)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -403,10 +403,10 @@ func (o *RollingUpdateOptions) Run() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(oldRc, nil), oldRcData); err != nil {
|
||||
if err := printer.PrintObj(oldRc, oldRcData); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(newRc, nil), newRcData); err != nil {
|
||||
if err := printer.PrintObj(newRc, newRcData); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -455,7 +455,7 @@ func (o *RollingUpdateOptions) Run() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(newRc, nil), o.Out)
|
||||
return printer.PrintObj(newRc, o.Out)
|
||||
}
|
||||
|
||||
func findNewName(args []string, oldRc *corev1.ReplicationController) string {
|
||||
|
@ -168,6 +168,6 @@ func (o *RolloutHistoryOptions) Run() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out)
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
})
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ func (o PauseOptions) RunPause() error {
|
||||
allErrs = append(allErrs, err)
|
||||
continue
|
||||
}
|
||||
if err = printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out); err != nil {
|
||||
if err = printer.PrintObj(info.Object, o.Out); err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
continue
|
||||
@ -182,7 +182,7 @@ func (o PauseOptions) RunPause() error {
|
||||
allErrs = append(allErrs, err)
|
||||
continue
|
||||
}
|
||||
if err = printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out); err != nil {
|
||||
if err = printer.PrintObj(info.Object, o.Out); err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ func (o ResumeOptions) RunResume() error {
|
||||
allErrs = append(allErrs, err)
|
||||
continue
|
||||
}
|
||||
if err = printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out); err != nil {
|
||||
if err = printer.PrintObj(info.Object, o.Out); err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
continue
|
||||
@ -185,7 +185,7 @@ func (o ResumeOptions) RunResume() error {
|
||||
allErrs = append(allErrs, err)
|
||||
continue
|
||||
}
|
||||
if err = printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out); err != nil {
|
||||
if err = printer.PrintObj(info.Object, o.Out); err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ func (o *UndoOptions) RunUndo() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return printer.PrintObj(cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping), o.Out)
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
})
|
||||
|
||||
return err
|
||||
|
@ -691,7 +691,6 @@ func (o *RunOptions) createGeneratedObject(f cmdutil.Factory, cmd *cobra.Command
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
actualObj = cmdutil.AsDefaultVersionedOrOriginal(actualObj, mapping)
|
||||
|
||||
return &RunObject{
|
||||
Object: actualObj,
|
||||
|
@ -280,7 +280,6 @@ func (o TaintOptions) RunTaint() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outputObj = cmdutil.AsDefaultVersionedOrOriginal(outputObj, mapping)
|
||||
|
||||
printer, err := o.ToPrinter(operation)
|
||||
if err != nil {
|
||||
|
@ -3,7 +3,6 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"conversion.go",
|
||||
"crdfinder.go",
|
||||
"factory.go",
|
||||
"factory_client_access.go",
|
||||
@ -14,7 +13,6 @@ go_library(
|
||||
importpath = "k8s.io/kubernetes/pkg/kubectl/cmd/util",
|
||||
visibility = ["//build/visible_to:pkg_kubectl_cmd_util_CONSUMERS"],
|
||||
deps = [
|
||||
"//pkg/api/legacyscheme:go_default_library",
|
||||
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
||||
"//pkg/kubectl/cmd/util/openapi/validation:go_default_library",
|
||||
"//pkg/kubectl/scheme:go_default_library",
|
||||
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
)
|
||||
|
||||
// AsDefaultVersionedOrOriginal returns the object as a Go object in the external form if possible (matching the
|
||||
// group version kind of the mapping if provided, a best guess based on serialization if not provided, or obj if it cannot be converted.
|
||||
// TODO update call sites to specify the scheme they want on their builder.
|
||||
func AsDefaultVersionedOrOriginal(obj runtime.Object, mapping *meta.RESTMapping) runtime.Object {
|
||||
converter := runtime.ObjectConvertor(legacyscheme.Scheme)
|
||||
groupVersioner := runtime.GroupVersioner(schema.GroupVersions(legacyscheme.Scheme.PrioritizedVersionsAllGroups()))
|
||||
if mapping != nil {
|
||||
groupVersioner = mapping.GroupVersionKind.GroupVersion()
|
||||
}
|
||||
|
||||
if obj, err := converter.ConvertToVersion(obj, groupVersioner); err == nil {
|
||||
return obj
|
||||
}
|
||||
return obj
|
||||
}
|
Loading…
Reference in New Issue
Block a user