mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 15:50:10 +00:00
Merge pull request #121771 from pohly/apimachinery-encoding-shortcut
encoding: avoid setting GVK unnecessarily
This commit is contained in:
commit
508e3b94fe
@ -236,10 +236,14 @@ func (e WithVersionEncoder) Encode(obj Object, stream io.Writer) error {
|
|||||||
gvk = preferredGVK
|
gvk = preferredGVK
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kind.SetGroupVersionKind(gvk)
|
|
||||||
err = e.Encoder.Encode(obj, stream)
|
// The gvk only needs to be set if not already as desired.
|
||||||
kind.SetGroupVersionKind(oldGVK)
|
if gvk != oldGVK {
|
||||||
return err
|
kind.SetGroupVersionKind(gvk)
|
||||||
|
defer kind.SetGroupVersionKind(oldGVK)
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.Encoder.Encode(obj, stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithoutVersionDecoder clears the group version kind of a deserialized object.
|
// WithoutVersionDecoder clears the group version kind of a deserialized object.
|
||||||
|
Loading…
Reference in New Issue
Block a user