Remove unnecessary roundtripping in get.go

This commit is contained in:
Maciej Szulik 2018-05-15 22:15:23 +02:00
parent dc62a73742
commit 582128a837
No known key found for this signature in database
GPG Key ID: F15E55D276FA84C4

View File

@ -343,7 +343,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
objs := make([]runtime.Object, len(infos))
for ix := range infos {
if o.ServerPrint {
table, err := o.decodeIntoTable(cmdutil.InternalVersionJSONEncoder(), infos[ix].Object)
table, err := o.decodeIntoTable(infos[ix].Object)
if err == nil {
infos[ix].Object = table
} else {
@ -589,34 +589,28 @@ func attemptToConvertToInternal(obj runtime.Object, converter runtime.ObjectConv
return internalObject
}
func (o *GetOptions) decodeIntoTable(encoder runtime.Encoder, obj runtime.Object) (runtime.Object, error) {
func (o *GetOptions) decodeIntoTable(obj runtime.Object) (runtime.Object, error) {
if obj.GetObjectKind().GroupVersionKind().Kind != "Table" {
return nil, fmt.Errorf("attempt to decode non-Table object into a v1beta1.Table")
}
b, err := runtime.Encode(encoder, obj)
if err != nil {
return nil, err
unstr, ok := obj.(*unstructured.Unstructured)
if !ok {
return nil, fmt.Errorf("attempt to decode non-Unstructured object")
}
table := &metav1beta1.Table{}
err = json.Unmarshal(b, table)
if err != nil {
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstr.Object, table); err != nil {
return nil, err
}
for i := range table.Rows {
row := &table.Rows[i]
if row.Object.Raw == nil || row.Object.Object != nil {
//if row already has Object.Object
//we don't change it
continue
}
converted, err := runtime.Decode(unstructured.UnstructuredJSONScheme, row.Object.Raw)
if err != nil {
//if error happens, we just continue
continue
return nil, err
}
row.Object.Object = converted
}