Fix boilerplate and make stub controller

This commit is contained in:
derekwaynecarr 2015-01-06 14:51:28 -05:00
parent 1e2b995a79
commit 74d2ee69eb

View File

@ -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 {