mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +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,17 +171,22 @@ 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:
|
||||||
// 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)
|
// An unstructured list can contain objects of multiple group version kinds. don't short-circuit just
|
||||||
objGVK := obj.GetObjectKind().GroupVersionKind()
|
// because the top-level type matches our desired destination type. actually send the object to the converter
|
||||||
if len(objGVK.Version) == 0 {
|
// to give it a chance to convert the list items if needed.
|
||||||
return c.encoder.Encode(obj, w)
|
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)
|
||||||
targetGVK, ok := c.encodeVersion.KindForGroupVersionKinds([]schema.GroupVersionKind{objGVK})
|
objGVK := obj.GetObjectKind().GroupVersionKind()
|
||||||
if !ok {
|
if len(objGVK.Version) == 0 {
|
||||||
return runtime.NewNotRegisteredGVKErrForTarget(objGVK, c.encodeVersion)
|
return c.encoder.Encode(obj, w)
|
||||||
}
|
}
|
||||||
if targetGVK == objGVK {
|
targetGVK, ok := c.encodeVersion.KindForGroupVersionKinds([]schema.GroupVersionKind{objGVK})
|
||||||
return c.encoder.Encode(obj, w)
|
if !ok {
|
||||||
|
return runtime.NewNotRegisteredGVKErrForTarget(objGVK, c.encodeVersion)
|
||||||
|
}
|
||||||
|
if targetGVK == objGVK {
|
||||||
|
return c.encoder.Encode(obj, w)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user