mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Unify Object and UnstructuredObject
The unified RESTMapper and Typer follow the new rules, but on error will fallback to the legacy path (while still supporting Unstructured objects). This allows callers to handle the appropriate distinction themselves if necessary. Add a LocalParam() method to the resource.Builder that DRYs up a large chunk of complicated code in set commands.
This commit is contained in:
@@ -191,13 +191,9 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
|
||||
changeCause := f.Command(cmd, false)
|
||||
|
||||
includeUninitialized := cmdutil.ShouldIncludeUninitialized(cmd, false)
|
||||
b := f.NewBuilder()
|
||||
if o.local {
|
||||
b = b.Local()
|
||||
} else {
|
||||
b = b.Unstructured()
|
||||
}
|
||||
b = b.
|
||||
b := f.NewBuilder().
|
||||
Unstructured().
|
||||
LocalParam(o.local).
|
||||
ContinueOnError().
|
||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
||||
FilenameParam(enforceNamespace, &o.FilenameOptions).
|
||||
@@ -304,16 +300,10 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var mapper meta.RESTMapper
|
||||
if o.local {
|
||||
mapper, _ = f.Object()
|
||||
} else {
|
||||
mapper, _ = f.UnstructuredObject()
|
||||
}
|
||||
if o.outputFormat != "" {
|
||||
return f.PrintObject(cmd, o.local, mapper, outputObj, o.out)
|
||||
return f.PrintObject(cmd, o.local, r.Mapper().RESTMapper, outputObj, o.out)
|
||||
}
|
||||
f.PrintSuccess(mapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, dataChangeMsg)
|
||||
f.PrintSuccess(r.Mapper().RESTMapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, dataChangeMsg)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user