-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.go
65 lines (55 loc) · 2.1 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package handler
import (
"github.com/dbsystel/kewl/pkg/codec"
"github.com/dbsystel/kewl/pkg/mutation"
"github.com/dbsystel/kewl/pkg/validation"
"github.com/dbsystel/kewl/pkg/webhook/facade"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
)
// Type denotes a type name for the handler
type Type string
const (
// TypeValidation marks a handler for validation
TypeValidation Type = "validation"
// TypeMutation marks a handler mutation
TypeMutation Type = "mutation"
// TypeOther marks a handler which does neither (like unmarshalling)
TypeOther Type = "other"
)
// AdmissionReview is a handler for v1beta1.AdmissionReview
type AdmissionReview interface {
// HandleReview handles the facade.AdmissionReview using the logr.Logger
HandleReview(logger logr.Logger, review facade.AdmissionReview) error
// HandlerType returns the Type to identify the web hook
HandlerType() Type
}
// UnmarshalReqObj is an AdmissionReview which handles the deserialization of the object in v1beta1.AdmissionRequest
type UnmarshalReqObj interface {
codec.SchemeRegistry
AdmissionReview
}
// Validator is an AdmissionReview for validating an object in v1beta1.AdmissionRequest
type Validator interface {
AdmissionReview
// AddValidator adds a validation.Validator to be used to validate the v1beta1.AdmissionRequest
AddValidator(validator validation.Validator) error
}
// Mutator is a AdmissionReview for mutating an object in v1beta1.AdmissionRequest
type Mutator interface {
AdmissionReview
// AddMutator adds a mutation.Mutator to be used to mutate the v1beta1.AdmissionRequest
AddMutator(mutator mutation.Mutator) error
}
// NewUnmarshalReqObj creates a new UnmarshalReqObj using a new runtime.Scheme
func NewUnmarshalReqObj() UnmarshalReqObj {
return &unmarshalReqObjImpl{codec.NewDeserializer(runtime.NewScheme())}
}
// NewValidator creates a new Validator
func NewValidator() Validator {
return &validatorImpl{unmarshaller: NewUnmarshalReqObj()}
}
// NewMutator creates a new Mutator and the provided metering.Summary for metering
func NewMutator() Mutator {
return &mutatorImpl{unmarshaller: NewUnmarshalReqObj()}
}