mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
Avoid short-circuiting conversion when decoding into opinionated unstructured objects
This commit is contained in:
parent
b51ac8f7d5
commit
1c5d3ab85e
@ -18,6 +18,7 @@ package versioning
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
@ -90,7 +91,16 @@ func (c *codec) Decode(data []byte, defaultGVK *schema.GroupVersionKind, into ru
|
|||||||
into = versioned.Last()
|
into = versioned.Last()
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, gvk, err := c.decoder.Decode(data, defaultGVK, into)
|
// If the into object is unstructured and expresses an opinion about its group/version,
|
||||||
|
// create a new instance of the type so we always exercise the conversion path (skips short-circuiting on `into == obj`)
|
||||||
|
decodeInto := into
|
||||||
|
if into != nil {
|
||||||
|
if _, ok := into.(runtime.Unstructured); ok && !into.GetObjectKind().GroupVersionKind().GroupVersion().Empty() {
|
||||||
|
decodeInto = reflect.New(reflect.TypeOf(into).Elem()).Interface().(runtime.Object)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
obj, gvk, err := c.decoder.Decode(data, defaultGVK, decodeInto)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, gvk, err
|
return nil, gvk, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user