mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Fix boilerplate and make stub controller
This commit is contained in:
parent
1e2b995a79
commit
74d2ee69eb
@ -17,19 +17,34 @@ limitations under the License.
|
||||
package admission
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
// alwaysAdmitController says yes to all admission control requests, its useful for testing.
|
||||
type alwaysAdmitController struct{}
|
||||
// stubAdmissionController is capable of either always admitting or always denying incoming requests
|
||||
type stubAdmissionController struct {
|
||||
admit bool
|
||||
}
|
||||
|
||||
func (alwaysAdmitController) AdmissionControl(operation, kind, namespace string, object runtime.Object) (err error) {
|
||||
return nil
|
||||
func (ac *stubAdmissionController) AdmissionControl(operation, kind, namespace string, object runtime.Object) (err error) {
|
||||
if !ac.admit {
|
||||
err = errors.New("No changes allowed")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func NewAlwaysAdmitController() AdmissionControl {
|
||||
return new(alwaysAdmitController)
|
||||
return &stubAdmissionController{
|
||||
admit: true,
|
||||
}
|
||||
}
|
||||
|
||||
func NewAlwaysDenyController() AdmissionControl {
|
||||
return &stubAdmissionController{
|
||||
admit: false,
|
||||
}
|
||||
}
|
||||
|
||||
type admissionController struct {
|
||||
|
Loading…
Reference in New Issue
Block a user