Skip to content

Commit 6dbde68

Browse files
committed
Remove extraneous decoder interface
We don't have anywhere that we actually make use of decoder as an interface, so switch to just have a concrete implementation.
1 parent 14f4abf commit 6dbde68

File tree

3 files changed

+7
-22
lines changed

3 files changed

+7
-22
lines changed

pkg/webhook/admission/decode.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,19 @@ import (
2121
"k8s.io/apimachinery/pkg/runtime/serializer"
2222
)
2323

24-
// DecodeFunc is a function that implements an admission decoder in a single function.
25-
type DecodeFunc func(Request, runtime.Object) error
26-
27-
var _ Decoder = DecodeFunc(nil)
28-
29-
// Decode implements the Decoder interface.
30-
func (f DecodeFunc) Decode(req Request, obj runtime.Object) error {
31-
return f(req, obj)
32-
}
33-
34-
type decoder struct {
24+
// Decoder knows how to decode the contents of an admission
25+
// request into a concrete object.
26+
type Decoder struct {
3527
codecs serializer.CodecFactory
3628
}
3729

3830
// NewDecoder creates a Decoder given the runtime.Scheme
39-
func NewDecoder(scheme *runtime.Scheme) (Decoder, error) {
40-
return decoder{codecs: serializer.NewCodecFactory(scheme)}, nil
31+
func NewDecoder(scheme *runtime.Scheme) (*Decoder, error) {
32+
return &Decoder{codecs: serializer.NewCodecFactory(scheme)}, nil
4133
}
4234

4335
// Decode decodes the inlined object in the AdmissionRequest into the passed-in runtime.Object.
44-
func (d decoder) Decode(req Request, into runtime.Object) error {
36+
func (d *Decoder) Decode(req Request, into runtime.Object) error {
4537
deserializer := d.codecs.UniversalDeserializer()
4638
return runtime.DecodeInto(deserializer, req.AdmissionRequest.Object.Raw, into)
4739
}

pkg/webhook/admission/decode_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
var _ = Describe("admission webhook decoder", func() {
30-
var decoder Decoder
30+
var decoder *Decoder
3131
BeforeEach(func(done Done) {
3232
var err error
3333
decoder, err = NewDecoder(scheme.Scheme)

pkg/webhook/admission/types.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/appscode/jsonpatch"
2121

2222
admissionv1beta1 "k8s.io/api/admission/v1beta1"
23-
"k8s.io/apimachinery/pkg/runtime"
2423
)
2524

2625
// Request defines the input for an admission handler.
@@ -46,12 +45,6 @@ type Response struct {
4645
admissionv1beta1.AdmissionResponse
4746
}
4847

49-
// Decoder is used to decode AdmissionRequest.
50-
type Decoder interface {
51-
// Decode decodes the raw byte object from the AdmissionRequest to the passed-in runtime.Object.
52-
Decode(Request, runtime.Object) error
53-
}
54-
5548
// WebhookType defines the type of an admission webhook
5649
// (validating or mutating).
5750
type WebhookType int

0 commit comments

Comments
 (0)