mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
admission: split MutationInterface out of Interface
This commit is contained in:
parent
970d2553cc
commit
d4f48c9313
@ -30,11 +30,29 @@ func (admissionHandler chainAdmissionHandler) Admit(a Attributes) error {
|
|||||||
if !handler.Handles(a.GetOperation()) {
|
if !handler.Handles(a.GetOperation()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err := handler.Admit(a)
|
if mutator, ok := handler.(MutationInterface); ok {
|
||||||
|
err := mutator.Admit(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidatingAdmit performs an admission control check using a chain of handlers, and returns immediately on first error
|
||||||
|
func (admissionHandler chainAdmissionHandler) ValidatingAdmit(a Attributes) error {
|
||||||
|
for _, handler := range admissionHandler {
|
||||||
|
if !handler.Handles(a.GetOperation()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if validator, ok := handler.(ValidationInterface); ok {
|
||||||
|
err := validator.ValidatingAdmit(a)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,22 +53,22 @@ type Attributes interface {
|
|||||||
|
|
||||||
// Interface is an abstract, pluggable interface for Admission Control decisions.
|
// Interface is an abstract, pluggable interface for Admission Control decisions.
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
// Admit makes an admission decision based on the request attributes
|
|
||||||
Admit(a Attributes) (err error)
|
|
||||||
|
|
||||||
// Handles returns true if this admission controller can handle the given operation
|
// Handles returns true if this admission controller can handle the given operation
|
||||||
// where operation can be one of CREATE, UPDATE, DELETE, or CONNECT
|
// where operation can be one of CREATE, UPDATE, DELETE, or CONNECT
|
||||||
Handles(operation Operation) bool
|
Handles(operation Operation) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MutationInterface interface {
|
||||||
|
Interface
|
||||||
|
|
||||||
|
// Admit makes an admission decision based on the request attributes
|
||||||
|
Admit(a Attributes) (err error)
|
||||||
|
}
|
||||||
|
|
||||||
// ValidationInterface is an abstract, pluggable interface for Admission Control decisions.
|
// ValidationInterface is an abstract, pluggable interface for Admission Control decisions.
|
||||||
type ValidationInterface interface {
|
type ValidationInterface interface {
|
||||||
// ValidatingAdmit makes an admission decision based on the request attributes. It is NOT allowed to mutate
|
// ValidatingAdmit makes an admission decision based on the request attributes. It is NOT allowed to mutate
|
||||||
ValidatingAdmit(a Attributes) (err error)
|
ValidatingAdmit(a Attributes) (err error)
|
||||||
|
|
||||||
// Handles returns true if this admission controller can handle the given operation
|
|
||||||
// where operation can be one of CREATE, UPDATE, DELETE, or CONNECT
|
|
||||||
Handles(operation Operation) bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Operation is the type of resource operation being checked for admission control
|
// Operation is the type of resource operation being checked for admission control
|
||||||
|
Loading…
Reference in New Issue
Block a user