mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
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 ```
This commit is contained in:
commit
4a7a18653c
@ -344,7 +344,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
|
|||||||
objs := make([]runtime.Object, len(infos))
|
objs := make([]runtime.Object, len(infos))
|
||||||
for ix := range infos {
|
for ix := range infos {
|
||||||
if o.ServerPrint {
|
if o.ServerPrint {
|
||||||
table, err := o.decodeIntoTable(cmdutil.InternalVersionJSONEncoder(), infos[ix].Object)
|
table, err := o.decodeIntoTable(infos[ix].Object)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
infos[ix].Object = table
|
infos[ix].Object = table
|
||||||
} else {
|
} else {
|
||||||
@ -597,34 +597,28 @@ func attemptToConvertToInternal(obj runtime.Object, converter runtime.ObjectConv
|
|||||||
return internalObject
|
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" {
|
if obj.GetObjectKind().GroupVersionKind().Kind != "Table" {
|
||||||
return nil, fmt.Errorf("attempt to decode non-Table object into a v1beta1.Table")
|
return nil, fmt.Errorf("attempt to decode non-Table object into a v1beta1.Table")
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := runtime.Encode(encoder, obj)
|
unstr, ok := obj.(*unstructured.Unstructured)
|
||||||
if err != nil {
|
if !ok {
|
||||||
return nil, err
|
return nil, fmt.Errorf("attempt to decode non-Unstructured object")
|
||||||
}
|
}
|
||||||
|
|
||||||
table := &metav1beta1.Table{}
|
table := &metav1beta1.Table{}
|
||||||
err = json.Unmarshal(b, table)
|
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstr.Object, table); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range table.Rows {
|
for i := range table.Rows {
|
||||||
row := &table.Rows[i]
|
row := &table.Rows[i]
|
||||||
if row.Object.Raw == nil || row.Object.Object != nil {
|
if row.Object.Raw == nil || row.Object.Object != nil {
|
||||||
//if row already has Object.Object
|
|
||||||
//we don't change it
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
converted, err := runtime.Decode(unstructured.UnstructuredJSONScheme, row.Object.Raw)
|
converted, err := runtime.Decode(unstructured.UnstructuredJSONScheme, row.Object.Raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//if error happens, we just continue
|
return nil, err
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
row.Object.Object = converted
|
row.Object.Object = converted
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user