@@ -41,8 +41,17 @@ type Interface interface {
4141 Validate () error
4242}
4343
44- // Decoder implements a decoder for objects in this API group.
45- var Decoder runtime.Decoder
44+ // StrictDecoder implements a decoder for objects in this API group. Fails upon
45+ // unknown fields in the input. Is the preferable choice when processing input
46+ // directly provided by the user (example: opaque config JSON provided in a
47+ // resource claim, validated only in the NodePrepareResources code path when no
48+ // validating webhook is deployed).
49+ var StrictDecoder runtime.Decoder
50+
51+ // NonstrictDecoder implements a decoder for objects in this API group. Silently
52+ // drops unknown fields in the input. Used for deserializing checkpoint data
53+ // (JSON that may have been created by older or newer versions of this driver).
54+ var NonstrictDecoder runtime.Decoder
4655
4756func init () {
4857 // Create a new scheme and add our types to it. If at some point in the
@@ -63,20 +72,23 @@ func init() {
6372 )
6473 metav1 .AddToGroupVersion (scheme , schemeGroupVersion )
6574
66- // Set up a json serializer to decode our types.
67- Decoder = json .NewSerializerWithOptions (
75+ // Note: the strictness applies to all types defined above via
76+ // AddKnownTypes(), i.e. it cannot be set per-type. That is OK in this case.
77+ // Unknown fields will simply be dropped (ignored) upon decode, which is
78+ // what we want. This is relevant in a downgrade case, when a checkpointed
79+ // JSON document contains fields added in a later version (workload defined
80+ // with a new version of this driver).
81+ NonstrictDecoder = json .NewSerializerWithOptions (
82+ json .DefaultMetaFactory ,
83+ scheme ,
84+ scheme ,
85+ json.SerializerOptions {Strict : false },
86+ )
87+
88+ StrictDecoder = json .NewSerializerWithOptions (
6889 json .DefaultMetaFactory ,
6990 scheme ,
7091 scheme ,
71- json.SerializerOptions {
72- // Note: the strictness applies to all types defined above via
73- // AddKnownTypes(), i.e. it cannot be set per-type. That is OK in
74- // this case. Unknown fields will simply be dropped (ignored) upon
75- // decode, which is what we want. This is relevant in a downgrade
76- // case, when a checkpointed JSON document contains fields added in
77- // a later version (workload defined with a new version of this
78- // driver).
79- Pretty : true , Strict : false ,
80- },
92+ json.SerializerOptions {Strict : true },
8193 )
8294}
0 commit comments