Merge pull request #63885 from soltysh/get_unmarshal

Automatic merge from submit-queue (batch tested with PRs 64392, 63885). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Remove unnecessary roundtripping in get.go

/assign @deads2k @juanvallejo 

**Release note**:
```release-note
NONE
```
pull/8/head
Kubernetes Submit Queue 2018-05-29 00:28:14 -07:00 committed by GitHub
commit 4a7a18653c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 13 deletions

View File

@ -344,7 +344,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 {
@ -597,34 +597,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
}