mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-18 07:25:10 +00:00
Make defaulting part of versioning codec
Most normal codec use should perform defaulting. DirectCodecs should not perform defaulting. Update the defaulting_test to fuzz the list of known defaulters. Use the new versioning.NewDefaultingCodec() method.
This commit is contained in:
@@ -76,6 +76,24 @@ func EncodeOrDie(e Encoder, obj Object) string {
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
// DefaultingSerializer invokes defaulting after decoding.
|
||||
type DefaultingSerializer struct {
|
||||
Defaulter ObjectDefaulter
|
||||
Decoder Decoder
|
||||
// Encoder is optional to allow this type to be used as both a Decoder and an Encoder
|
||||
Encoder
|
||||
}
|
||||
|
||||
// Decode performs a decode and then allows the defaulter to act on the provided object.
|
||||
func (d DefaultingSerializer) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, into Object) (Object, *unversioned.GroupVersionKind, error) {
|
||||
obj, gvk, err := d.Decoder.Decode(data, defaultGVK, into)
|
||||
if err != nil {
|
||||
return obj, gvk, err
|
||||
}
|
||||
d.Defaulter.Default(obj)
|
||||
return obj, gvk, nil
|
||||
}
|
||||
|
||||
// UseOrCreateObject returns obj if the canonical ObjectKind returned by the provided typer matches gvk, or
|
||||
// invokes the ObjectCreator to instantiate a new gvk. Returns an error if the typer cannot find the object.
|
||||
func UseOrCreateObject(t ObjectTyper, c ObjectCreater, gvk unversioned.GroupVersionKind, obj Object) (Object, error) {
|
||||
|
||||
Reference in New Issue
Block a user