Remove client from attributes, remove admission control interface, fix-up error codes

This commit is contained in:
derekwaynecarr
2015-01-07 14:33:21 -05:00
parent 2820c2c601
commit a56087cdf8
18 changed files with 84 additions and 130 deletions

View File

@@ -17,12 +17,16 @@ limitations under the License.
package admit
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
"io"
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
)
func init() {
admission.RegisterPlugin("AlwaysAdmit", func(config io.Reader) (admission.Interface, error) { return NewAlwaysAdmit(), nil })
admission.RegisterPlugin("AlwaysAdmit", func(client client.Interface, config io.Reader) (admission.Interface, error) {
return NewAlwaysAdmit(), nil
})
}
// alwaysAdmit is an implementation of admission.Interface which always says yes to an admit request.

View File

@@ -22,10 +22,13 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
apierrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
)
func init() {
admission.RegisterPlugin("AlwaysDeny", func(config io.Reader) (admission.Interface, error) { return NewAlwaysDeny(), nil })
admission.RegisterPlugin("AlwaysDeny", func(client client.Interface, config io.Reader) (admission.Interface, error) {
return NewAlwaysDeny(), nil
})
}
// alwaysDeny is an implementation of admission.Interface which always says no to an admission request.
@@ -33,7 +36,7 @@ func init() {
type alwaysDeny struct{}
func (alwaysDeny) Admit(a admission.Attributes) (err error) {
return apierrors.NewConflict(a.GetKind(), "", errors.New("No changes allowed"))
return apierrors.NewForbidden(a.GetKind(), "", errors.New("Admission control is denying all modifications"))
}
func NewAlwaysDeny() admission.Interface {

View File

@@ -24,7 +24,7 @@ import (
func TestAdmission(t *testing.T) {
handler := NewAlwaysDeny()
err := handler.Admit(admission.NewAttributesRecord(nil, nil, "foo", "Pod", "ignored"))
err := handler.Admit(admission.NewAttributesRecord(nil, "foo", "Pod", "ignored"))
if err == nil {
t.Errorf("Expected error returned from admission handler")
}