mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-08 20:50:24 +00:00
Remove unstructured error checking from affected code
Also remove error messages that depended on ObjectKinds() - future changes will potentially remove this interface and the replacements here are equivalent.
This commit is contained in:
@@ -198,18 +198,6 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Prune {
|
|
||||||
mapper, _, err := f.UnstructuredObject()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
options.PruneResources, err = parsePruneResources(mapper, cmdutil.GetFlagStringArray(cmd, "prune-whitelist"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// include the uninitialized objects by default if --prune is true
|
// include the uninitialized objects by default if --prune is true
|
||||||
// unless explicitly set --include-uninitialized=false
|
// unless explicitly set --include-uninitialized=false
|
||||||
includeUninitialized := cmdutil.ShouldIncludeUninitialized(cmd, options.Prune)
|
includeUninitialized := cmdutil.ShouldIncludeUninitialized(cmd, options.Prune)
|
||||||
@@ -227,6 +215,13 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.Prune {
|
||||||
|
options.PruneResources, err = parsePruneResources(r.Mapper().RESTMapper, cmdutil.GetFlagStringArray(cmd, "prune-whitelist"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dryRun := cmdutil.GetFlagBool(cmd, "dry-run")
|
dryRun := cmdutil.GetFlagBool(cmd, "dry-run")
|
||||||
output := cmdutil.GetFlagString(cmd, "output")
|
output := cmdutil.GetFlagString(cmd, "output")
|
||||||
shortOutput := output == "name"
|
shortOutput := output == "name"
|
||||||
|
@@ -112,7 +112,7 @@ func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command)
|
|||||||
o.Codec = f.JSONEncoder()
|
o.Codec = f.JSONEncoder()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
o.Mapper, o.Typer, err = f.UnstructuredObject()
|
o.Mapper, o.Typer = f.UnstructuredObject()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -308,10 +308,7 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
|
|||||||
if o.local {
|
if o.local {
|
||||||
mapper, _ = f.Object()
|
mapper, _ = f.Object()
|
||||||
} else {
|
} else {
|
||||||
mapper, _, err = f.UnstructuredObject()
|
mapper, _ = f.UnstructuredObject()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if o.outputFormat != "" {
|
if o.outputFormat != "" {
|
||||||
return f.PrintObject(cmd, o.local, mapper, outputObj, o.out)
|
return f.PrintObject(cmd, o.local, mapper, outputObj, o.out)
|
||||||
|
@@ -222,11 +222,7 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
|
|||||||
if len(options.OutputFormat) > 0 && options.OutputFormat != "name" {
|
if len(options.OutputFormat) > 0 && options.OutputFormat != "name" {
|
||||||
return f.PrintResourceInfoForCommand(cmd, info, out)
|
return f.PrintResourceInfoForCommand(cmd, info, out)
|
||||||
}
|
}
|
||||||
mapper, _, err := f.UnstructuredObject()
|
f.PrintSuccess(r.Mapper().RESTMapper, options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f.PrintSuccess(mapper, options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg)
|
|
||||||
|
|
||||||
// if object was not successfully patched, exit with error code 1
|
// if object was not successfully patched, exit with error code 1
|
||||||
if !didPatch {
|
if !didPatch {
|
||||||
|
@@ -230,10 +230,7 @@ func TestGetUnknownSchemaObject(t *testing.T) {
|
|||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
tf.ClientConfig = defaultClientConfig()
|
tf.ClientConfig = defaultClientConfig()
|
||||||
|
|
||||||
mapper, _, err := f.UnstructuredObject()
|
mapper, _ := f.UnstructuredObject()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
m, err := mapper.RESTMapping(schema.GroupKind{Group: "apitest", Kind: "Type"})
|
m, err := mapper.RESTMapping(schema.GroupKind{Group: "apitest", Kind: "Type"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@@ -192,7 +192,7 @@ func RunRollingUpdate(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args
|
|||||||
var keepOldName bool
|
var keepOldName bool
|
||||||
var replicasDefaulted bool
|
var replicasDefaulted bool
|
||||||
|
|
||||||
mapper, typer := f.Object()
|
mapper, _ := f.Object()
|
||||||
|
|
||||||
if len(filename) != 0 {
|
if len(filename) != 0 {
|
||||||
schema, err := f.Validator(cmdutil.GetFlagBool(cmd, "validate"))
|
schema, err := f.Validator(cmdutil.GetFlagBool(cmd, "validate"))
|
||||||
@@ -223,11 +223,8 @@ func RunRollingUpdate(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args
|
|||||||
}
|
}
|
||||||
newRc, ok = obj.(*api.ReplicationController)
|
newRc, ok = obj.(*api.ReplicationController)
|
||||||
if !ok {
|
if !ok {
|
||||||
if gvks, _, err := typer.ObjectKinds(obj); err == nil {
|
glog.V(4).Infof("Object %T is not a ReplicationController", obj)
|
||||||
return cmdutil.UsageErrorf(cmd, "%s contains a %v not a ReplicationController", filename, gvks[0])
|
return cmdutil.UsageErrorf(cmd, "%s contains a %v not a ReplicationController", filename, obj.GetObjectKind().GroupVersionKind())
|
||||||
}
|
|
||||||
glog.V(4).Infof("Object %#v is not a ReplicationController", obj)
|
|
||||||
return cmdutil.UsageErrorf(cmd, "%s does not specify a valid ReplicationController", filename)
|
|
||||||
}
|
}
|
||||||
infos, err := request.Infos()
|
infos, err := request.Infos()
|
||||||
if err != nil || len(infos) != 1 {
|
if err != nil || len(infos) != 1 {
|
||||||
|
@@ -107,11 +107,7 @@ func (o *EditOptions) Complete(f cmdutil.Factory, out, errOut io.Writer, args []
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
mapper, _, err := f.UnstructuredObject()
|
mapper, _ := f.UnstructuredObject()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
b := f.NewBuilder().Unstructured()
|
b := f.NewBuilder().Unstructured()
|
||||||
if o.EditMode == NormalEditMode || o.EditMode == ApplyEditMode {
|
if o.EditMode == NormalEditMode || o.EditMode == ApplyEditMode {
|
||||||
// when do normal edit or apply edit we need to always retrieve the latest resource from server
|
// when do normal edit or apply edit we need to always retrieve the latest resource from server
|
||||||
|
@@ -310,11 +310,7 @@ func (f *ring0Factory) MapBasedSelectorForObject(object runtime.Object) (string,
|
|||||||
}
|
}
|
||||||
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
|
||||||
default:
|
default:
|
||||||
gvks, _, err := legacyscheme.Scheme.ObjectKinds(object)
|
return "", fmt.Errorf("cannot extract pod selector from %T", object)
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return "", fmt.Errorf("cannot extract pod selector from %v", gvks[0])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,11 +328,7 @@ func (f *ring0Factory) PortsForObject(object runtime.Object) ([]string, error) {
|
|||||||
case *extensions.ReplicaSet:
|
case *extensions.ReplicaSet:
|
||||||
return getPorts(t.Spec.Template.Spec), nil
|
return getPorts(t.Spec.Template.Spec), nil
|
||||||
default:
|
default:
|
||||||
gvks, _, err := legacyscheme.Scheme.ObjectKinds(object)
|
return nil, fmt.Errorf("cannot extract ports from %T", object)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("cannot extract ports from %v", gvks[0])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,11 +346,7 @@ func (f *ring0Factory) ProtocolsForObject(object runtime.Object) (map[string]str
|
|||||||
case *extensions.ReplicaSet:
|
case *extensions.ReplicaSet:
|
||||||
return getProtocols(t.Spec.Template.Spec), nil
|
return getProtocols(t.Spec.Template.Spec), nil
|
||||||
default:
|
default:
|
||||||
gvks, _, err := legacyscheme.Scheme.ObjectKinds(object)
|
return nil, fmt.Errorf("cannot extract protocols from %T", object)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("cannot extract protocols from %v", gvks[0])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -286,11 +286,7 @@ func (f *ring1Factory) LogsForObject(object, options runtime.Object, timeout tim
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
gvks, _, err := legacyscheme.Scheme.ObjectKinds(object)
|
return nil, fmt.Errorf("cannot get the logs from %T", object)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("cannot get the logs from %v", gvks[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sortBy := func(pods []*v1.Pod) sort.Interface { return controller.ByLogging(pods) }
|
sortBy := func(pods []*v1.Pod) sort.Interface { return controller.ByLogging(pods) }
|
||||||
@@ -414,11 +410,7 @@ func (f *ring1Factory) AttachablePodForObject(object runtime.Object, timeout tim
|
|||||||
return t, nil
|
return t, nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
gvks, _, err := legacyscheme.Scheme.ObjectKinds(object)
|
return nil, fmt.Errorf("cannot attach to %T: not implemented", object)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("cannot attach to %v: not implemented", gvks[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sortBy := func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) }
|
sortBy := func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) }
|
||||||
|
Reference in New Issue
Block a user