@@ -26,22 +26,35 @@ import (
26
26
27
27
// Decoder knows how to decode the contents of an admission
28
28
// request into a concrete object.
29
- type Decoder struct {
29
+ type Decoder interface {
30
+ // Decode decodes the inlined object in the AdmissionRequest into the passed-in runtime.Object.
31
+ // If you want decode the OldObject in the AdmissionRequest, use DecodeRaw.
32
+ // It errors out if req.Object.Raw is empty i.e. containing 0 raw bytes.
33
+ Decode (req Request , into runtime.Object ) error
34
+
35
+ // DecodeRaw decodes a RawExtension object into the passed-in runtime.Object.
36
+ // It errors out if rawObj is empty i.e. containing 0 raw bytes.
37
+ DecodeRaw (rawObj runtime.RawExtension , into runtime.Object ) error
38
+ }
39
+
40
+ // decoder knows how to decode the contents of an admission
41
+ // request into a concrete object.
42
+ type decoder struct {
30
43
codecs serializer.CodecFactory
31
44
}
32
45
33
- // NewDecoder creates a Decoder given the runtime.Scheme.
34
- func NewDecoder (scheme * runtime.Scheme ) * Decoder {
46
+ // NewDecoder creates a decoder given the runtime.Scheme.
47
+ func NewDecoder (scheme * runtime.Scheme ) Decoder {
35
48
if scheme == nil {
36
49
panic ("scheme should never be nil" )
37
50
}
38
- return & Decoder {codecs : serializer .NewCodecFactory (scheme )}
51
+ return & decoder {codecs : serializer .NewCodecFactory (scheme )}
39
52
}
40
53
41
54
// Decode decodes the inlined object in the AdmissionRequest into the passed-in runtime.Object.
42
55
// If you want decode the OldObject in the AdmissionRequest, use DecodeRaw.
43
56
// It errors out if req.Object.Raw is empty i.e. containing 0 raw bytes.
44
- func (d * Decoder ) Decode (req Request , into runtime.Object ) error {
57
+ func (d * decoder ) Decode (req Request , into runtime.Object ) error {
45
58
// we error out if rawObj is an empty object.
46
59
if len (req .Object .Raw ) == 0 {
47
60
return fmt .Errorf ("there is no content to decode" )
@@ -51,7 +64,7 @@ func (d *Decoder) Decode(req Request, into runtime.Object) error {
51
64
52
65
// DecodeRaw decodes a RawExtension object into the passed-in runtime.Object.
53
66
// It errors out if rawObj is empty i.e. containing 0 raw bytes.
54
- func (d * Decoder ) DecodeRaw (rawObj runtime.RawExtension , into runtime.Object ) error {
67
+ func (d * decoder ) DecodeRaw (rawObj runtime.RawExtension , into runtime.Object ) error {
55
68
// NB(directxman12): there's a bug/weird interaction between decoders and
56
69
// the API server where the API server doesn't send a GVK on the embedded
57
70
// objects, which means the unstructured decoder refuses to decode. It
0 commit comments