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

@@ -56,7 +56,7 @@ const (
// Handle returns a Handler function that exposes the provided storage interfaces
// as RESTful resources at prefix, serialized by codec, and also includes the support
// http resources.
func Handle(storage map[string]RESTStorage, codec runtime.Codec, root string, version string, selfLinker runtime.SelfLinker, admissionControl admission.AdmissionControl) http.Handler {
func Handle(storage map[string]RESTStorage, codec runtime.Codec, root string, version string, selfLinker runtime.SelfLinker, admissionControl admission.Interface) http.Handler {
prefix := root + "/" + version
group := NewAPIGroupVersion(storage, codec, prefix, selfLinker, admissionControl)
container := restful.NewContainer()
@@ -84,7 +84,7 @@ type APIGroupVersion struct {
// This is a helper method for registering multiple sets of REST handlers under different
// prefixes onto a server.
// TODO: add multitype codec serialization
func NewAPIGroupVersion(storage map[string]RESTStorage, codec runtime.Codec, canonicalPrefix string, selfLinker runtime.SelfLinker, admissionControl admission.AdmissionControl) *APIGroupVersion {
func NewAPIGroupVersion(storage map[string]RESTStorage, codec runtime.Codec, canonicalPrefix string, selfLinker runtime.SelfLinker, admissionControl admission.Interface) *APIGroupVersion {
return &APIGroupVersion{RESTHandler{
storage: storage,
codec: codec,

View File

@@ -39,6 +39,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/admit"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/deny"
)
func convert(obj runtime.Object) (runtime.Object, error) {
@@ -54,7 +56,7 @@ var accessor = meta.NewAccessor()
var versioner runtime.ResourceVersioner = accessor
var selfLinker runtime.SelfLinker = accessor
var mapper meta.RESTMapper
var admissionControl admission.AdmissionControl
var admissionControl admission.Interface
func interfacesFor(version string) (*meta.VersionInterfaces, error) {
switch version {
@@ -94,7 +96,7 @@ func init() {
)
defMapper.Add(api.Scheme, true, versions...)
mapper = defMapper
admissionControl = admission.NewAlwaysAdmitController()
admissionControl = admit.NewAlwaysAdmit()
}
type Simple struct {
@@ -482,7 +484,7 @@ func TestDeleteInvokesAdmissionControl(t *testing.T) {
simpleStorage := SimpleRESTStorage{}
ID := "id"
storage["simple"] = &simpleStorage
handler := Handle(storage, codec, "/prefix", testVersion, selfLinker, admission.NewAlwaysDenyController())
handler := Handle(storage, codec, "/prefix", testVersion, selfLinker, deny.NewAlwaysDeny())
server := httptest.NewServer(handler)
defer server.Close()
@@ -492,7 +494,7 @@ func TestDeleteInvokesAdmissionControl(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if response.StatusCode != http.StatusConflict {
if response.StatusCode != http.StatusForbidden {
t.Errorf("Unexpected response %#v", response)
}
}
@@ -566,7 +568,7 @@ func TestUpdateInvokesAdmissionControl(t *testing.T) {
t: t,
expectedSet: "/prefix/version/simple/" + ID,
}
handler := Handle(storage, codec, "/prefix", testVersion, selfLinker, admission.NewAlwaysDenyController())
handler := Handle(storage, codec, "/prefix", testVersion, selfLinker, deny.NewAlwaysDeny())
server := httptest.NewServer(handler)
defer server.Close()
@@ -585,7 +587,7 @@ func TestUpdateInvokesAdmissionControl(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if response.StatusCode != http.StatusConflict {
if response.StatusCode != http.StatusForbidden {
t.Errorf("Unexpected response %#v", response)
}
}
@@ -679,7 +681,7 @@ func TestCreateInvokesAdmissionControl(t *testing.T) {
}
handler := Handle(map[string]RESTStorage{
"foo": simpleStorage,
}, codec, "/prefix", testVersion, selfLinker, admission.NewAlwaysDenyController())
}, codec, "/prefix", testVersion, selfLinker, deny.NewAlwaysDeny())
handler.(*defaultAPIServer).group.handler.asyncOpWait = 0
server := httptest.NewServer(handler)
defer server.Close()
@@ -698,7 +700,7 @@ func TestCreateInvokesAdmissionControl(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if response.StatusCode != http.StatusConflict {
if response.StatusCode != http.StatusForbidden {
t.Errorf("Unexpected response %#v", response)
}
}

View File

@@ -38,7 +38,7 @@ type RESTHandler struct {
selfLinker runtime.SelfLinker
ops *Operations
asyncOpWait time.Duration
admissionControl admission.AdmissionControl
admissionControl admission.Interface
}
// ServeHTTP handles requests to all RESTStorage objects.
@@ -209,7 +209,7 @@ func (h *RESTHandler) handleRESTStorage(parts []string, req *http.Request, w htt
}
// invoke admission control
err = h.admissionControl.AdmissionControl("CREATE", parts[0], namespace, obj)
err = h.admissionControl.Admit(admission.NewAttributesRecord(obj, namespace, parts[0], "CREATE"))
if err != nil {
errorJSON(err, h.codec, w)
return
@@ -230,7 +230,7 @@ func (h *RESTHandler) handleRESTStorage(parts []string, req *http.Request, w htt
}
// invoke admission control
err := h.admissionControl.AdmissionControl("DELETE", parts[0], namespace, nil)
err := h.admissionControl.Admit(admission.NewAttributesRecord(nil, namespace, parts[0], "DELETE"))
if err != nil {
errorJSON(err, h.codec, w)
return
@@ -262,7 +262,7 @@ func (h *RESTHandler) handleRESTStorage(parts []string, req *http.Request, w htt
}
// invoke admission control
err = h.admissionControl.AdmissionControl("UPDATE", parts[0], namespace, obj)
err = h.admissionControl.Admit(admission.NewAttributesRecord(obj, namespace, parts[0], "UPDATE"))
if err != nil {
errorJSON(err, h.codec, w)
return