From 74d2ee69eb64219b4b3fff5752cb2dfe8b98f991 Mon Sep 17 00:00:00 2001 From: derekwaynecarr Date: Tue, 6 Jan 2015 14:51:28 -0500 Subject: [PATCH] Fix boilerplate and make stub controller --- pkg/admission/admission_control.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/pkg/admission/admission_control.go b/pkg/admission/admission_control.go index 31cab355906..829e2684f56 100644 --- a/pkg/admission/admission_control.go +++ b/pkg/admission/admission_control.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -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 {