mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-08 12:41:58 +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
|
||||
}
|
||||
|
||||
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
|
||||
// unless explicitly set --include-uninitialized=false
|
||||
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
|
||||
}
|
||||
|
||||
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")
|
||||
output := cmdutil.GetFlagString(cmd, "output")
|
||||
shortOutput := output == "name"
|
||||
|
@@ -112,7 +112,7 @@ func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command)
|
||||
o.Codec = f.JSONEncoder()
|
||||
|
||||
var err error
|
||||
o.Mapper, o.Typer, err = f.UnstructuredObject()
|
||||
o.Mapper, o.Typer = f.UnstructuredObject()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -308,10 +308,7 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
|
||||
if o.local {
|
||||
mapper, _ = f.Object()
|
||||
} else {
|
||||
mapper, _, err = f.UnstructuredObject()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mapper, _ = f.UnstructuredObject()
|
||||
}
|
||||
if o.outputFormat != "" {
|
||||
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" {
|
||||
return f.PrintResourceInfoForCommand(cmd, info, out)
|
||||
}
|
||||
mapper, _, err := f.UnstructuredObject()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.PrintSuccess(mapper, options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg)
|
||||
f.PrintSuccess(r.Mapper().RESTMapper, options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg)
|
||||
|
||||
// if object was not successfully patched, exit with error code 1
|
||||
if !didPatch {
|
||||
|
@@ -230,10 +230,7 @@ func TestGetUnknownSchemaObject(t *testing.T) {
|
||||
tf.Namespace = "test"
|
||||
tf.ClientConfig = defaultClientConfig()
|
||||
|
||||
mapper, _, err := f.UnstructuredObject()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mapper, _ := f.UnstructuredObject()
|
||||
m, err := mapper.RESTMapping(schema.GroupKind{Group: "apitest", Kind: "Type"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@@ -192,7 +192,7 @@ func RunRollingUpdate(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args
|
||||
var keepOldName bool
|
||||
var replicasDefaulted bool
|
||||
|
||||
mapper, typer := f.Object()
|
||||
mapper, _ := f.Object()
|
||||
|
||||
if len(filename) != 0 {
|
||||
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)
|
||||
if !ok {
|
||||
if gvks, _, err := typer.ObjectKinds(obj); err == nil {
|
||||
return cmdutil.UsageErrorf(cmd, "%s contains a %v not a ReplicationController", filename, gvks[0])
|
||||
}
|
||||
glog.V(4).Infof("Object %#v is not a ReplicationController", obj)
|
||||
return cmdutil.UsageErrorf(cmd, "%s does not specify a valid ReplicationController", filename)
|
||||
glog.V(4).Infof("Object %T is not a ReplicationController", obj)
|
||||
return cmdutil.UsageErrorf(cmd, "%s contains a %v not a ReplicationController", filename, obj.GetObjectKind().GroupVersionKind())
|
||||
}
|
||||
infos, err := request.Infos()
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
mapper, _, err := f.UnstructuredObject()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mapper, _ := f.UnstructuredObject()
|
||||
b := f.NewBuilder().Unstructured()
|
||||
if o.EditMode == NormalEditMode || o.EditMode == ApplyEditMode {
|
||||
// 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
|
||||
default:
|
||||
gvks, _, err := legacyscheme.Scheme.ObjectKinds(object)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "", fmt.Errorf("cannot extract pod selector from %v", gvks[0])
|
||||
return "", fmt.Errorf("cannot extract pod selector from %T", object)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,11 +328,7 @@ func (f *ring0Factory) PortsForObject(object runtime.Object) ([]string, error) {
|
||||
case *extensions.ReplicaSet:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
default:
|
||||
gvks, _, err := legacyscheme.Scheme.ObjectKinds(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("cannot extract ports from %v", gvks[0])
|
||||
return nil, fmt.Errorf("cannot extract ports from %T", object)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,11 +346,7 @@ func (f *ring0Factory) ProtocolsForObject(object runtime.Object) (map[string]str
|
||||
case *extensions.ReplicaSet:
|
||||
return getProtocols(t.Spec.Template.Spec), nil
|
||||
default:
|
||||
gvks, _, err := legacyscheme.Scheme.ObjectKinds(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("cannot extract protocols from %v", gvks[0])
|
||||
return nil, fmt.Errorf("cannot extract protocols from %T", object)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -286,11 +286,7 @@ func (f *ring1Factory) LogsForObject(object, options runtime.Object, timeout tim
|
||||
}
|
||||
|
||||
default:
|
||||
gvks, _, err := legacyscheme.Scheme.ObjectKinds(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("cannot get the logs from %v", gvks[0])
|
||||
return nil, fmt.Errorf("cannot get the logs from %T", object)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
default:
|
||||
gvks, _, err := legacyscheme.Scheme.ObjectKinds(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("cannot attach to %v: not implemented", gvks[0])
|
||||
return nil, fmt.Errorf("cannot attach to %T: not implemented", object)
|
||||
}
|
||||
|
||||
sortBy := func(pods []*v1.Pod) sort.Interface { return sort.Reverse(controller.ActivePods(pods)) }
|
||||
|
Reference in New Issue
Block a user