mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Do not bypass same version unstructed conversion if it is a list
This give the converter a chance to convert list items to the requested version.
This commit is contained in:
parent
8a39e5381c
commit
531041ce94
@ -19,6 +19,7 @@ package versioning
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
)
|
)
|
||||||
@ -170,6 +171,10 @@ func (c *codec) Encode(obj runtime.Object, w io.Writer) error {
|
|||||||
case *runtime.Unknown:
|
case *runtime.Unknown:
|
||||||
return c.encoder.Encode(obj, w)
|
return c.encoder.Encode(obj, w)
|
||||||
case runtime.Unstructured:
|
case runtime.Unstructured:
|
||||||
|
// An unstructured list can contain objects of multiple group version kinds. don't short-circuit just
|
||||||
|
// because the top-level type matches our desired destination type. actually send the object to the converter
|
||||||
|
// to give it a chance to convert the list items if needed.
|
||||||
|
if _, ok := obj.(*unstructured.UnstructuredList); !ok {
|
||||||
// avoid conversion roundtrip if GVK is the right one already or is empty (yes, this is a hack, but the old behaviour we rely on in kubectl)
|
// avoid conversion roundtrip if GVK is the right one already or is empty (yes, this is a hack, but the old behaviour we rely on in kubectl)
|
||||||
objGVK := obj.GetObjectKind().GroupVersionKind()
|
objGVK := obj.GetObjectKind().GroupVersionKind()
|
||||||
if len(objGVK.Version) == 0 {
|
if len(objGVK.Version) == 0 {
|
||||||
@ -183,6 +188,7 @@ func (c *codec) Encode(obj runtime.Object, w io.Writer) error {
|
|||||||
return c.encoder.Encode(obj, w)
|
return c.encoder.Encode(obj, w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gvks, isUnversioned, err := c.typer.ObjectKinds(obj)
|
gvks, isUnversioned, err := c.typer.ObjectKinds(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user