mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +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
|
package admission
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// alwaysAdmitController says yes to all admission control requests, its useful for testing.
|
// stubAdmissionController is capable of either always admitting or always denying incoming requests
|
||||||
type alwaysAdmitController struct{}
|
type stubAdmissionController struct {
|
||||||
|
admit bool
|
||||||
|
}
|
||||||
|
|
||||||
func (alwaysAdmitController) AdmissionControl(operation, kind, namespace string, object runtime.Object) (err error) {
|
func (ac *stubAdmissionController) AdmissionControl(operation, kind, namespace string, object runtime.Object) (err error) {
|
||||||
return nil
|
if !ac.admit {
|
||||||
|
err = errors.New("No changes allowed")
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAlwaysAdmitController() AdmissionControl {
|
func NewAlwaysAdmitController() AdmissionControl {
|
||||||
return new(alwaysAdmitController)
|
return &stubAdmissionController{
|
||||||
|
admit: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAlwaysDenyController() AdmissionControl {
|
||||||
|
return &stubAdmissionController{
|
||||||
|
admit: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type admissionController struct {
|
type admissionController struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user