Commit 2452afff authored by Dr. Stefan Schimanski's avatar Dr. Stefan Schimanski

admission: wire create+update validation func into kube registries

parent 74b4223a
...@@ -33,6 +33,7 @@ import ( ...@@ -33,6 +33,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kruntime "k8s.io/apimachinery/pkg/runtime" kruntime "k8s.io/apimachinery/pkg/runtime"
apirequest "k8s.io/apiserver/pkg/endpoints/request" apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage" "k8s.io/apiserver/pkg/storage"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/endpoints" "k8s.io/kubernetes/pkg/api/endpoints"
...@@ -220,7 +221,7 @@ func (r *leaseEndpointReconciler) doReconcile(serviceName string, endpointPorts ...@@ -220,7 +221,7 @@ func (r *leaseEndpointReconciler) doReconcile(serviceName string, endpointPorts
} }
glog.Warningf("Resetting endpoints for master service %q to %v", serviceName, masterIPs) glog.Warningf("Resetting endpoints for master service %q to %v", serviceName, masterIPs)
return r.endpointRegistry.UpdateEndpoints(ctx, e) return r.endpointRegistry.UpdateEndpoints(ctx, e, rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
} }
// checkEndpointSubsetFormatWithLease determines if the endpoint is in the // checkEndpointSubsetFormatWithLease determines if the endpoint is in the
......
...@@ -33,8 +33,8 @@ type Registry interface { ...@@ -33,8 +33,8 @@ type Registry interface {
ListStatefulSets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*apps.StatefulSetList, error) ListStatefulSets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*apps.StatefulSetList, error)
WatchStatefulSets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchStatefulSets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
GetStatefulSet(ctx genericapirequest.Context, statefulSetID string, options *metav1.GetOptions) (*apps.StatefulSet, error) GetStatefulSet(ctx genericapirequest.Context, statefulSetID string, options *metav1.GetOptions) (*apps.StatefulSet, error)
CreateStatefulSet(ctx genericapirequest.Context, statefulSet *apps.StatefulSet) (*apps.StatefulSet, error) CreateStatefulSet(ctx genericapirequest.Context, statefulSet *apps.StatefulSet, createValidation rest.ValidateObjectFunc) (*apps.StatefulSet, error)
UpdateStatefulSet(ctx genericapirequest.Context, statefulSet *apps.StatefulSet) (*apps.StatefulSet, error) UpdateStatefulSet(ctx genericapirequest.Context, statefulSet *apps.StatefulSet, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*apps.StatefulSet, error)
DeleteStatefulSet(ctx genericapirequest.Context, statefulSetID string) error DeleteStatefulSet(ctx genericapirequest.Context, statefulSetID string) error
} }
...@@ -72,16 +72,16 @@ func (s *storage) GetStatefulSet(ctx genericapirequest.Context, statefulSetID st ...@@ -72,16 +72,16 @@ func (s *storage) GetStatefulSet(ctx genericapirequest.Context, statefulSetID st
return obj.(*apps.StatefulSet), nil return obj.(*apps.StatefulSet), nil
} }
func (s *storage) CreateStatefulSet(ctx genericapirequest.Context, statefulSet *apps.StatefulSet) (*apps.StatefulSet, error) { func (s *storage) CreateStatefulSet(ctx genericapirequest.Context, statefulSet *apps.StatefulSet, createValidation rest.ValidateObjectFunc) (*apps.StatefulSet, error) {
obj, err := s.Create(ctx, statefulSet, false) obj, err := s.Create(ctx, statefulSet, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return obj.(*apps.StatefulSet), nil return obj.(*apps.StatefulSet), nil
} }
func (s *storage) UpdateStatefulSet(ctx genericapirequest.Context, statefulSet *apps.StatefulSet) (*apps.StatefulSet, error) { func (s *storage) UpdateStatefulSet(ctx genericapirequest.Context, statefulSet *apps.StatefulSet, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*apps.StatefulSet, error) {
obj, _, err := s.Update(ctx, statefulSet.Name, rest.DefaultUpdatedObjectInfo(statefulSet)) obj, _, err := s.Update(ctx, statefulSet.Name, rest.DefaultUpdatedObjectInfo(statefulSet), createValidation, updateValidation)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -108,8 +108,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -108,8 +108,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
// Implement ShortNamesProvider // Implement ShortNamesProvider
...@@ -156,7 +156,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met ...@@ -156,7 +156,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return scale, err return scale, err
} }
func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
ss, err := r.registry.GetStatefulSet(ctx, name, &metav1.GetOptions{}) ss, err := r.registry.GetStatefulSet(ctx, name, &metav1.GetOptions{})
if err != nil { if err != nil {
return nil, false, err return nil, false, err
...@@ -185,7 +185,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r ...@@ -185,7 +185,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r
ss.Spec.Replicas = scale.Spec.Replicas ss.Spec.Replicas = scale.Spec.Replicas
ss.ResourceVersion = scale.ResourceVersion ss.ResourceVersion = scale.ResourceVersion
ss, err = r.registry.UpdateStatefulSet(ctx, ss) ss, err = r.registry.UpdateStatefulSet(ctx, ss, createValidation, updateValidation)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
} }
......
...@@ -46,7 +46,7 @@ func newStorage(t *testing.T) (StatefulSetStorage, *etcdtesting.EtcdTestServer) ...@@ -46,7 +46,7 @@ func newStorage(t *testing.T) (StatefulSetStorage, *etcdtesting.EtcdTestServer)
// createStatefulSet is a helper function that returns a StatefulSet with the updated resource version. // createStatefulSet is a helper function that returns a StatefulSet with the updated resource version.
func createStatefulSet(storage *REST, ps apps.StatefulSet, t *testing.T) (apps.StatefulSet, error) { func createStatefulSet(storage *REST, ps apps.StatefulSet, t *testing.T) (apps.StatefulSet, error) {
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), ps.Namespace) ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), ps.Namespace)
obj, err := storage.Create(ctx, &ps, false) obj, err := storage.Create(ctx, &ps, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Errorf("Failed to create StatefulSet, %v", err) t.Errorf("Failed to create StatefulSet, %v", err)
} }
...@@ -125,7 +125,7 @@ func TestStatusUpdate(t *testing.T) { ...@@ -125,7 +125,7 @@ func TestStatusUpdate(t *testing.T) {
}, },
} }
if _, _, err := storage.Status.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil { if _, _, err := storage.Status.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj, err := storage.StatefulSet.Get(ctx, "foo", &metav1.GetOptions{}) obj, err := storage.StatefulSet.Get(ctx, "foo", &metav1.GetOptions{})
...@@ -274,7 +274,7 @@ func TestScaleUpdate(t *testing.T) { ...@@ -274,7 +274,7 @@ func TestScaleUpdate(t *testing.T) {
}, },
} }
if _, _, err := storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil { if _, _, err := storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Fatalf("error updating scale %v: %v", update, err) t.Fatalf("error updating scale %v: %v", update, err)
} }
...@@ -290,7 +290,7 @@ func TestScaleUpdate(t *testing.T) { ...@@ -290,7 +290,7 @@ func TestScaleUpdate(t *testing.T) {
update.ResourceVersion = sts.ResourceVersion update.ResourceVersion = sts.ResourceVersion
update.Spec.Replicas = 15 update.Spec.Replicas = 15
if _, _, err = storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil && !errors.IsConflict(err) { if _, _, err = storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil && !errors.IsConflict(err) {
t.Fatalf("unexpected error, expecting an update conflict but got %v", err) t.Fatalf("unexpected error, expecting an update conflict but got %v", err)
} }
} }
......
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/authentication/authenticator" "k8s.io/apiserver/pkg/authentication/authenticator"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/authentication" "k8s.io/kubernetes/pkg/apis/authentication"
) )
...@@ -39,7 +40,7 @@ func (r *REST) New() runtime.Object { ...@@ -39,7 +40,7 @@ func (r *REST) New() runtime.Object {
return &authentication.TokenReview{} return &authentication.TokenReview{}
} }
func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
tokenReview, ok := obj.(*authentication.TokenReview) tokenReview, ok := obj.(*authentication.TokenReview)
if !ok { if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("not a TokenReview: %#v", obj)) return nil, apierrors.NewBadRequest(fmt.Sprintf("not a TokenReview: %#v", obj))
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/authorization/authorizer"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization" authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
authorizationvalidation "k8s.io/kubernetes/pkg/apis/authorization/validation" authorizationvalidation "k8s.io/kubernetes/pkg/apis/authorization/validation"
authorizationutil "k8s.io/kubernetes/pkg/registry/authorization/util" authorizationutil "k8s.io/kubernetes/pkg/registry/authorization/util"
...@@ -40,7 +41,7 @@ func (r *REST) New() runtime.Object { ...@@ -40,7 +41,7 @@ func (r *REST) New() runtime.Object {
return &authorizationapi.LocalSubjectAccessReview{} return &authorizationapi.LocalSubjectAccessReview{}
} }
func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
localSubjectAccessReview, ok := obj.(*authorizationapi.LocalSubjectAccessReview) localSubjectAccessReview, ok := obj.(*authorizationapi.LocalSubjectAccessReview)
if !ok { if !ok {
return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a LocaLocalSubjectAccessReview: %#v", obj)) return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a LocaLocalSubjectAccessReview: %#v", obj))
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/authorization/authorizer"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization" authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
authorizationvalidation "k8s.io/kubernetes/pkg/apis/authorization/validation" authorizationvalidation "k8s.io/kubernetes/pkg/apis/authorization/validation"
authorizationutil "k8s.io/kubernetes/pkg/registry/authorization/util" authorizationutil "k8s.io/kubernetes/pkg/registry/authorization/util"
...@@ -40,7 +41,7 @@ func (r *REST) New() runtime.Object { ...@@ -40,7 +41,7 @@ func (r *REST) New() runtime.Object {
return &authorizationapi.SelfSubjectAccessReview{} return &authorizationapi.SelfSubjectAccessReview{}
} }
func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
selfSAR, ok := obj.(*authorizationapi.SelfSubjectAccessReview) selfSAR, ok := obj.(*authorizationapi.SelfSubjectAccessReview)
if !ok { if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("not a SelfSubjectAccessReview: %#v", obj)) return nil, apierrors.NewBadRequest(fmt.Sprintf("not a SelfSubjectAccessReview: %#v", obj))
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/authorization/authorizer"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization" authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
) )
...@@ -42,7 +43,7 @@ func (r *REST) New() runtime.Object { ...@@ -42,7 +43,7 @@ func (r *REST) New() runtime.Object {
} }
// Create attempts to get self subject rules in specific namespace. // Create attempts to get self subject rules in specific namespace.
func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
selfSRR, ok := obj.(*authorizationapi.SelfSubjectRulesReview) selfSRR, ok := obj.(*authorizationapi.SelfSubjectRulesReview)
if !ok { if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("not a SelfSubjectRulesReview: %#v", obj)) return nil, apierrors.NewBadRequest(fmt.Sprintf("not a SelfSubjectRulesReview: %#v", obj))
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/authorization/authorizer"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization" authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
authorizationvalidation "k8s.io/kubernetes/pkg/apis/authorization/validation" authorizationvalidation "k8s.io/kubernetes/pkg/apis/authorization/validation"
authorizationutil "k8s.io/kubernetes/pkg/registry/authorization/util" authorizationutil "k8s.io/kubernetes/pkg/registry/authorization/util"
...@@ -40,7 +41,7 @@ func (r *REST) New() runtime.Object { ...@@ -40,7 +41,7 @@ func (r *REST) New() runtime.Object {
return &authorizationapi.SubjectAccessReview{} return &authorizationapi.SubjectAccessReview{}
} }
func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
subjectAccessReview, ok := obj.(*authorizationapi.SubjectAccessReview) subjectAccessReview, ok := obj.(*authorizationapi.SubjectAccessReview)
if !ok { if !ok {
return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a SubjectAccessReview: %#v", obj)) return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a SubjectAccessReview: %#v", obj))
......
...@@ -26,6 +26,7 @@ import ( ...@@ -26,6 +26,7 @@ import (
"k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/authorization/authorizer"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization" authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
) )
...@@ -174,9 +175,9 @@ func TestCreate(t *testing.T) { ...@@ -174,9 +175,9 @@ func TestCreate(t *testing.T) {
reason: tc.reason, reason: tc.reason,
err: tc.err, err: tc.err,
} }
rest := NewREST(auth) storage := NewREST(auth)
result, err := rest.Create(genericapirequest.NewContext(), &authorizationapi.SubjectAccessReview{Spec: tc.spec}, false) result, err := storage.Create(genericapirequest.NewContext(), &authorizationapi.SubjectAccessReview{Spec: tc.spec}, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
if tc.expectedErr != "" { if tc.expectedErr != "" {
if !strings.Contains(err.Error(), tc.expectedErr) { if !strings.Contains(err.Error(), tc.expectedErr) {
......
...@@ -83,6 +83,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -83,6 +83,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -81,6 +81,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -81,6 +81,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -98,6 +98,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -98,6 +98,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -28,8 +28,8 @@ import ( ...@@ -28,8 +28,8 @@ import (
// Registry is an interface for things that know how to store CSRs. // Registry is an interface for things that know how to store CSRs.
type Registry interface { type Registry interface {
ListCSRs(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*certificates.CertificateSigningRequestList, error) ListCSRs(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*certificates.CertificateSigningRequestList, error)
CreateCSR(ctx genericapirequest.Context, csr *certificates.CertificateSigningRequest) error CreateCSR(ctx genericapirequest.Context, csr *certificates.CertificateSigningRequest, createValidation rest.ValidateObjectFunc) error
UpdateCSR(ctx genericapirequest.Context, csr *certificates.CertificateSigningRequest) error UpdateCSR(ctx genericapirequest.Context, csr *certificates.CertificateSigningRequest, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
GetCSR(ctx genericapirequest.Context, csrID string, options *metav1.GetOptions) (*certificates.CertificateSigningRequest, error) GetCSR(ctx genericapirequest.Context, csrID string, options *metav1.GetOptions) (*certificates.CertificateSigningRequest, error)
DeleteCSR(ctx genericapirequest.Context, csrID string) error DeleteCSR(ctx genericapirequest.Context, csrID string) error
WatchCSRs(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchCSRs(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
...@@ -55,13 +55,13 @@ func (s *storage) ListCSRs(ctx genericapirequest.Context, options *metainternalv ...@@ -55,13 +55,13 @@ func (s *storage) ListCSRs(ctx genericapirequest.Context, options *metainternalv
return obj.(*certificates.CertificateSigningRequestList), nil return obj.(*certificates.CertificateSigningRequestList), nil
} }
func (s *storage) CreateCSR(ctx genericapirequest.Context, csr *certificates.CertificateSigningRequest) error { func (s *storage) CreateCSR(ctx genericapirequest.Context, csr *certificates.CertificateSigningRequest, createValidation rest.ValidateObjectFunc) error {
_, err := s.Create(ctx, csr, false) _, err := s.Create(ctx, csr, createValidation, false)
return err return err
} }
func (s *storage) UpdateCSR(ctx genericapirequest.Context, csr *certificates.CertificateSigningRequest) error { func (s *storage) UpdateCSR(ctx genericapirequest.Context, csr *certificates.CertificateSigningRequest, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, csr.Name, rest.DefaultUpdatedObjectInfo(csr)) _, _, err := s.Update(ctx, csr.Name, rest.DefaultUpdatedObjectInfo(csr), createValidation, updateValidation)
return err return err
} }
......
...@@ -78,8 +78,8 @@ func (r *StatusREST) New() runtime.Object { ...@@ -78,8 +78,8 @@ func (r *StatusREST) New() runtime.Object {
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
// ApprovalREST implements the REST endpoint for changing the approval state of a CSR. // ApprovalREST implements the REST endpoint for changing the approval state of a CSR.
...@@ -92,6 +92,6 @@ func (r *ApprovalREST) New() runtime.Object { ...@@ -92,6 +92,6 @@ func (r *ApprovalREST) New() runtime.Object {
} }
// Update alters the approval subset of an object. // Update alters the approval subset of an object.
func (r *ApprovalREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *ApprovalREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -30,8 +30,8 @@ type Registry interface { ...@@ -30,8 +30,8 @@ type Registry interface {
ListConfigMaps(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.ConfigMapList, error) ListConfigMaps(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.ConfigMapList, error)
WatchConfigMaps(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchConfigMaps(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
GetConfigMap(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*api.ConfigMap, error) GetConfigMap(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*api.ConfigMap, error)
CreateConfigMap(ctx genericapirequest.Context, cfg *api.ConfigMap) (*api.ConfigMap, error) CreateConfigMap(ctx genericapirequest.Context, cfg *api.ConfigMap, createValidation rest.ValidateObjectFunc) (*api.ConfigMap, error)
UpdateConfigMap(ctx genericapirequest.Context, cfg *api.ConfigMap) (*api.ConfigMap, error) UpdateConfigMap(ctx genericapirequest.Context, cfg *api.ConfigMap, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*api.ConfigMap, error)
DeleteConfigMap(ctx genericapirequest.Context, name string) error DeleteConfigMap(ctx genericapirequest.Context, name string) error
} }
...@@ -68,8 +68,8 @@ func (s *storage) GetConfigMap(ctx genericapirequest.Context, name string, optio ...@@ -68,8 +68,8 @@ func (s *storage) GetConfigMap(ctx genericapirequest.Context, name string, optio
return obj.(*api.ConfigMap), nil return obj.(*api.ConfigMap), nil
} }
func (s *storage) CreateConfigMap(ctx genericapirequest.Context, cfg *api.ConfigMap) (*api.ConfigMap, error) { func (s *storage) CreateConfigMap(ctx genericapirequest.Context, cfg *api.ConfigMap, createValidation rest.ValidateObjectFunc) (*api.ConfigMap, error) {
obj, err := s.Create(ctx, cfg, false) obj, err := s.Create(ctx, cfg, createValidation, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -77,8 +77,8 @@ func (s *storage) CreateConfigMap(ctx genericapirequest.Context, cfg *api.Config ...@@ -77,8 +77,8 @@ func (s *storage) CreateConfigMap(ctx genericapirequest.Context, cfg *api.Config
return obj.(*api.ConfigMap), nil return obj.(*api.ConfigMap), nil
} }
func (s *storage) UpdateConfigMap(ctx genericapirequest.Context, cfg *api.ConfigMap) (*api.ConfigMap, error) { func (s *storage) UpdateConfigMap(ctx genericapirequest.Context, cfg *api.ConfigMap, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*api.ConfigMap, error) {
obj, _, err := s.Update(ctx, cfg.Name, rest.DefaultUpdatedObjectInfo(cfg)) obj, _, err := s.Update(ctx, cfg.Name, rest.DefaultUpdatedObjectInfo(cfg), createValidation, updateValidation)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -30,7 +30,7 @@ type Registry interface { ...@@ -30,7 +30,7 @@ type Registry interface {
ListEndpoints(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.EndpointsList, error) ListEndpoints(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.EndpointsList, error)
GetEndpoints(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*api.Endpoints, error) GetEndpoints(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*api.Endpoints, error)
WatchEndpoints(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchEndpoints(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
UpdateEndpoints(ctx genericapirequest.Context, e *api.Endpoints) error UpdateEndpoints(ctx genericapirequest.Context, e *api.Endpoints, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
DeleteEndpoints(ctx genericapirequest.Context, name string) error DeleteEndpoints(ctx genericapirequest.Context, name string) error
} }
...@@ -65,8 +65,8 @@ func (s *storage) GetEndpoints(ctx genericapirequest.Context, name string, optio ...@@ -65,8 +65,8 @@ func (s *storage) GetEndpoints(ctx genericapirequest.Context, name string, optio
return obj.(*api.Endpoints), nil return obj.(*api.Endpoints), nil
} }
func (s *storage) UpdateEndpoints(ctx genericapirequest.Context, endpoints *api.Endpoints) error { func (s *storage) UpdateEndpoints(ctx genericapirequest.Context, endpoints *api.Endpoints, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, endpoints.Name, rest.DefaultUpdatedObjectInfo(endpoints)) _, _, err := s.Update(ctx, endpoints.Name, rest.DefaultUpdatedObjectInfo(endpoints), createValidation, updateValidation)
return err return err
} }
......
...@@ -30,8 +30,8 @@ type Registry interface { ...@@ -30,8 +30,8 @@ type Registry interface {
ListNamespaces(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.NamespaceList, error) ListNamespaces(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.NamespaceList, error)
WatchNamespaces(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchNamespaces(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
GetNamespace(ctx genericapirequest.Context, namespaceID string, options *metav1.GetOptions) (*api.Namespace, error) GetNamespace(ctx genericapirequest.Context, namespaceID string, options *metav1.GetOptions) (*api.Namespace, error)
CreateNamespace(ctx genericapirequest.Context, namespace *api.Namespace) error CreateNamespace(ctx genericapirequest.Context, namespace *api.Namespace, createValidation rest.ValidateObjectFunc) error
UpdateNamespace(ctx genericapirequest.Context, namespace *api.Namespace) error UpdateNamespace(ctx genericapirequest.Context, namespace *api.Namespace, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
DeleteNamespace(ctx genericapirequest.Context, namespaceID string) error DeleteNamespace(ctx genericapirequest.Context, namespaceID string) error
} }
...@@ -66,13 +66,13 @@ func (s *storage) GetNamespace(ctx genericapirequest.Context, namespaceName stri ...@@ -66,13 +66,13 @@ func (s *storage) GetNamespace(ctx genericapirequest.Context, namespaceName stri
return obj.(*api.Namespace), nil return obj.(*api.Namespace), nil
} }
func (s *storage) CreateNamespace(ctx genericapirequest.Context, namespace *api.Namespace) error { func (s *storage) CreateNamespace(ctx genericapirequest.Context, namespace *api.Namespace, createValidation rest.ValidateObjectFunc) error {
_, err := s.Create(ctx, namespace, false) _, err := s.Create(ctx, namespace, createValidation, false)
return err return err
} }
func (s *storage) UpdateNamespace(ctx genericapirequest.Context, namespace *api.Namespace) error { func (s *storage) UpdateNamespace(ctx genericapirequest.Context, namespace *api.Namespace, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, namespace.Name, rest.DefaultUpdatedObjectInfo(namespace)) _, _, err := s.Update(ctx, namespace.Name, rest.DefaultUpdatedObjectInfo(namespace), createValidation, updateValidation)
return err return err
} }
......
...@@ -89,12 +89,12 @@ func (r *REST) List(ctx genericapirequest.Context, options *metainternalversion. ...@@ -89,12 +89,12 @@ func (r *REST) List(ctx genericapirequest.Context, options *metainternalversion.
return r.store.List(ctx, options) return r.store.List(ctx, options)
} }
func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
return r.store.Create(ctx, obj, includeUninitialized) return r.store.Create(ctx, obj, createValidation, includeUninitialized)
} }
func (r *REST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *REST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
func (r *REST) Get(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (runtime.Object, error) { func (r *REST) Get(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
...@@ -219,8 +219,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -219,8 +219,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
func (r *FinalizeREST) New() runtime.Object { func (r *FinalizeREST) New() runtime.Object {
...@@ -228,6 +228,6 @@ func (r *FinalizeREST) New() runtime.Object { ...@@ -228,6 +228,6 @@ func (r *FinalizeREST) New() runtime.Object {
} }
// Update alters the status finalizers subset of an object. // Update alters the status finalizers subset of an object.
func (r *FinalizeREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *FinalizeREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest"
etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing" etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/registry/registrytest" "k8s.io/kubernetes/pkg/registry/registrytest"
...@@ -67,7 +68,7 @@ func TestCreateSetsFields(t *testing.T) { ...@@ -67,7 +68,7 @@ func TestCreateSetsFields(t *testing.T) {
defer storage.store.DestroyFunc() defer storage.store.DestroyFunc()
namespace := validNewNamespace() namespace := validNewNamespace()
ctx := genericapirequest.NewContext() ctx := genericapirequest.NewContext()
_, err := storage.Create(ctx, namespace, false) _, err := storage.Create(ctx, namespace, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
......
...@@ -28,8 +28,8 @@ import ( ...@@ -28,8 +28,8 @@ import (
// Registry is an interface for things that know how to store node. // Registry is an interface for things that know how to store node.
type Registry interface { type Registry interface {
ListNodes(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.NodeList, error) ListNodes(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.NodeList, error)
CreateNode(ctx genericapirequest.Context, node *api.Node) error CreateNode(ctx genericapirequest.Context, node *api.Node, createValidation rest.ValidateObjectFunc) error
UpdateNode(ctx genericapirequest.Context, node *api.Node) error UpdateNode(ctx genericapirequest.Context, node *api.Node, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
GetNode(ctx genericapirequest.Context, nodeID string, options *metav1.GetOptions) (*api.Node, error) GetNode(ctx genericapirequest.Context, nodeID string, options *metav1.GetOptions) (*api.Node, error)
DeleteNode(ctx genericapirequest.Context, nodeID string) error DeleteNode(ctx genericapirequest.Context, nodeID string) error
WatchNodes(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchNodes(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
...@@ -55,13 +55,13 @@ func (s *storage) ListNodes(ctx genericapirequest.Context, options *metainternal ...@@ -55,13 +55,13 @@ func (s *storage) ListNodes(ctx genericapirequest.Context, options *metainternal
return obj.(*api.NodeList), nil return obj.(*api.NodeList), nil
} }
func (s *storage) CreateNode(ctx genericapirequest.Context, node *api.Node) error { func (s *storage) CreateNode(ctx genericapirequest.Context, node *api.Node, createValidation rest.ValidateObjectFunc) error {
_, err := s.Create(ctx, node, false) _, err := s.Create(ctx, node, createValidation, false)
return err return err
} }
func (s *storage) UpdateNode(ctx genericapirequest.Context, node *api.Node) error { func (s *storage) UpdateNode(ctx genericapirequest.Context, node *api.Node, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, node.Name, rest.DefaultUpdatedObjectInfo(node)) _, _, err := s.Update(ctx, node.Name, rest.DefaultUpdatedObjectInfo(node), createValidation, updateValidation)
return err return err
} }
......
...@@ -68,8 +68,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -68,8 +68,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
// NewStorage returns a NodeStorage object that will work against nodes. // NewStorage returns a NodeStorage object that will work against nodes.
......
...@@ -78,6 +78,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -78,6 +78,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -187,7 +187,7 @@ func TestUpdateStatus(t *testing.T) { ...@@ -187,7 +187,7 @@ func TestUpdateStatus(t *testing.T) {
}, },
} }
_, _, err = statusStorage.Update(ctx, pvIn.Name, rest.DefaultUpdatedObjectInfo(pvIn)) _, _, err = statusStorage.Update(ctx, pvIn.Name, rest.DefaultUpdatedObjectInfo(pvIn), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
......
...@@ -78,6 +78,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -78,6 +78,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -178,7 +178,7 @@ func TestUpdateStatus(t *testing.T) { ...@@ -178,7 +178,7 @@ func TestUpdateStatus(t *testing.T) {
}, },
} }
_, _, err = statusStorage.Update(ctx, pvc.Name, rest.DefaultUpdatedObjectInfo(pvc)) _, _, err = statusStorage.Update(ctx, pvc.Name, rest.DefaultUpdatedObjectInfo(pvc), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
......
...@@ -78,7 +78,7 @@ func (r *EvictionREST) New() runtime.Object { ...@@ -78,7 +78,7 @@ func (r *EvictionREST) New() runtime.Object {
} }
// Create attempts to create a new eviction. That is, it tries to evict a pod. // Create attempts to create a new eviction. That is, it tries to evict a pod.
func (r *EvictionREST) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (r *EvictionREST) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
eviction := obj.(*policy.Eviction) eviction := obj.(*policy.Eviction)
obj, err := r.store.Get(ctx, eviction.Name, &metav1.GetOptions{}) obj, err := r.store.Get(ctx, eviction.Name, &metav1.GetOptions{})
......
...@@ -135,7 +135,7 @@ func (r *BindingREST) New() runtime.Object { ...@@ -135,7 +135,7 @@ func (r *BindingREST) New() runtime.Object {
var _ = rest.Creater(&BindingREST{}) var _ = rest.Creater(&BindingREST{})
// Create ensures a pod is bound to a specific host. // Create ensures a pod is bound to a specific host.
func (r *BindingREST) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (out runtime.Object, err error) { func (r *BindingREST) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (out runtime.Object, err error) {
binding := obj.(*api.Binding) binding := obj.(*api.Binding)
// TODO: move me to a binding strategy // TODO: move me to a binding strategy
...@@ -212,6 +212,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -212,6 +212,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -188,7 +188,7 @@ func TestIgnoreDeleteNotFound(t *testing.T) { ...@@ -188,7 +188,7 @@ func TestIgnoreDeleteNotFound(t *testing.T) {
} }
// create pod // create pod
_, err = registry.Create(testContext, pod, false) _, err = registry.Create(testContext, pod, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
...@@ -225,7 +225,7 @@ func TestCreateSetsFields(t *testing.T) { ...@@ -225,7 +225,7 @@ func TestCreateSetsFields(t *testing.T) {
defer server.Terminate(t) defer server.Terminate(t)
defer storage.Store.DestroyFunc() defer storage.Store.DestroyFunc()
pod := validNewPod() pod := validNewPod()
_, err := storage.Create(genericapirequest.NewDefaultContext(), pod, false) _, err := storage.Create(genericapirequest.NewDefaultContext(), pod, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -489,7 +489,7 @@ func TestEtcdCreate(t *testing.T) { ...@@ -489,7 +489,7 @@ func TestEtcdCreate(t *testing.T) {
defer server.Terminate(t) defer server.Terminate(t)
defer storage.Store.DestroyFunc() defer storage.Store.DestroyFunc()
ctx := genericapirequest.NewDefaultContext() ctx := genericapirequest.NewDefaultContext()
_, err := storage.Create(ctx, validNewPod(), false) _, err := storage.Create(ctx, validNewPod(), rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -498,7 +498,7 @@ func TestEtcdCreate(t *testing.T) { ...@@ -498,7 +498,7 @@ func TestEtcdCreate(t *testing.T) {
_, err = bindingStorage.Create(ctx, &api.Binding{ _, err = bindingStorage.Create(ctx, &api.Binding{
ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "foo"},
Target: api.ObjectReference{Name: "machine"}, Target: api.ObjectReference{Name: "machine"},
}, false) }, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -524,7 +524,7 @@ func TestEtcdCreateBindingNoPod(t *testing.T) { ...@@ -524,7 +524,7 @@ func TestEtcdCreateBindingNoPod(t *testing.T) {
_, err := bindingStorage.Create(ctx, &api.Binding{ _, err := bindingStorage.Create(ctx, &api.Binding{
ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "foo"},
Target: api.ObjectReference{Name: "machine"}, Target: api.ObjectReference{Name: "machine"},
}, false) }, rest.ValidateAllObjectFunc, false)
if err == nil { if err == nil {
t.Fatalf("Expected not-found-error but got nothing") t.Fatalf("Expected not-found-error but got nothing")
} }
...@@ -547,7 +547,7 @@ func TestEtcdCreateFailsWithoutNamespace(t *testing.T) { ...@@ -547,7 +547,7 @@ func TestEtcdCreateFailsWithoutNamespace(t *testing.T) {
defer storage.Store.DestroyFunc() defer storage.Store.DestroyFunc()
pod := validNewPod() pod := validNewPod()
pod.Namespace = "" pod.Namespace = ""
_, err := storage.Create(genericapirequest.NewContext(), pod, false) _, err := storage.Create(genericapirequest.NewContext(), pod, rest.ValidateAllObjectFunc, false)
// Accept "namespace" or "Namespace". // Accept "namespace" or "Namespace".
if err == nil || !strings.Contains(err.Error(), "amespace") { if err == nil || !strings.Contains(err.Error(), "amespace") {
t.Fatalf("expected error that namespace was missing from context, got: %v", err) t.Fatalf("expected error that namespace was missing from context, got: %v", err)
...@@ -559,7 +559,7 @@ func TestEtcdCreateWithContainersNotFound(t *testing.T) { ...@@ -559,7 +559,7 @@ func TestEtcdCreateWithContainersNotFound(t *testing.T) {
defer server.Terminate(t) defer server.Terminate(t)
defer storage.Store.DestroyFunc() defer storage.Store.DestroyFunc()
ctx := genericapirequest.NewDefaultContext() ctx := genericapirequest.NewDefaultContext()
_, err := storage.Create(ctx, validNewPod(), false) _, err := storage.Create(ctx, validNewPod(), rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -572,7 +572,7 @@ func TestEtcdCreateWithContainersNotFound(t *testing.T) { ...@@ -572,7 +572,7 @@ func TestEtcdCreateWithContainersNotFound(t *testing.T) {
Annotations: map[string]string{"label1": "value1"}, Annotations: map[string]string{"label1": "value1"},
}, },
Target: api.ObjectReference{Name: "machine"}, Target: api.ObjectReference{Name: "machine"},
}, false) }, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -594,7 +594,7 @@ func TestEtcdCreateWithConflict(t *testing.T) { ...@@ -594,7 +594,7 @@ func TestEtcdCreateWithConflict(t *testing.T) {
defer storage.Store.DestroyFunc() defer storage.Store.DestroyFunc()
ctx := genericapirequest.NewDefaultContext() ctx := genericapirequest.NewDefaultContext()
_, err := storage.Create(ctx, validNewPod(), false) _, err := storage.Create(ctx, validNewPod(), rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -608,12 +608,12 @@ func TestEtcdCreateWithConflict(t *testing.T) { ...@@ -608,12 +608,12 @@ func TestEtcdCreateWithConflict(t *testing.T) {
}, },
Target: api.ObjectReference{Name: "machine"}, Target: api.ObjectReference{Name: "machine"},
} }
_, err = bindingStorage.Create(ctx, &binding, false) _, err = bindingStorage.Create(ctx, &binding, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
_, err = bindingStorage.Create(ctx, &binding, false) _, err = bindingStorage.Create(ctx, &binding, rest.ValidateAllObjectFunc, false)
if err == nil || !errors.IsConflict(err) { if err == nil || !errors.IsConflict(err) {
t.Fatalf("expected resource conflict error, not: %v", err) t.Fatalf("expected resource conflict error, not: %v", err)
} }
...@@ -624,7 +624,7 @@ func TestEtcdCreateWithExistingContainers(t *testing.T) { ...@@ -624,7 +624,7 @@ func TestEtcdCreateWithExistingContainers(t *testing.T) {
defer server.Terminate(t) defer server.Terminate(t)
defer storage.Store.DestroyFunc() defer storage.Store.DestroyFunc()
ctx := genericapirequest.NewDefaultContext() ctx := genericapirequest.NewDefaultContext()
_, err := storage.Create(ctx, validNewPod(), false) _, err := storage.Create(ctx, validNewPod(), rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -633,7 +633,7 @@ func TestEtcdCreateWithExistingContainers(t *testing.T) { ...@@ -633,7 +633,7 @@ func TestEtcdCreateWithExistingContainers(t *testing.T) {
_, err = bindingStorage.Create(ctx, &api.Binding{ _, err = bindingStorage.Create(ctx, &api.Binding{
ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "foo"},
Target: api.ObjectReference{Name: "machine"}, Target: api.ObjectReference{Name: "machine"},
}, false) }, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -683,10 +683,10 @@ func TestEtcdCreateBinding(t *testing.T) { ...@@ -683,10 +683,10 @@ func TestEtcdCreateBinding(t *testing.T) {
for k, test := range testCases { for k, test := range testCases {
storage, bindingStorage, _, server := newStorage(t) storage, bindingStorage, _, server := newStorage(t)
if _, err := storage.Create(ctx, validNewPod(), false); err != nil { if _, err := storage.Create(ctx, validNewPod(), rest.ValidateAllObjectFunc, false); err != nil {
t.Fatalf("%s: unexpected error: %v", k, err) t.Fatalf("%s: unexpected error: %v", k, err)
} }
if _, err := bindingStorage.Create(ctx, &test.binding, false); !test.errOK(err) { if _, err := bindingStorage.Create(ctx, &test.binding, rest.ValidateAllObjectFunc, false); !test.errOK(err) {
t.Errorf("%s: unexpected error: %v", k, err) t.Errorf("%s: unexpected error: %v", k, err)
} else if err == nil { } else if err == nil {
// If bind succeeded, verify Host field in pod's Spec. // If bind succeeded, verify Host field in pod's Spec.
...@@ -712,7 +712,7 @@ func TestEtcdUpdateUninitialized(t *testing.T) { ...@@ -712,7 +712,7 @@ func TestEtcdUpdateUninitialized(t *testing.T) {
pod := validNewPod() pod := validNewPod()
// add pending initializers to the pod // add pending initializers to the pod
pod.ObjectMeta.Initializers = &metav1.Initializers{Pending: []metav1.Initializer{{Name: "init.k8s.io"}}} pod.ObjectMeta.Initializers = &metav1.Initializers{Pending: []metav1.Initializer{{Name: "init.k8s.io"}}}
if _, err := storage.Create(ctx, pod, true); err != nil { if _, err := storage.Create(ctx, pod, rest.ValidateAllObjectFunc, true); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
podIn := *pod podIn := *pod
...@@ -727,7 +727,7 @@ func TestEtcdUpdateUninitialized(t *testing.T) { ...@@ -727,7 +727,7 @@ func TestEtcdUpdateUninitialized(t *testing.T) {
}) })
podIn.ObjectMeta.Initializers = nil podIn.ObjectMeta.Initializers = nil
_, _, err := storage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(&podIn)) _, _, err := storage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(&podIn), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
...@@ -754,7 +754,7 @@ func TestEtcdStatusUpdateUninitialized(t *testing.T) { ...@@ -754,7 +754,7 @@ func TestEtcdStatusUpdateUninitialized(t *testing.T) {
pod := validNewPod() pod := validNewPod()
// add pending initializers to the pod // add pending initializers to the pod
pod.ObjectMeta.Initializers = &metav1.Initializers{Pending: []metav1.Initializer{{Name: "init.k8s.io"}}} pod.ObjectMeta.Initializers = &metav1.Initializers{Pending: []metav1.Initializer{{Name: "init.k8s.io"}}}
if _, err := storage.Create(ctx, pod, true); err != nil { if _, err := storage.Create(ctx, pod, rest.ValidateAllObjectFunc, true); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
podIn := *pod podIn := *pod
...@@ -762,7 +762,7 @@ func TestEtcdStatusUpdateUninitialized(t *testing.T) { ...@@ -762,7 +762,7 @@ func TestEtcdStatusUpdateUninitialized(t *testing.T) {
podIn.Status.Phase = api.PodRunning podIn.Status.Phase = api.PodRunning
podIn.ObjectMeta.Initializers = nil podIn.ObjectMeta.Initializers = nil
_, _, err := statusStorage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(&podIn)) _, _, err := statusStorage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(&podIn), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
expected := "Forbidden: must not update status when the object is uninitialized" expected := "Forbidden: must not update status when the object is uninitialized"
if err == nil { if err == nil {
t.Fatalf("Unexpected no err, expected %q", expected) t.Fatalf("Unexpected no err, expected %q", expected)
...@@ -778,12 +778,12 @@ func TestEtcdUpdateNotScheduled(t *testing.T) { ...@@ -778,12 +778,12 @@ func TestEtcdUpdateNotScheduled(t *testing.T) {
defer storage.Store.DestroyFunc() defer storage.Store.DestroyFunc()
ctx := genericapirequest.NewDefaultContext() ctx := genericapirequest.NewDefaultContext()
if _, err := storage.Create(ctx, validNewPod(), false); err != nil { if _, err := storage.Create(ctx, validNewPod(), rest.ValidateAllObjectFunc, false); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
podIn := validChangedPod() podIn := validChangedPod()
_, _, err := storage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(podIn)) _, _, err := storage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(podIn), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
...@@ -853,7 +853,7 @@ func TestEtcdUpdateScheduled(t *testing.T) { ...@@ -853,7 +853,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
SchedulerName: api.DefaultSchedulerName, SchedulerName: api.DefaultSchedulerName,
}, },
} }
_, _, err = storage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(&podIn)) _, _, err = storage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(&podIn), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
...@@ -937,7 +937,7 @@ func TestEtcdUpdateStatus(t *testing.T) { ...@@ -937,7 +937,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
expected.Labels = podIn.Labels expected.Labels = podIn.Labels
expected.Status = podIn.Status expected.Status = podIn.Status
_, _, err = statusStorage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(&podIn)) _, _, err = statusStorage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(&podIn), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
......
...@@ -34,8 +34,8 @@ type Registry interface { ...@@ -34,8 +34,8 @@ type Registry interface {
ListControllers(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.ReplicationControllerList, error) ListControllers(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.ReplicationControllerList, error)
WatchControllers(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchControllers(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
GetController(ctx genericapirequest.Context, controllerID string, options *metav1.GetOptions) (*api.ReplicationController, error) GetController(ctx genericapirequest.Context, controllerID string, options *metav1.GetOptions) (*api.ReplicationController, error)
CreateController(ctx genericapirequest.Context, controller *api.ReplicationController) (*api.ReplicationController, error) CreateController(ctx genericapirequest.Context, controller *api.ReplicationController, createValidation rest.ValidateObjectFunc) (*api.ReplicationController, error)
UpdateController(ctx genericapirequest.Context, controller *api.ReplicationController) (*api.ReplicationController, error) UpdateController(ctx genericapirequest.Context, controller *api.ReplicationController, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*api.ReplicationController, error)
DeleteController(ctx genericapirequest.Context, controllerID string) error DeleteController(ctx genericapirequest.Context, controllerID string) error
} }
...@@ -73,16 +73,16 @@ func (s *storage) GetController(ctx genericapirequest.Context, controllerID stri ...@@ -73,16 +73,16 @@ func (s *storage) GetController(ctx genericapirequest.Context, controllerID stri
return obj.(*api.ReplicationController), nil return obj.(*api.ReplicationController), nil
} }
func (s *storage) CreateController(ctx genericapirequest.Context, controller *api.ReplicationController) (*api.ReplicationController, error) { func (s *storage) CreateController(ctx genericapirequest.Context, controller *api.ReplicationController, createValidation rest.ValidateObjectFunc) (*api.ReplicationController, error) {
obj, err := s.Create(ctx, controller, false) obj, err := s.Create(ctx, controller, createValidation, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return obj.(*api.ReplicationController), nil return obj.(*api.ReplicationController), nil
} }
func (s *storage) UpdateController(ctx genericapirequest.Context, controller *api.ReplicationController) (*api.ReplicationController, error) { func (s *storage) UpdateController(ctx genericapirequest.Context, controller *api.ReplicationController, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*api.ReplicationController, error) {
obj, _, err := s.Update(ctx, controller.Name, rest.DefaultUpdatedObjectInfo(controller)) obj, _, err := s.Update(ctx, controller.Name, rest.DefaultUpdatedObjectInfo(controller), createValidation, updateValidation)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -119,8 +119,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -119,8 +119,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
type ScaleREST struct { type ScaleREST struct {
...@@ -153,13 +153,14 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met ...@@ -153,13 +153,14 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return scaleFromRC(rc), nil return scaleFromRC(rc), nil
} }
func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
rc, err := r.registry.GetController(ctx, name, &metav1.GetOptions{}) rc, err := r.registry.GetController(ctx, name, &metav1.GetOptions{})
if err != nil { if err != nil {
return nil, false, errors.NewNotFound(autoscaling.Resource("replicationcontrollers/scale"), name) return nil, false, errors.NewNotFound(autoscaling.Resource("replicationcontrollers/scale"), name)
} }
oldScale := scaleFromRC(rc) oldScale := scaleFromRC(rc)
// TODO: should this pass validation?
obj, err := objInfo.UpdatedObject(ctx, oldScale) obj, err := objInfo.UpdatedObject(ctx, oldScale)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
...@@ -179,7 +180,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r ...@@ -179,7 +180,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r
rc.Spec.Replicas = scale.Spec.Replicas rc.Spec.Replicas = scale.Spec.Replicas
rc.ResourceVersion = scale.ResourceVersion rc.ResourceVersion = scale.ResourceVersion
rc, err = r.registry.UpdateController(ctx, rc) rc, err = r.registry.UpdateController(ctx, rc, createValidation, updateValidation)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
} }
......
...@@ -55,7 +55,7 @@ func newStorage(t *testing.T) (ControllerStorage, *etcdtesting.EtcdTestServer) { ...@@ -55,7 +55,7 @@ func newStorage(t *testing.T) (ControllerStorage, *etcdtesting.EtcdTestServer) {
// createController is a helper function that returns a controller with the updated resource version. // createController is a helper function that returns a controller with the updated resource version.
func createController(storage *REST, rc api.ReplicationController, t *testing.T) (api.ReplicationController, error) { func createController(storage *REST, rc api.ReplicationController, t *testing.T) (api.ReplicationController, error) {
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), rc.Namespace) ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), rc.Namespace)
obj, err := storage.Create(ctx, &rc, false) obj, err := storage.Create(ctx, &rc, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Errorf("Failed to create controller, %v", err) t.Errorf("Failed to create controller, %v", err)
} }
...@@ -173,7 +173,7 @@ func TestGenerationNumber(t *testing.T) { ...@@ -173,7 +173,7 @@ func TestGenerationNumber(t *testing.T) {
// Updates to spec should increment the generation number // Updates to spec should increment the generation number
controller.Spec.Replicas += 1 controller.Spec.Replicas += 1
storage.Controller.Update(ctx, controller.Name, rest.DefaultUpdatedObjectInfo(controller)) storage.Controller.Update(ctx, controller.Name, rest.DefaultUpdatedObjectInfo(controller), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -188,7 +188,7 @@ func TestGenerationNumber(t *testing.T) { ...@@ -188,7 +188,7 @@ func TestGenerationNumber(t *testing.T) {
// Updates to status should not increment either spec or status generation numbers // Updates to status should not increment either spec or status generation numbers
controller.Status.Replicas += 1 controller.Status.Replicas += 1
storage.Controller.Update(ctx, controller.Name, rest.DefaultUpdatedObjectInfo(controller)) storage.Controller.Update(ctx, controller.Name, rest.DefaultUpdatedObjectInfo(controller), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -308,7 +308,7 @@ func TestScaleUpdate(t *testing.T) { ...@@ -308,7 +308,7 @@ func TestScaleUpdate(t *testing.T) {
}, },
} }
if _, _, err := storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil { if _, _, err := storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Fatalf("error updating scale %v: %v", update, err) t.Fatalf("error updating scale %v: %v", update, err)
} }
obj, err := storage.Scale.Get(ctx, name, &metav1.GetOptions{}) obj, err := storage.Scale.Get(ctx, name, &metav1.GetOptions{})
...@@ -323,7 +323,7 @@ func TestScaleUpdate(t *testing.T) { ...@@ -323,7 +323,7 @@ func TestScaleUpdate(t *testing.T) {
update.ResourceVersion = rc.ResourceVersion update.ResourceVersion = rc.ResourceVersion
update.Spec.Replicas = 15 update.Spec.Replicas = 15
if _, _, err = storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil && !errors.IsConflict(err) { if _, _, err = storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil && !errors.IsConflict(err) {
t.Fatalf("unexpected error, expecting an update conflict but got %v", err) t.Fatalf("unexpected error, expecting an update conflict but got %v", err)
} }
} }
......
...@@ -77,6 +77,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -77,6 +77,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -87,7 +87,7 @@ func TestCreateSetsFields(t *testing.T) { ...@@ -87,7 +87,7 @@ func TestCreateSetsFields(t *testing.T) {
defer storage.Store.DestroyFunc() defer storage.Store.DestroyFunc()
ctx := genericapirequest.NewDefaultContext() ctx := genericapirequest.NewDefaultContext()
resourcequota := validNewResourceQuota() resourcequota := validNewResourceQuota()
_, err := storage.Create(genericapirequest.NewDefaultContext(), resourcequota, false) _, err := storage.Create(genericapirequest.NewDefaultContext(), resourcequota, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -191,7 +191,7 @@ func TestUpdateStatus(t *testing.T) { ...@@ -191,7 +191,7 @@ func TestUpdateStatus(t *testing.T) {
}, },
} }
_, _, err = status.Update(ctx, resourcequotaIn.Name, rest.DefaultUpdatedObjectInfo(resourcequotaIn)) _, _, err = status.Update(ctx, resourcequotaIn.Name, rest.DefaultUpdatedObjectInfo(resourcequotaIn), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
......
...@@ -30,8 +30,8 @@ type Registry interface { ...@@ -30,8 +30,8 @@ type Registry interface {
ListSecrets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.SecretList, error) ListSecrets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.SecretList, error)
WatchSecrets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchSecrets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
GetSecret(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*api.Secret, error) GetSecret(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*api.Secret, error)
CreateSecret(ctx genericapirequest.Context, Secret *api.Secret) (*api.Secret, error) CreateSecret(ctx genericapirequest.Context, Secret *api.Secret, createValidation rest.ValidateObjectFunc) (*api.Secret, error)
UpdateSecret(ctx genericapirequest.Context, Secret *api.Secret) (*api.Secret, error) UpdateSecret(ctx genericapirequest.Context, Secret *api.Secret, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*api.Secret, error)
DeleteSecret(ctx genericapirequest.Context, name string) error DeleteSecret(ctx genericapirequest.Context, name string) error
} }
...@@ -66,13 +66,13 @@ func (s *storage) GetSecret(ctx genericapirequest.Context, name string, options ...@@ -66,13 +66,13 @@ func (s *storage) GetSecret(ctx genericapirequest.Context, name string, options
return obj.(*api.Secret), nil return obj.(*api.Secret), nil
} }
func (s *storage) CreateSecret(ctx genericapirequest.Context, secret *api.Secret) (*api.Secret, error) { func (s *storage) CreateSecret(ctx genericapirequest.Context, secret *api.Secret, createValidation rest.ValidateObjectFunc) (*api.Secret, error) {
obj, err := s.Create(ctx, secret, false) obj, err := s.Create(ctx, secret, createValidation, false)
return obj.(*api.Secret), err return obj.(*api.Secret), err
} }
func (s *storage) UpdateSecret(ctx genericapirequest.Context, secret *api.Secret) (*api.Secret, error) { func (s *storage) UpdateSecret(ctx genericapirequest.Context, secret *api.Secret, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*api.Secret, error) {
obj, _, err := s.Update(ctx, secret.Name, rest.DefaultUpdatedObjectInfo(secret)) obj, _, err := s.Update(ctx, secret.Name, rest.DefaultUpdatedObjectInfo(secret), createValidation, updateValidation)
return obj.(*api.Secret), err return obj.(*api.Secret), err
} }
......
...@@ -30,10 +30,10 @@ import ( ...@@ -30,10 +30,10 @@ import (
// Registry is an interface for things that know how to store services. // Registry is an interface for things that know how to store services.
type Registry interface { type Registry interface {
ListServices(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.ServiceList, error) ListServices(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.ServiceList, error)
CreateService(ctx genericapirequest.Context, svc *api.Service) (*api.Service, error) CreateService(ctx genericapirequest.Context, svc *api.Service, createValidation rest.ValidateObjectFunc) (*api.Service, error)
GetService(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*api.Service, error) GetService(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*api.Service, error)
DeleteService(ctx genericapirequest.Context, name string) error DeleteService(ctx genericapirequest.Context, name string) error
UpdateService(ctx genericapirequest.Context, svc *api.Service) (*api.Service, error) UpdateService(ctx genericapirequest.Context, svc *api.Service, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*api.Service, error)
WatchServices(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchServices(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
ExportService(ctx genericapirequest.Context, name string, options metav1.ExportOptions) (*api.Service, error) ExportService(ctx genericapirequest.Context, name string, options metav1.ExportOptions) (*api.Service, error)
} }
...@@ -57,8 +57,8 @@ func (s *storage) ListServices(ctx genericapirequest.Context, options *metainter ...@@ -57,8 +57,8 @@ func (s *storage) ListServices(ctx genericapirequest.Context, options *metainter
return obj.(*api.ServiceList), nil return obj.(*api.ServiceList), nil
} }
func (s *storage) CreateService(ctx genericapirequest.Context, svc *api.Service) (*api.Service, error) { func (s *storage) CreateService(ctx genericapirequest.Context, svc *api.Service, createValidation rest.ValidateObjectFunc) (*api.Service, error) {
obj, err := s.Create(ctx, svc, false) obj, err := s.Create(ctx, svc, createValidation, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -78,8 +78,8 @@ func (s *storage) DeleteService(ctx genericapirequest.Context, name string) erro ...@@ -78,8 +78,8 @@ func (s *storage) DeleteService(ctx genericapirequest.Context, name string) erro
return err return err
} }
func (s *storage) UpdateService(ctx genericapirequest.Context, svc *api.Service) (*api.Service, error) { func (s *storage) UpdateService(ctx genericapirequest.Context, svc *api.Service, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*api.Service, error) {
obj, _, err := s.Update(ctx, svc.Name, rest.DefaultUpdatedObjectInfo(svc)) obj, _, err := s.Update(ctx, svc.Name, rest.DefaultUpdatedObjectInfo(svc), createValidation, updateValidation)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -88,7 +88,7 @@ func (rs *REST) Categories() []string { ...@@ -88,7 +88,7 @@ func (rs *REST) Categories() []string {
} }
// TODO: implement includeUninitialized by refactoring this to move to store // TODO: implement includeUninitialized by refactoring this to move to store
func (rs *REST) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (rs *REST) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
service := obj.(*api.Service) service := obj.(*api.Service)
if err := rest.BeforeCreate(Strategy, ctx, obj); err != nil { if err := rest.BeforeCreate(Strategy, ctx, obj); err != nil {
...@@ -133,7 +133,7 @@ func (rs *REST) Create(ctx genericapirequest.Context, obj runtime.Object, includ ...@@ -133,7 +133,7 @@ func (rs *REST) Create(ctx genericapirequest.Context, obj runtime.Object, includ
} }
} }
out, err := rs.registry.CreateService(ctx, service) out, err := rs.registry.CreateService(ctx, service, createValidation)
if err != nil { if err != nil {
err = rest.CheckGeneratedNameError(Strategy, err, service) err = rest.CheckGeneratedNameError(Strategy, err, service)
} }
...@@ -284,7 +284,7 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service, node ...@@ -284,7 +284,7 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service, node
return true, nil return true, nil
} }
func (rs *REST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (rs *REST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
oldService, err := rs.registry.GetService(ctx, name, &metav1.GetOptions{}) oldService, err := rs.registry.GetService(ctx, name, &metav1.GetOptions{})
if err != nil { if err != nil {
return nil, false, err return nil, false, err
...@@ -360,7 +360,7 @@ func (rs *REST) Update(ctx genericapirequest.Context, name string, objInfo rest. ...@@ -360,7 +360,7 @@ func (rs *REST) Update(ctx genericapirequest.Context, name string, objInfo rest.
} }
} }
out, err := rs.registry.UpdateService(ctx, service) out, err := rs.registry.UpdateService(ctx, service, createValidation, updateValidation)
if err == nil { if err == nil {
el := nodePortOp.Commit() el := nodePortOp.Commit()
if el != nil { if el != nil {
......
...@@ -89,6 +89,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -89,6 +89,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -30,8 +30,8 @@ type Registry interface { ...@@ -30,8 +30,8 @@ type Registry interface {
ListServiceAccounts(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.ServiceAccountList, error) ListServiceAccounts(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*api.ServiceAccountList, error)
WatchServiceAccounts(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchServiceAccounts(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
GetServiceAccount(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*api.ServiceAccount, error) GetServiceAccount(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*api.ServiceAccount, error)
CreateServiceAccount(ctx genericapirequest.Context, ServiceAccount *api.ServiceAccount) error CreateServiceAccount(ctx genericapirequest.Context, ServiceAccount *api.ServiceAccount, createValidation rest.ValidateObjectFunc) error
UpdateServiceAccount(ctx genericapirequest.Context, ServiceAccount *api.ServiceAccount) error UpdateServiceAccount(ctx genericapirequest.Context, ServiceAccount *api.ServiceAccount, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
DeleteServiceAccount(ctx genericapirequest.Context, name string) error DeleteServiceAccount(ctx genericapirequest.Context, name string) error
} }
...@@ -66,13 +66,13 @@ func (s *storage) GetServiceAccount(ctx genericapirequest.Context, name string, ...@@ -66,13 +66,13 @@ func (s *storage) GetServiceAccount(ctx genericapirequest.Context, name string,
return obj.(*api.ServiceAccount), nil return obj.(*api.ServiceAccount), nil
} }
func (s *storage) CreateServiceAccount(ctx genericapirequest.Context, serviceAccount *api.ServiceAccount) error { func (s *storage) CreateServiceAccount(ctx genericapirequest.Context, serviceAccount *api.ServiceAccount, createValidation rest.ValidateObjectFunc) error {
_, err := s.Create(ctx, serviceAccount, false) _, err := s.Create(ctx, serviceAccount, createValidation, false)
return err return err
} }
func (s *storage) UpdateServiceAccount(ctx genericapirequest.Context, serviceAccount *api.ServiceAccount) error { func (s *storage) UpdateServiceAccount(ctx genericapirequest.Context, serviceAccount *api.ServiceAccount, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, serviceAccount.Name, rest.DefaultUpdatedObjectInfo(serviceAccount)) _, _, err := s.Update(ctx, serviceAccount.Name, rest.DefaultUpdatedObjectInfo(serviceAccount), createValidation, updateValidation)
return err return err
} }
......
...@@ -69,7 +69,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met ...@@ -69,7 +69,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return scaleFromRC(rc), nil return scaleFromRC(rc), nil
} }
func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
rc, err := (*r.registry).GetController(ctx, name, &metav1.GetOptions{}) rc, err := (*r.registry).GetController(ctx, name, &metav1.GetOptions{})
if err != nil { if err != nil {
return nil, false, errors.NewNotFound(extensions.Resource("replicationcontrollers/scale"), name) return nil, false, errors.NewNotFound(extensions.Resource("replicationcontrollers/scale"), name)
...@@ -92,7 +92,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r ...@@ -92,7 +92,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r
rc.Spec.Replicas = scale.Spec.Replicas rc.Spec.Replicas = scale.Spec.Replicas
rc.ResourceVersion = scale.ResourceVersion rc.ResourceVersion = scale.ResourceVersion
rc, err = (*r.registry).UpdateController(ctx, rc) rc, err = (*r.registry).UpdateController(ctx, rc, createValidation, updateValidation)
if err != nil { if err != nil {
return nil, false, errors.NewConflict(extensions.Resource("replicationcontrollers/scale"), scale.Name, err) return nil, false, errors.NewConflict(extensions.Resource("replicationcontrollers/scale"), scale.Name, err)
} }
......
...@@ -123,7 +123,7 @@ func TestUpdate(t *testing.T) { ...@@ -123,7 +123,7 @@ func TestUpdate(t *testing.T) {
}, },
} }
if _, _, err := storage.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil { if _, _, err := storage.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj, err := storage.Get(ctx, "foo", &metav1.GetOptions{}) obj, err := storage.Get(ctx, "foo", &metav1.GetOptions{})
......
...@@ -89,6 +89,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -89,6 +89,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -30,8 +30,8 @@ import ( ...@@ -30,8 +30,8 @@ import (
type Registry interface { type Registry interface {
ListDeployments(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*extensions.DeploymentList, error) ListDeployments(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*extensions.DeploymentList, error)
GetDeployment(ctx genericapirequest.Context, deploymentID string, options *metav1.GetOptions) (*extensions.Deployment, error) GetDeployment(ctx genericapirequest.Context, deploymentID string, options *metav1.GetOptions) (*extensions.Deployment, error)
CreateDeployment(ctx genericapirequest.Context, deployment *extensions.Deployment) (*extensions.Deployment, error) CreateDeployment(ctx genericapirequest.Context, deployment *extensions.Deployment, createValidation rest.ValidateObjectFunc) (*extensions.Deployment, error)
UpdateDeployment(ctx genericapirequest.Context, deployment *extensions.Deployment) (*extensions.Deployment, error) UpdateDeployment(ctx genericapirequest.Context, deployment *extensions.Deployment, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*extensions.Deployment, error)
DeleteDeployment(ctx genericapirequest.Context, deploymentID string) error DeleteDeployment(ctx genericapirequest.Context, deploymentID string) error
} }
...@@ -64,16 +64,16 @@ func (s *storage) GetDeployment(ctx genericapirequest.Context, deploymentID stri ...@@ -64,16 +64,16 @@ func (s *storage) GetDeployment(ctx genericapirequest.Context, deploymentID stri
return obj.(*extensions.Deployment), nil return obj.(*extensions.Deployment), nil
} }
func (s *storage) CreateDeployment(ctx genericapirequest.Context, deployment *extensions.Deployment) (*extensions.Deployment, error) { func (s *storage) CreateDeployment(ctx genericapirequest.Context, deployment *extensions.Deployment, createValidation rest.ValidateObjectFunc) (*extensions.Deployment, error) {
obj, err := s.Create(ctx, deployment, false) obj, err := s.Create(ctx, deployment, createValidation, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return obj.(*extensions.Deployment), nil return obj.(*extensions.Deployment), nil
} }
func (s *storage) UpdateDeployment(ctx genericapirequest.Context, deployment *extensions.Deployment) (*extensions.Deployment, error) { func (s *storage) UpdateDeployment(ctx genericapirequest.Context, deployment *extensions.Deployment, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*extensions.Deployment, error) {
obj, _, err := s.Update(ctx, deployment.Name, rest.DefaultUpdatedObjectInfo(deployment)) obj, _, err := s.Update(ctx, deployment.Name, rest.DefaultUpdatedObjectInfo(deployment), createValidation, updateValidation)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -115,8 +115,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -115,8 +115,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
// RollbackREST implements the REST endpoint for initiating the rollback of a deployment // RollbackREST implements the REST endpoint for initiating the rollback of a deployment
...@@ -131,7 +131,7 @@ func (r *RollbackREST) New() runtime.Object { ...@@ -131,7 +131,7 @@ func (r *RollbackREST) New() runtime.Object {
var _ = rest.Creater(&RollbackREST{}) var _ = rest.Creater(&RollbackREST{})
func (r *RollbackREST) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (r *RollbackREST) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
rollback, ok := obj.(*extensions.DeploymentRollback) rollback, ok := obj.(*extensions.DeploymentRollback)
if !ok { if !ok {
return nil, errors.NewBadRequest(fmt.Sprintf("not a DeploymentRollback: %#v", obj)) return nil, errors.NewBadRequest(fmt.Sprintf("not a DeploymentRollback: %#v", obj))
...@@ -227,7 +227,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met ...@@ -227,7 +227,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return scale, nil return scale, nil
} }
func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
deployment, err := r.registry.GetDeployment(ctx, name, &metav1.GetOptions{}) deployment, err := r.registry.GetDeployment(ctx, name, &metav1.GetOptions{})
if err != nil { if err != nil {
return nil, false, errors.NewNotFound(extensions.Resource("deployments/scale"), name) return nil, false, errors.NewNotFound(extensions.Resource("deployments/scale"), name)
...@@ -256,7 +256,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r ...@@ -256,7 +256,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r
deployment.Spec.Replicas = scale.Spec.Replicas deployment.Spec.Replicas = scale.Spec.Replicas
deployment.ResourceVersion = scale.ResourceVersion deployment.ResourceVersion = scale.ResourceVersion
deployment, err = r.registry.UpdateDeployment(ctx, deployment) deployment, err = r.registry.UpdateDeployment(ctx, deployment, createValidation, updateValidation)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
} }
......
...@@ -251,7 +251,7 @@ func TestScaleUpdate(t *testing.T) { ...@@ -251,7 +251,7 @@ func TestScaleUpdate(t *testing.T) {
}, },
} }
if _, _, err := storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil { if _, _, err := storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Fatalf("error updating scale %v: %v", update, err) t.Fatalf("error updating scale %v: %v", update, err)
} }
obj, err := storage.Scale.Get(ctx, name, &metav1.GetOptions{}) obj, err := storage.Scale.Get(ctx, name, &metav1.GetOptions{})
...@@ -266,7 +266,7 @@ func TestScaleUpdate(t *testing.T) { ...@@ -266,7 +266,7 @@ func TestScaleUpdate(t *testing.T) {
update.ResourceVersion = deployment.ResourceVersion update.ResourceVersion = deployment.ResourceVersion
update.Spec.Replicas = 15 update.Spec.Replicas = 15
if _, _, err = storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil && !errors.IsConflict(err) { if _, _, err = storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil && !errors.IsConflict(err) {
t.Fatalf("unexpected error, expecting an update conflict but got %v", err) t.Fatalf("unexpected error, expecting an update conflict but got %v", err)
} }
} }
...@@ -290,7 +290,7 @@ func TestStatusUpdate(t *testing.T) { ...@@ -290,7 +290,7 @@ func TestStatusUpdate(t *testing.T) {
}, },
} }
if _, _, err := storage.Status.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil { if _, _, err := storage.Status.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj, err := storage.Deployment.Get(ctx, name, &metav1.GetOptions{}) obj, err := storage.Deployment.Get(ctx, name, &metav1.GetOptions{})
...@@ -341,10 +341,10 @@ func TestEtcdCreateDeploymentRollback(t *testing.T) { ...@@ -341,10 +341,10 @@ func TestEtcdCreateDeploymentRollback(t *testing.T) {
storage, server := newStorage(t) storage, server := newStorage(t)
rollbackStorage := storage.Rollback rollbackStorage := storage.Rollback
if _, err := storage.Deployment.Create(ctx, validNewDeployment(), false); err != nil { if _, err := storage.Deployment.Create(ctx, validNewDeployment(), rest.ValidateAllObjectFunc, false); err != nil {
t.Fatalf("%s: unexpected error: %v", k, err) t.Fatalf("%s: unexpected error: %v", k, err)
} }
rollbackRespStatus, err := rollbackStorage.Create(ctx, &test.rollback, false) rollbackRespStatus, err := rollbackStorage.Create(ctx, &test.rollback, rest.ValidateAllObjectFunc, false)
if !test.errOK(err) { if !test.errOK(err) {
t.Errorf("%s: unexpected error: %v", k, err) t.Errorf("%s: unexpected error: %v", k, err)
} else if err == nil { } else if err == nil {
...@@ -381,7 +381,7 @@ func TestEtcdCreateDeploymentRollbackNoDeployment(t *testing.T) { ...@@ -381,7 +381,7 @@ func TestEtcdCreateDeploymentRollbackNoDeployment(t *testing.T) {
Name: name, Name: name,
UpdatedAnnotations: map[string]string{}, UpdatedAnnotations: map[string]string{},
RollbackTo: extensions.RollbackConfig{Revision: 1}, RollbackTo: extensions.RollbackConfig{Revision: 1},
}, false) }, rest.ValidateAllObjectFunc, false)
if err == nil { if err == nil {
t.Fatalf("Expected not-found-error but got nothing") t.Fatalf("Expected not-found-error but got nothing")
} }
......
...@@ -81,6 +81,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -81,6 +81,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -34,8 +34,8 @@ type Registry interface { ...@@ -34,8 +34,8 @@ type Registry interface {
ListReplicaSets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*extensions.ReplicaSetList, error) ListReplicaSets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*extensions.ReplicaSetList, error)
WatchReplicaSets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchReplicaSets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
GetReplicaSet(ctx genericapirequest.Context, replicaSetID string, options *metav1.GetOptions) (*extensions.ReplicaSet, error) GetReplicaSet(ctx genericapirequest.Context, replicaSetID string, options *metav1.GetOptions) (*extensions.ReplicaSet, error)
CreateReplicaSet(ctx genericapirequest.Context, replicaSet *extensions.ReplicaSet) (*extensions.ReplicaSet, error) CreateReplicaSet(ctx genericapirequest.Context, replicaSet *extensions.ReplicaSet, createValidation rest.ValidateObjectFunc) (*extensions.ReplicaSet, error)
UpdateReplicaSet(ctx genericapirequest.Context, replicaSet *extensions.ReplicaSet) (*extensions.ReplicaSet, error) UpdateReplicaSet(ctx genericapirequest.Context, replicaSet *extensions.ReplicaSet, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*extensions.ReplicaSet, error)
DeleteReplicaSet(ctx genericapirequest.Context, replicaSetID string) error DeleteReplicaSet(ctx genericapirequest.Context, replicaSetID string) error
} }
...@@ -73,16 +73,16 @@ func (s *storage) GetReplicaSet(ctx genericapirequest.Context, replicaSetID stri ...@@ -73,16 +73,16 @@ func (s *storage) GetReplicaSet(ctx genericapirequest.Context, replicaSetID stri
return obj.(*extensions.ReplicaSet), nil return obj.(*extensions.ReplicaSet), nil
} }
func (s *storage) CreateReplicaSet(ctx genericapirequest.Context, replicaSet *extensions.ReplicaSet) (*extensions.ReplicaSet, error) { func (s *storage) CreateReplicaSet(ctx genericapirequest.Context, replicaSet *extensions.ReplicaSet, createValidation rest.ValidateObjectFunc) (*extensions.ReplicaSet, error) {
obj, err := s.Create(ctx, replicaSet, false) obj, err := s.Create(ctx, replicaSet, createValidation, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return obj.(*extensions.ReplicaSet), nil return obj.(*extensions.ReplicaSet), nil
} }
func (s *storage) UpdateReplicaSet(ctx genericapirequest.Context, replicaSet *extensions.ReplicaSet) (*extensions.ReplicaSet, error) { func (s *storage) UpdateReplicaSet(ctx genericapirequest.Context, replicaSet *extensions.ReplicaSet, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*extensions.ReplicaSet, error) {
obj, _, err := s.Update(ctx, replicaSet.Name, rest.DefaultUpdatedObjectInfo(replicaSet)) obj, _, err := s.Update(ctx, replicaSet.Name, rest.DefaultUpdatedObjectInfo(replicaSet), createValidation, updateValidation)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -119,8 +119,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -119,8 +119,8 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
type ScaleREST struct { type ScaleREST struct {
...@@ -161,7 +161,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met ...@@ -161,7 +161,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return scale, err return scale, err
} }
func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
rs, err := r.registry.GetReplicaSet(ctx, name, &metav1.GetOptions{}) rs, err := r.registry.GetReplicaSet(ctx, name, &metav1.GetOptions{})
if err != nil { if err != nil {
return nil, false, errors.NewNotFound(extensions.Resource("replicasets/scale"), name) return nil, false, errors.NewNotFound(extensions.Resource("replicasets/scale"), name)
...@@ -172,6 +172,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r ...@@ -172,6 +172,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r
return nil, false, err return nil, false, err
} }
// TODO: should this pass admission?
obj, err := objInfo.UpdatedObject(ctx, oldScale) obj, err := objInfo.UpdatedObject(ctx, oldScale)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
...@@ -190,7 +191,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r ...@@ -190,7 +191,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r
rs.Spec.Replicas = scale.Spec.Replicas rs.Spec.Replicas = scale.Spec.Replicas
rs.ResourceVersion = scale.ResourceVersion rs.ResourceVersion = scale.ResourceVersion
rs, err = r.registry.UpdateReplicaSet(ctx, rs) rs, err = r.registry.UpdateReplicaSet(ctx, rs, createValidation, updateValidation)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
} }
......
...@@ -47,7 +47,7 @@ func newStorage(t *testing.T) (*ReplicaSetStorage, *etcdtesting.EtcdTestServer) ...@@ -47,7 +47,7 @@ func newStorage(t *testing.T) (*ReplicaSetStorage, *etcdtesting.EtcdTestServer)
// createReplicaSet is a helper function that returns a ReplicaSet with the updated resource version. // createReplicaSet is a helper function that returns a ReplicaSet with the updated resource version.
func createReplicaSet(storage *REST, rs extensions.ReplicaSet, t *testing.T) (extensions.ReplicaSet, error) { func createReplicaSet(storage *REST, rs extensions.ReplicaSet, t *testing.T) (extensions.ReplicaSet, error) {
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), rs.Namespace) ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), rs.Namespace)
obj, err := storage.Create(ctx, &rs, false) obj, err := storage.Create(ctx, &rs, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Errorf("Failed to create ReplicaSet, %v", err) t.Errorf("Failed to create ReplicaSet, %v", err)
} }
...@@ -169,7 +169,7 @@ func TestGenerationNumber(t *testing.T) { ...@@ -169,7 +169,7 @@ func TestGenerationNumber(t *testing.T) {
// Updates to spec should increment the generation number // Updates to spec should increment the generation number
storedRS.Spec.Replicas += 1 storedRS.Spec.Replicas += 1
storage.ReplicaSet.Update(ctx, storedRS.Name, rest.DefaultUpdatedObjectInfo(storedRS)) storage.ReplicaSet.Update(ctx, storedRS.Name, rest.DefaultUpdatedObjectInfo(storedRS), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -184,7 +184,7 @@ func TestGenerationNumber(t *testing.T) { ...@@ -184,7 +184,7 @@ func TestGenerationNumber(t *testing.T) {
// Updates to status should not increment either spec or status generation numbers // Updates to status should not increment either spec or status generation numbers
storedRS.Status.Replicas += 1 storedRS.Status.Replicas += 1
storage.ReplicaSet.Update(ctx, storedRS.Name, rest.DefaultUpdatedObjectInfo(storedRS)) storage.ReplicaSet.Update(ctx, storedRS.Name, rest.DefaultUpdatedObjectInfo(storedRS), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -311,7 +311,7 @@ func TestScaleUpdate(t *testing.T) { ...@@ -311,7 +311,7 @@ func TestScaleUpdate(t *testing.T) {
}, },
} }
if _, _, err := storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil { if _, _, err := storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Fatalf("error updating scale %v: %v", update, err) t.Fatalf("error updating scale %v: %v", update, err)
} }
...@@ -327,7 +327,7 @@ func TestScaleUpdate(t *testing.T) { ...@@ -327,7 +327,7 @@ func TestScaleUpdate(t *testing.T) {
update.ResourceVersion = rs.ResourceVersion update.ResourceVersion = rs.ResourceVersion
update.Spec.Replicas = 15 update.Spec.Replicas = 15
if _, _, err = storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil && !errors.IsConflict(err) { if _, _, err = storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil && !errors.IsConflict(err) {
t.Fatalf("unexpected error, expecting an update conflict but got %v", err) t.Fatalf("unexpected error, expecting an update conflict but got %v", err)
} }
} }
...@@ -352,7 +352,7 @@ func TestStatusUpdate(t *testing.T) { ...@@ -352,7 +352,7 @@ func TestStatusUpdate(t *testing.T) {
}, },
} }
if _, _, err := storage.Status.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil { if _, _, err := storage.Status.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj, err := storage.ReplicaSet.Get(ctx, "foo", &metav1.GetOptions{}) obj, err := storage.ReplicaSet.Get(ctx, "foo", &metav1.GetOptions{})
......
...@@ -28,8 +28,8 @@ import ( ...@@ -28,8 +28,8 @@ import (
// Registry is an interface for things that know how to store NetworkPolicies. // Registry is an interface for things that know how to store NetworkPolicies.
type Registry interface { type Registry interface {
ListNetworkPolicies(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*networking.NetworkPolicyList, error) ListNetworkPolicies(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*networking.NetworkPolicyList, error)
CreateNetworkPolicy(ctx genericapirequest.Context, np *networking.NetworkPolicy) error CreateNetworkPolicy(ctx genericapirequest.Context, np *networking.NetworkPolicy, createValidation rest.ValidateObjectFunc) error
UpdateNetworkPolicy(ctx genericapirequest.Context, np *networking.NetworkPolicy) error UpdateNetworkPolicy(ctx genericapirequest.Context, np *networking.NetworkPolicy, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
GetNetworkPolicy(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*networking.NetworkPolicy, error) GetNetworkPolicy(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*networking.NetworkPolicy, error)
DeleteNetworkPolicy(ctx genericapirequest.Context, name string) error DeleteNetworkPolicy(ctx genericapirequest.Context, name string) error
WatchNetworkPolicies(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchNetworkPolicies(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
...@@ -55,13 +55,13 @@ func (s *storage) ListNetworkPolicies(ctx genericapirequest.Context, options *me ...@@ -55,13 +55,13 @@ func (s *storage) ListNetworkPolicies(ctx genericapirequest.Context, options *me
return obj.(*networking.NetworkPolicyList), nil return obj.(*networking.NetworkPolicyList), nil
} }
func (s *storage) CreateNetworkPolicy(ctx genericapirequest.Context, np *networking.NetworkPolicy) error { func (s *storage) CreateNetworkPolicy(ctx genericapirequest.Context, np *networking.NetworkPolicy, createValidation rest.ValidateObjectFunc) error {
_, err := s.Create(ctx, np, false) _, err := s.Create(ctx, np, createValidation, false)
return err return err
} }
func (s *storage) UpdateNetworkPolicy(ctx genericapirequest.Context, np *networking.NetworkPolicy) error { func (s *storage) UpdateNetworkPolicy(ctx genericapirequest.Context, np *networking.NetworkPolicy, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, np.Name, rest.DefaultUpdatedObjectInfo(np)) _, _, err := s.Update(ctx, np.Name, rest.DefaultUpdatedObjectInfo(np), createValidation, updateValidation)
return err return err
} }
......
...@@ -78,6 +78,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me ...@@ -78,6 +78,6 @@ func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *me
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -41,7 +41,7 @@ func newStorage(t *testing.T) (*REST, *StatusREST, *etcdtesting.EtcdTestServer) ...@@ -41,7 +41,7 @@ func newStorage(t *testing.T) (*REST, *StatusREST, *etcdtesting.EtcdTestServer)
// createPodDisruptionBudget is a helper function that returns a PodDisruptionBudget with the updated resource version. // createPodDisruptionBudget is a helper function that returns a PodDisruptionBudget with the updated resource version.
func createPodDisruptionBudget(storage *REST, pdb policy.PodDisruptionBudget, t *testing.T) (policy.PodDisruptionBudget, error) { func createPodDisruptionBudget(storage *REST, pdb policy.PodDisruptionBudget, t *testing.T) (policy.PodDisruptionBudget, error) {
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), pdb.Namespace) ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), pdb.Namespace)
obj, err := storage.Create(ctx, &pdb, false) obj, err := storage.Create(ctx, &pdb, rest.ValidateAllObjectFunc, false)
if err != nil { if err != nil {
t.Errorf("Failed to create PodDisruptionBudget, %v", err) t.Errorf("Failed to create PodDisruptionBudget, %v", err)
} }
...@@ -109,7 +109,7 @@ func TestStatusUpdate(t *testing.T) { ...@@ -109,7 +109,7 @@ func TestStatusUpdate(t *testing.T) {
}, },
} }
if _, _, err := statusStorage.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update)); err != nil { if _, _, err := statusStorage.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
obj, err = storage.Get(ctx, "foo", &metav1.GetOptions{}) obj, err = storage.Get(ctx, "foo", &metav1.GetOptions{})
......
...@@ -40,9 +40,9 @@ func NewStorage(s rest.StandardStorage, ruleResolver rbacregistryvalidation.Auth ...@@ -40,9 +40,9 @@ func NewStorage(s rest.StandardStorage, ruleResolver rbacregistryvalidation.Auth
return &Storage{s, ruleResolver} return &Storage{s, ruleResolver}
} }
func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, createValidatingAdmission rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
if rbacregistry.EscalationAllowed(ctx) { if rbacregistry.EscalationAllowed(ctx) {
return s.StandardStorage.Create(ctx, obj, includeUninitialized) return s.StandardStorage.Create(ctx, obj, createValidatingAdmission, includeUninitialized)
} }
clusterRole := obj.(*rbac.ClusterRole) clusterRole := obj.(*rbac.ClusterRole)
...@@ -50,12 +50,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, incl ...@@ -50,12 +50,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, incl
if err := rbacregistryvalidation.ConfirmNoEscalation(ctx, s.ruleResolver, rules); err != nil { if err := rbacregistryvalidation.ConfirmNoEscalation(ctx, s.ruleResolver, rules); err != nil {
return nil, errors.NewForbidden(groupResource, clusterRole.Name, err) return nil, errors.NewForbidden(groupResource, clusterRole.Name, err)
} }
return s.StandardStorage.Create(ctx, obj, includeUninitialized) return s.StandardStorage.Create(ctx, obj, createValidatingAdmission, includeUninitialized)
} }
func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
if rbacregistry.EscalationAllowed(ctx) { if rbacregistry.EscalationAllowed(ctx) {
return s.StandardStorage.Update(ctx, name, obj) return s.StandardStorage.Update(ctx, name, obj, createValidation, updateValidation)
} }
nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx genericapirequest.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx genericapirequest.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
...@@ -73,5 +73,5 @@ func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.Up ...@@ -73,5 +73,5 @@ func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.Up
return obj, nil return obj, nil
}) })
return s.StandardStorage.Update(ctx, name, nonEscalatingInfo) return s.StandardStorage.Update(ctx, name, nonEscalatingInfo, createValidation, updateValidation)
} }
...@@ -28,8 +28,8 @@ import ( ...@@ -28,8 +28,8 @@ import (
// Registry is an interface for things that know how to store ClusterRoles. // Registry is an interface for things that know how to store ClusterRoles.
type Registry interface { type Registry interface {
ListClusterRoles(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*rbac.ClusterRoleList, error) ListClusterRoles(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*rbac.ClusterRoleList, error)
CreateClusterRole(ctx genericapirequest.Context, clusterRole *rbac.ClusterRole) error CreateClusterRole(ctx genericapirequest.Context, clusterRole *rbac.ClusterRole, createValidation rest.ValidateObjectFunc) error
UpdateClusterRole(ctx genericapirequest.Context, clusterRole *rbac.ClusterRole) error UpdateClusterRole(ctx genericapirequest.Context, clusterRole *rbac.ClusterRole, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
GetClusterRole(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*rbac.ClusterRole, error) GetClusterRole(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*rbac.ClusterRole, error)
DeleteClusterRole(ctx genericapirequest.Context, name string) error DeleteClusterRole(ctx genericapirequest.Context, name string) error
WatchClusterRoles(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchClusterRoles(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
...@@ -55,13 +55,13 @@ func (s *storage) ListClusterRoles(ctx genericapirequest.Context, options *metai ...@@ -55,13 +55,13 @@ func (s *storage) ListClusterRoles(ctx genericapirequest.Context, options *metai
return obj.(*rbac.ClusterRoleList), nil return obj.(*rbac.ClusterRoleList), nil
} }
func (s *storage) CreateClusterRole(ctx genericapirequest.Context, clusterRole *rbac.ClusterRole) error { func (s *storage) CreateClusterRole(ctx genericapirequest.Context, clusterRole *rbac.ClusterRole, createValidation rest.ValidateObjectFunc) error {
_, err := s.Create(ctx, clusterRole, false) _, err := s.Create(ctx, clusterRole, createValidation, false)
return err return err
} }
func (s *storage) UpdateClusterRole(ctx genericapirequest.Context, clusterRole *rbac.ClusterRole) error { func (s *storage) UpdateClusterRole(ctx genericapirequest.Context, clusterRole *rbac.ClusterRole, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, clusterRole.Name, rest.DefaultUpdatedObjectInfo(clusterRole)) _, _, err := s.Update(ctx, clusterRole.Name, rest.DefaultUpdatedObjectInfo(clusterRole), createValidation, updateValidation)
return err return err
} }
......
...@@ -44,14 +44,14 @@ func NewStorage(s rest.StandardStorage, authorizer authorizer.Authorizer, ruleRe ...@@ -44,14 +44,14 @@ func NewStorage(s rest.StandardStorage, authorizer authorizer.Authorizer, ruleRe
return &Storage{s, authorizer, ruleResolver} return &Storage{s, authorizer, ruleResolver}
} }
func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
if rbacregistry.EscalationAllowed(ctx) { if rbacregistry.EscalationAllowed(ctx) {
return s.StandardStorage.Create(ctx, obj, includeUninitialized) return s.StandardStorage.Create(ctx, obj, createValidation, includeUninitialized)
} }
clusterRoleBinding := obj.(*rbac.ClusterRoleBinding) clusterRoleBinding := obj.(*rbac.ClusterRoleBinding)
if rbacregistry.BindingAuthorized(ctx, clusterRoleBinding.RoleRef, metav1.NamespaceNone, s.authorizer) { if rbacregistry.BindingAuthorized(ctx, clusterRoleBinding.RoleRef, metav1.NamespaceNone, s.authorizer) {
return s.StandardStorage.Create(ctx, obj, includeUninitialized) return s.StandardStorage.Create(ctx, obj, createValidation, includeUninitialized)
} }
rules, err := s.ruleResolver.GetRoleReferenceRules(clusterRoleBinding.RoleRef, metav1.NamespaceNone) rules, err := s.ruleResolver.GetRoleReferenceRules(clusterRoleBinding.RoleRef, metav1.NamespaceNone)
...@@ -61,12 +61,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, incl ...@@ -61,12 +61,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, incl
if err := rbacregistryvalidation.ConfirmNoEscalation(ctx, s.ruleResolver, rules); err != nil { if err := rbacregistryvalidation.ConfirmNoEscalation(ctx, s.ruleResolver, rules); err != nil {
return nil, errors.NewForbidden(groupResource, clusterRoleBinding.Name, err) return nil, errors.NewForbidden(groupResource, clusterRoleBinding.Name, err)
} }
return s.StandardStorage.Create(ctx, obj, includeUninitialized) return s.StandardStorage.Create(ctx, obj, createValidation, includeUninitialized)
} }
func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
if rbacregistry.EscalationAllowed(ctx) { if rbacregistry.EscalationAllowed(ctx) {
return s.StandardStorage.Update(ctx, name, obj) return s.StandardStorage.Update(ctx, name, obj, createValidation, updateValidation)
} }
nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx genericapirequest.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx genericapirequest.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
...@@ -93,5 +93,5 @@ func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.Up ...@@ -93,5 +93,5 @@ func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.Up
return obj, nil return obj, nil
}) })
return s.StandardStorage.Update(ctx, name, nonEscalatingInfo) return s.StandardStorage.Update(ctx, name, nonEscalatingInfo, createValidation, updateValidation)
} }
...@@ -28,8 +28,8 @@ import ( ...@@ -28,8 +28,8 @@ import (
// Registry is an interface for things that know how to store ClusterRoleBindings. // Registry is an interface for things that know how to store ClusterRoleBindings.
type Registry interface { type Registry interface {
ListClusterRoleBindings(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*rbac.ClusterRoleBindingList, error) ListClusterRoleBindings(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*rbac.ClusterRoleBindingList, error)
CreateClusterRoleBinding(ctx genericapirequest.Context, clusterRoleBinding *rbac.ClusterRoleBinding) error CreateClusterRoleBinding(ctx genericapirequest.Context, clusterRoleBinding *rbac.ClusterRoleBinding, createValidation rest.ValidateObjectFunc) error
UpdateClusterRoleBinding(ctx genericapirequest.Context, clusterRoleBinding *rbac.ClusterRoleBinding) error UpdateClusterRoleBinding(ctx genericapirequest.Context, clusterRoleBinding *rbac.ClusterRoleBinding, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
GetClusterRoleBinding(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*rbac.ClusterRoleBinding, error) GetClusterRoleBinding(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*rbac.ClusterRoleBinding, error)
DeleteClusterRoleBinding(ctx genericapirequest.Context, name string) error DeleteClusterRoleBinding(ctx genericapirequest.Context, name string) error
WatchClusterRoleBindings(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchClusterRoleBindings(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
...@@ -55,13 +55,13 @@ func (s *storage) ListClusterRoleBindings(ctx genericapirequest.Context, options ...@@ -55,13 +55,13 @@ func (s *storage) ListClusterRoleBindings(ctx genericapirequest.Context, options
return obj.(*rbac.ClusterRoleBindingList), nil return obj.(*rbac.ClusterRoleBindingList), nil
} }
func (s *storage) CreateClusterRoleBinding(ctx genericapirequest.Context, clusterRoleBinding *rbac.ClusterRoleBinding) error { func (s *storage) CreateClusterRoleBinding(ctx genericapirequest.Context, clusterRoleBinding *rbac.ClusterRoleBinding, createValidation rest.ValidateObjectFunc) error {
_, err := s.Create(ctx, clusterRoleBinding, false) _, err := s.Create(ctx, clusterRoleBinding, createValidation, false)
return err return err
} }
func (s *storage) UpdateClusterRoleBinding(ctx genericapirequest.Context, clusterRoleBinding *rbac.ClusterRoleBinding) error { func (s *storage) UpdateClusterRoleBinding(ctx genericapirequest.Context, clusterRoleBinding *rbac.ClusterRoleBinding, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, clusterRoleBinding.Name, rest.DefaultUpdatedObjectInfo(clusterRoleBinding)) _, _, err := s.Update(ctx, clusterRoleBinding.Name, rest.DefaultUpdatedObjectInfo(clusterRoleBinding), createValidation, updateValidation)
return err return err
} }
......
...@@ -40,9 +40,9 @@ func NewStorage(s rest.StandardStorage, ruleResolver rbacregistryvalidation.Auth ...@@ -40,9 +40,9 @@ func NewStorage(s rest.StandardStorage, ruleResolver rbacregistryvalidation.Auth
return &Storage{s, ruleResolver} return &Storage{s, ruleResolver}
} }
func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
if rbacregistry.EscalationAllowed(ctx) { if rbacregistry.EscalationAllowed(ctx) {
return s.StandardStorage.Create(ctx, obj, includeUninitialized) return s.StandardStorage.Create(ctx, obj, createValidation, includeUninitialized)
} }
role := obj.(*rbac.Role) role := obj.(*rbac.Role)
...@@ -50,12 +50,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, incl ...@@ -50,12 +50,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, incl
if err := rbacregistryvalidation.ConfirmNoEscalation(ctx, s.ruleResolver, rules); err != nil { if err := rbacregistryvalidation.ConfirmNoEscalation(ctx, s.ruleResolver, rules); err != nil {
return nil, errors.NewForbidden(groupResource, role.Name, err) return nil, errors.NewForbidden(groupResource, role.Name, err)
} }
return s.StandardStorage.Create(ctx, obj, includeUninitialized) return s.StandardStorage.Create(ctx, obj, createValidation, includeUninitialized)
} }
func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
if rbacregistry.EscalationAllowed(ctx) { if rbacregistry.EscalationAllowed(ctx) {
return s.StandardStorage.Update(ctx, name, obj) return s.StandardStorage.Update(ctx, name, obj, createValidation, updateValidation)
} }
nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx genericapirequest.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx genericapirequest.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
...@@ -73,5 +73,5 @@ func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.Up ...@@ -73,5 +73,5 @@ func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.Up
return obj, nil return obj, nil
}) })
return s.StandardStorage.Update(ctx, name, nonEscalatingInfo) return s.StandardStorage.Update(ctx, name, nonEscalatingInfo, createValidation, updateValidation)
} }
...@@ -28,8 +28,8 @@ import ( ...@@ -28,8 +28,8 @@ import (
// Registry is an interface for things that know how to store Roles. // Registry is an interface for things that know how to store Roles.
type Registry interface { type Registry interface {
ListRoles(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*rbac.RoleList, error) ListRoles(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*rbac.RoleList, error)
CreateRole(ctx genericapirequest.Context, role *rbac.Role) error CreateRole(ctx genericapirequest.Context, role *rbac.Role, createValidation rest.ValidateObjectFunc) error
UpdateRole(ctx genericapirequest.Context, role *rbac.Role) error UpdateRole(ctx genericapirequest.Context, role *rbac.Role, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
GetRole(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*rbac.Role, error) GetRole(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*rbac.Role, error)
DeleteRole(ctx genericapirequest.Context, name string) error DeleteRole(ctx genericapirequest.Context, name string) error
WatchRoles(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchRoles(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
...@@ -55,13 +55,14 @@ func (s *storage) ListRoles(ctx genericapirequest.Context, options *metainternal ...@@ -55,13 +55,14 @@ func (s *storage) ListRoles(ctx genericapirequest.Context, options *metainternal
return obj.(*rbac.RoleList), nil return obj.(*rbac.RoleList), nil
} }
func (s *storage) CreateRole(ctx genericapirequest.Context, role *rbac.Role) error { func (s *storage) CreateRole(ctx genericapirequest.Context, role *rbac.Role, createValidation rest.ValidateObjectFunc) error {
_, err := s.Create(ctx, role, false) _, err := s.Create(ctx, role, createValidation, false)
return err return err
} }
func (s *storage) UpdateRole(ctx genericapirequest.Context, role *rbac.Role) error { func (s *storage) UpdateRole(ctx genericapirequest.Context, role *rbac.Role, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, role.Name, rest.DefaultUpdatedObjectInfo(role)) // TODO: any admission?
_, _, err := s.Update(ctx, role.Name, rest.DefaultUpdatedObjectInfo(role), createValidation, updateValidation)
return err return err
} }
......
...@@ -43,9 +43,9 @@ func NewStorage(s rest.StandardStorage, authorizer authorizer.Authorizer, ruleRe ...@@ -43,9 +43,9 @@ func NewStorage(s rest.StandardStorage, authorizer authorizer.Authorizer, ruleRe
return &Storage{s, authorizer, ruleResolver} return &Storage{s, authorizer, ruleResolver}
} }
func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
if rbacregistry.EscalationAllowed(ctx) { if rbacregistry.EscalationAllowed(ctx) {
return s.StandardStorage.Create(ctx, obj, includeUninitialized) return s.StandardStorage.Create(ctx, obj, createValidation, includeUninitialized)
} }
// Get the namespace from the context (populated from the URL). // Get the namespace from the context (populated from the URL).
...@@ -57,7 +57,7 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, incl ...@@ -57,7 +57,7 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, incl
roleBinding := obj.(*rbac.RoleBinding) roleBinding := obj.(*rbac.RoleBinding)
if rbacregistry.BindingAuthorized(ctx, roleBinding.RoleRef, namespace, s.authorizer) { if rbacregistry.BindingAuthorized(ctx, roleBinding.RoleRef, namespace, s.authorizer) {
return s.StandardStorage.Create(ctx, obj, includeUninitialized) return s.StandardStorage.Create(ctx, obj, createValidation, includeUninitialized)
} }
rules, err := s.ruleResolver.GetRoleReferenceRules(roleBinding.RoleRef, namespace) rules, err := s.ruleResolver.GetRoleReferenceRules(roleBinding.RoleRef, namespace)
...@@ -67,12 +67,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, incl ...@@ -67,12 +67,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, incl
if err := rbacregistryvalidation.ConfirmNoEscalation(ctx, s.ruleResolver, rules); err != nil { if err := rbacregistryvalidation.ConfirmNoEscalation(ctx, s.ruleResolver, rules); err != nil {
return nil, errors.NewForbidden(groupResource, roleBinding.Name, err) return nil, errors.NewForbidden(groupResource, roleBinding.Name, err)
} }
return s.StandardStorage.Create(ctx, obj, includeUninitialized) return s.StandardStorage.Create(ctx, obj, createValidation, includeUninitialized)
} }
func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
if rbacregistry.EscalationAllowed(ctx) { if rbacregistry.EscalationAllowed(ctx) {
return s.StandardStorage.Update(ctx, name, obj) return s.StandardStorage.Update(ctx, name, obj, createValidation, updateValidation)
} }
nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx genericapirequest.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx genericapirequest.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
...@@ -106,5 +106,5 @@ func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.Up ...@@ -106,5 +106,5 @@ func (s *Storage) Update(ctx genericapirequest.Context, name string, obj rest.Up
return obj, nil return obj, nil
}) })
return s.StandardStorage.Update(ctx, name, nonEscalatingInfo) return s.StandardStorage.Update(ctx, name, nonEscalatingInfo, createValidation, updateValidation)
} }
...@@ -28,8 +28,8 @@ import ( ...@@ -28,8 +28,8 @@ import (
// Registry is an interface for things that know how to store RoleBindings. // Registry is an interface for things that know how to store RoleBindings.
type Registry interface { type Registry interface {
ListRoleBindings(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*rbac.RoleBindingList, error) ListRoleBindings(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*rbac.RoleBindingList, error)
CreateRoleBinding(ctx genericapirequest.Context, roleBinding *rbac.RoleBinding) error CreateRoleBinding(ctx genericapirequest.Context, roleBinding *rbac.RoleBinding, createValidation rest.ValidateObjectFunc) error
UpdateRoleBinding(ctx genericapirequest.Context, roleBinding *rbac.RoleBinding) error UpdateRoleBinding(ctx genericapirequest.Context, roleBinding *rbac.RoleBinding, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
GetRoleBinding(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*rbac.RoleBinding, error) GetRoleBinding(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*rbac.RoleBinding, error)
DeleteRoleBinding(ctx genericapirequest.Context, name string) error DeleteRoleBinding(ctx genericapirequest.Context, name string) error
WatchRoleBindings(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchRoleBindings(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
...@@ -55,14 +55,14 @@ func (s *storage) ListRoleBindings(ctx genericapirequest.Context, options *metai ...@@ -55,14 +55,14 @@ func (s *storage) ListRoleBindings(ctx genericapirequest.Context, options *metai
return obj.(*rbac.RoleBindingList), nil return obj.(*rbac.RoleBindingList), nil
} }
func (s *storage) CreateRoleBinding(ctx genericapirequest.Context, roleBinding *rbac.RoleBinding) error { func (s *storage) CreateRoleBinding(ctx genericapirequest.Context, roleBinding *rbac.RoleBinding, createValidation rest.ValidateObjectFunc) error {
// TODO(ericchiang): add additional validation // TODO(ericchiang): add additional validation
_, err := s.Create(ctx, roleBinding, false) _, err := s.Create(ctx, roleBinding, createValidation, false)
return err return err
} }
func (s *storage) UpdateRoleBinding(ctx genericapirequest.Context, roleBinding *rbac.RoleBinding) error { func (s *storage) UpdateRoleBinding(ctx genericapirequest.Context, roleBinding *rbac.RoleBinding, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, roleBinding.Name, rest.DefaultUpdatedObjectInfo(roleBinding)) _, _, err := s.Update(ctx, roleBinding.Name, rest.DefaultUpdatedObjectInfo(roleBinding), createValidation, updateValidation)
return err return err
} }
......
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
) )
...@@ -66,7 +67,7 @@ func (e *EndpointRegistry) WatchEndpoints(ctx genericapirequest.Context, options ...@@ -66,7 +67,7 @@ func (e *EndpointRegistry) WatchEndpoints(ctx genericapirequest.Context, options
return nil, fmt.Errorf("unimplemented!") return nil, fmt.Errorf("unimplemented!")
} }
func (e *EndpointRegistry) UpdateEndpoints(ctx genericapirequest.Context, endpoints *api.Endpoints) error { func (e *EndpointRegistry) UpdateEndpoints(ctx genericapirequest.Context, endpoints *api.Endpoints, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
// TODO: support namespaces in this mock // TODO: support namespaces in this mock
e.lock.Lock() e.lock.Lock()
defer e.lock.Unlock() defer e.lock.Unlock()
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
) )
...@@ -72,7 +73,7 @@ func (r *ServiceRegistry) ListServices(ctx genericapirequest.Context, options *m ...@@ -72,7 +73,7 @@ func (r *ServiceRegistry) ListServices(ctx genericapirequest.Context, options *m
return res, r.Err return res, r.Err
} }
func (r *ServiceRegistry) CreateService(ctx genericapirequest.Context, svc *api.Service) (*api.Service, error) { func (r *ServiceRegistry) CreateService(ctx genericapirequest.Context, svc *api.Service, createValidation rest.ValidateObjectFunc) (*api.Service, error) {
r.mu.Lock() r.mu.Lock()
defer r.mu.Unlock() defer r.mu.Unlock()
...@@ -99,7 +100,7 @@ func (r *ServiceRegistry) DeleteService(ctx genericapirequest.Context, id string ...@@ -99,7 +100,7 @@ func (r *ServiceRegistry) DeleteService(ctx genericapirequest.Context, id string
return r.Err return r.Err
} }
func (r *ServiceRegistry) UpdateService(ctx genericapirequest.Context, svc *api.Service) (*api.Service, error) { func (r *ServiceRegistry) UpdateService(ctx genericapirequest.Context, svc *api.Service, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*api.Service, error) {
r.mu.Lock() r.mu.Lock()
defer r.mu.Unlock() defer r.mu.Unlock()
......
...@@ -28,8 +28,8 @@ import ( ...@@ -28,8 +28,8 @@ import (
// Registry is an interface for things that know how to store PriorityClass. // Registry is an interface for things that know how to store PriorityClass.
type Registry interface { type Registry interface {
ListPriorityClasses(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*scheduling.PriorityClassList, error) ListPriorityClasses(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*scheduling.PriorityClassList, error)
CreatePriorityClass(ctx genericapirequest.Context, pc *scheduling.PriorityClass) error CreatePriorityClass(ctx genericapirequest.Context, pc *scheduling.PriorityClass, createValidation rest.ValidateObjectFunc) error
UpdatePriorityClass(ctx genericapirequest.Context, pc *scheduling.PriorityClass) error UpdatePriorityClass(ctx genericapirequest.Context, pc *scheduling.PriorityClass, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
GetPriorityClass(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*scheduling.PriorityClass, error) GetPriorityClass(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*scheduling.PriorityClass, error)
DeletePriorityClass(ctx genericapirequest.Context, name string) error DeletePriorityClass(ctx genericapirequest.Context, name string) error
WatchPriorityClasses(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchPriorityClasses(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
...@@ -55,13 +55,13 @@ func (s *storage) ListPriorityClasses(ctx genericapirequest.Context, options *me ...@@ -55,13 +55,13 @@ func (s *storage) ListPriorityClasses(ctx genericapirequest.Context, options *me
return obj.(*scheduling.PriorityClassList), nil return obj.(*scheduling.PriorityClassList), nil
} }
func (s *storage) CreatePriorityClass(ctx genericapirequest.Context, pc *scheduling.PriorityClass) error { func (s *storage) CreatePriorityClass(ctx genericapirequest.Context, pc *scheduling.PriorityClass, createValidation rest.ValidateObjectFunc) error {
_, err := s.Create(ctx, pc, false) _, err := s.Create(ctx, pc, createValidation, false)
return err return err
} }
func (s *storage) UpdatePriorityClass(ctx genericapirequest.Context, pc *scheduling.PriorityClass) error { func (s *storage) UpdatePriorityClass(ctx genericapirequest.Context, pc *scheduling.PriorityClass, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, pc.Name, rest.DefaultUpdatedObjectInfo(pc)) _, _, err := s.Update(ctx, pc.Name, rest.DefaultUpdatedObjectInfo(pc), createValidation, updateValidation)
return err return err
} }
......
...@@ -28,8 +28,8 @@ import ( ...@@ -28,8 +28,8 @@ import (
// Registry is an interface for things that know how to store PodPresets. // Registry is an interface for things that know how to store PodPresets.
type Registry interface { type Registry interface {
ListPodPresets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*settings.PodPresetList, error) ListPodPresets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*settings.PodPresetList, error)
CreatePodPreset(ctx genericapirequest.Context, pp *settings.PodPreset) error CreatePodPreset(ctx genericapirequest.Context, pp *settings.PodPreset, createValidation rest.ValidateObjectFunc) error
UpdatePodPreset(ctx genericapirequest.Context, pp *settings.PodPreset) error UpdatePodPreset(ctx genericapirequest.Context, pp *settings.PodPreset, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error
GetPodPreset(ctx genericapirequest.Context, ppID string, options *metav1.GetOptions) (*settings.PodPreset, error) GetPodPreset(ctx genericapirequest.Context, ppID string, options *metav1.GetOptions) (*settings.PodPreset, error)
DeletePodPreset(ctx genericapirequest.Context, ppID string) error DeletePodPreset(ctx genericapirequest.Context, ppID string) error
WatchPodPresets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) WatchPodPresets(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
...@@ -55,13 +55,13 @@ func (s *storage) ListPodPresets(ctx genericapirequest.Context, options *metaint ...@@ -55,13 +55,13 @@ func (s *storage) ListPodPresets(ctx genericapirequest.Context, options *metaint
return obj.(*settings.PodPresetList), nil return obj.(*settings.PodPresetList), nil
} }
func (s *storage) CreatePodPreset(ctx genericapirequest.Context, pp *settings.PodPreset) error { func (s *storage) CreatePodPreset(ctx genericapirequest.Context, pp *settings.PodPreset, createValidation rest.ValidateObjectFunc) error {
_, err := s.Create(ctx, pp, false) _, err := s.Create(ctx, pp, createValidation, false)
return err return err
} }
func (s *storage) UpdatePodPreset(ctx genericapirequest.Context, pp *settings.PodPreset) error { func (s *storage) UpdatePodPreset(ctx genericapirequest.Context, pp *settings.PodPreset, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) error {
_, _, err := s.Update(ctx, pp.Name, rest.DefaultUpdatedObjectInfo(pp)) _, _, err := s.Update(ctx, pp.Name, rest.DefaultUpdatedObjectInfo(pp), createValidation, updateValidation)
return err return err
} }
......
...@@ -34,7 +34,7 @@ import ( ...@@ -34,7 +34,7 @@ import (
) )
// newHandlerForTest returns the admission controller configured for testing. // newHandlerForTest returns the admission controller configured for testing.
func newHandlerForTest(c clientset.Interface) (admission.Interface, informers.SharedInformerFactory, error) { func newHandlerForTest(c clientset.Interface) (admission.MutationInterface, informers.SharedInformerFactory, error) {
f := informers.NewSharedInformerFactory(c, 5*time.Minute) f := informers.NewSharedInformerFactory(c, 5*time.Minute)
handler := NewExists() handler := NewExists()
pluginInitializer := kubeadmission.NewPluginInitializer(c, f, nil, nil, nil, nil, nil) pluginInitializer := kubeadmission.NewPluginInitializer(c, f, nil, nil, nil, nil, nil)
......
...@@ -272,7 +272,7 @@ func TestPVCResizeAdmission(t *testing.T) { ...@@ -272,7 +272,7 @@ func TestPVCResizeAdmission(t *testing.T) {
ctrl := newPlugin() ctrl := newPlugin()
informerFactory := informers.NewSharedInformerFactory(nil, controller.NoResyncPeriodFunc()) informerFactory := informers.NewSharedInformerFactory(nil, controller.NoResyncPeriodFunc())
ctrl.SetInternalKubeInformerFactory(informerFactory) ctrl.SetInternalKubeInformerFactory(informerFactory)
err := ctrl.Validate() err := ctrl.ValidateInitialization()
if err != nil { if err != nil {
t.Fatalf("neither pv lister nor storageclass lister can be nil") t.Fatalf("neither pv lister nor storageclass lister can be nil")
} }
......
...@@ -393,7 +393,7 @@ func TestMergeVolumes(t *testing.T) { ...@@ -393,7 +393,7 @@ func TestMergeVolumes(t *testing.T) {
// NewTestAdmission provides an admission plugin with test implementations of internal structs. It uses // NewTestAdmission provides an admission plugin with test implementations of internal structs. It uses
// an authorizer that always returns true. // an authorizer that always returns true.
func NewTestAdmission(lister settingslisters.PodPresetLister, objects ...runtime.Object) kadmission.Interface { func NewTestAdmission(lister settingslisters.PodPresetLister, objects ...runtime.Object) kadmission.MutationInterface {
// Build a test client that the admission plugin can use to look up the service account missing from its cache // Build a test client that the admission plugin can use to look up the service account missing from its cache
client := fake.NewSimpleClientset(objects...) client := fake.NewSimpleClientset(objects...)
......
...@@ -49,7 +49,7 @@ const defaultContainerName = "test-c" ...@@ -49,7 +49,7 @@ const defaultContainerName = "test-c"
// NewTestAdmission provides an admission plugin with test implementations of internal structs. It uses // NewTestAdmission provides an admission plugin with test implementations of internal structs. It uses
// an authorizer that always returns true. // an authorizer that always returns true.
func NewTestAdmission(lister extensionslisters.PodSecurityPolicyLister) kadmission.Interface { func NewTestAdmission(lister extensionslisters.PodSecurityPolicyLister) kadmission.MutationInterface {
return &podSecurityPolicyPlugin{ return &podSecurityPolicyPlugin{
Handler: kadmission.NewHandler(kadmission.Create, kadmission.Update), Handler: kadmission.NewHandler(kadmission.Create, kadmission.Update),
strategyFactory: kpsp.NewSimpleStrategyFactory(), strategyFactory: kpsp.NewSimpleStrategyFactory(),
......
...@@ -167,6 +167,6 @@ func (r *StatusREST) New() runtime.Object { ...@@ -167,6 +167,6 @@ func (r *StatusREST) New() runtime.Object {
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -26,8 +26,8 @@ import ( ...@@ -26,8 +26,8 @@ import (
type FakeHandler struct { type FakeHandler struct {
*Handler *Handler
name string name string
admit bool admit, admitCalled bool
admitCalled bool validate, validateCalled bool
} }
func (h *FakeHandler) Admit(a Attributes) (err error) { func (h *FakeHandler) Admit(a Attributes) (err error) {
...@@ -38,6 +38,14 @@ func (h *FakeHandler) Admit(a Attributes) (err error) { ...@@ -38,6 +38,14 @@ func (h *FakeHandler) Admit(a Attributes) (err error) {
return fmt.Errorf("Don't admit") return fmt.Errorf("Don't admit")
} }
func (h *FakeHandler) Validate(a Attributes) (err error) {
h.admitCalled = true
if h.admit {
return nil
}
return fmt.Errorf("Don't admit")
}
func makeHandler(name string, admit bool, ops ...Operation) Interface { func makeHandler(name string, admit bool, ops ...Operation) Interface {
return &FakeHandler{ return &FakeHandler{
name: name, name: name,
......
...@@ -57,9 +57,9 @@ func Register(plugins *admission.Plugins) { ...@@ -57,9 +57,9 @@ func Register(plugins *admission.Plugins) {
}) })
} }
// lifecycle is an implementation of admission.Interface. // Lifecycle is an implementation of admission.Interface.
// It enforces life-cycle constraints around a Namespace depending on its Phase // It enforces life-cycle constraints around a Namespace depending on its Phase
type lifecycle struct { type Lifecycle struct {
*admission.Handler *admission.Handler
client kubernetes.Interface client kubernetes.Interface
immortalNamespaces sets.String immortalNamespaces sets.String
...@@ -73,8 +73,8 @@ type forceLiveLookupEntry struct { ...@@ -73,8 +73,8 @@ type forceLiveLookupEntry struct {
expiry time.Time expiry time.Time
} }
var _ = initializer.WantsExternalKubeInformerFactory(&lifecycle{}) var _ = initializer.WantsExternalKubeInformerFactory(&Lifecycle{})
var _ = initializer.WantsExternalKubeClientSet(&lifecycle{}) var _ = initializer.WantsExternalKubeClientSet(&Lifecycle{})
func makeNamespaceKey(namespace string) *v1.Namespace { func makeNamespaceKey(namespace string) *v1.Namespace {
return &v1.Namespace{ return &v1.Namespace{
...@@ -85,7 +85,7 @@ func makeNamespaceKey(namespace string) *v1.Namespace { ...@@ -85,7 +85,7 @@ func makeNamespaceKey(namespace string) *v1.Namespace {
} }
} }
func (l *lifecycle) Admit(a admission.Attributes) error { func (l *Lifecycle) Admit(a admission.Attributes) error {
// prevent deletion of immortal namespaces // prevent deletion of immortal namespaces
if a.GetOperation() == admission.Delete && a.GetKind().GroupKind() == v1.SchemeGroupVersion.WithKind("Namespace").GroupKind() && l.immortalNamespaces.Has(a.GetName()) { if a.GetOperation() == admission.Delete && a.GetKind().GroupKind() == v1.SchemeGroupVersion.WithKind("Namespace").GroupKind() && l.immortalNamespaces.Has(a.GetName()) {
return errors.NewForbidden(a.GetResource().GroupResource(), a.GetName(), fmt.Errorf("this namespace may not be deleted")) return errors.NewForbidden(a.GetResource().GroupResource(), a.GetName(), fmt.Errorf("this namespace may not be deleted"))
...@@ -188,14 +188,14 @@ func (l *lifecycle) Admit(a admission.Attributes) error { ...@@ -188,14 +188,14 @@ func (l *lifecycle) Admit(a admission.Attributes) error {
return nil return nil
} }
// NewLifecycle creates a new namespace lifecycle admission control handler // NewLifecycle creates a new namespace Lifecycle admission control handler
func NewLifecycle(immortalNamespaces sets.String) (admission.Interface, error) { func NewLifecycle(immortalNamespaces sets.String) (*Lifecycle, error) {
return newLifecycleWithClock(immortalNamespaces, clock.RealClock{}) return newLifecycleWithClock(immortalNamespaces, clock.RealClock{})
} }
func newLifecycleWithClock(immortalNamespaces sets.String, clock utilcache.Clock) (admission.Interface, error) { func newLifecycleWithClock(immortalNamespaces sets.String, clock utilcache.Clock) (*Lifecycle, error) {
forceLiveLookupCache := utilcache.NewLRUExpireCacheWithClock(100, clock) forceLiveLookupCache := utilcache.NewLRUExpireCacheWithClock(100, clock)
return &lifecycle{ return &Lifecycle{
Handler: admission.NewHandler(admission.Create, admission.Update, admission.Delete), Handler: admission.NewHandler(admission.Create, admission.Update, admission.Delete),
immortalNamespaces: immortalNamespaces, immortalNamespaces: immortalNamespaces,
forceLiveLookupCache: forceLiveLookupCache, forceLiveLookupCache: forceLiveLookupCache,
...@@ -203,19 +203,19 @@ func newLifecycleWithClock(immortalNamespaces sets.String, clock utilcache.Clock ...@@ -203,19 +203,19 @@ func newLifecycleWithClock(immortalNamespaces sets.String, clock utilcache.Clock
} }
// SetExternalKubeInformerFactory implements the WantsExternalKubeInformerFactory interface. // SetExternalKubeInformerFactory implements the WantsExternalKubeInformerFactory interface.
func (l *lifecycle) SetExternalKubeInformerFactory(f informers.SharedInformerFactory) { func (l *Lifecycle) SetExternalKubeInformerFactory(f informers.SharedInformerFactory) {
namespaceInformer := f.Core().V1().Namespaces() namespaceInformer := f.Core().V1().Namespaces()
l.namespaceLister = namespaceInformer.Lister() l.namespaceLister = namespaceInformer.Lister()
l.SetReadyFunc(namespaceInformer.Informer().HasSynced) l.SetReadyFunc(namespaceInformer.Informer().HasSynced)
} }
// SetExternalKubeClientSet implements the WantsExternalKubeClientSet interface. // SetExternalKubeClientSet implements the WantsExternalKubeClientSet interface.
func (l *lifecycle) SetExternalKubeClientSet(client kubernetes.Interface) { func (l *Lifecycle) SetExternalKubeClientSet(client kubernetes.Interface) {
l.client = client l.client = client
} }
// Validate implement the Validator interface. // Validate implement the Validator interface.
func (l *lifecycle) Validate() error { func (l *Lifecycle) Validate() error {
if l.namespaceLister == nil { if l.namespaceLister == nil {
return fmt.Errorf("missing namespaceLister") return fmt.Errorf("missing namespaceLister")
} }
......
...@@ -37,12 +37,12 @@ import ( ...@@ -37,12 +37,12 @@ import (
) )
// newHandlerForTest returns a configured handler for testing. // newHandlerForTest returns a configured handler for testing.
func newHandlerForTest(c clientset.Interface) (admission.Interface, informers.SharedInformerFactory, error) { func newHandlerForTest(c clientset.Interface) (*Lifecycle, informers.SharedInformerFactory, error) {
return newHandlerForTestWithClock(c, clock.RealClock{}) return newHandlerForTestWithClock(c, clock.RealClock{})
} }
// newHandlerForTestWithClock returns a configured handler for testing. // newHandlerForTestWithClock returns a configured handler for testing.
func newHandlerForTestWithClock(c clientset.Interface, cacheClock clock.Clock) (admission.Interface, informers.SharedInformerFactory, error) { func newHandlerForTestWithClock(c clientset.Interface, cacheClock clock.Clock) (*Lifecycle, informers.SharedInformerFactory, error) {
f := informers.NewSharedInformerFactory(c, 5*time.Minute) f := informers.NewSharedInformerFactory(c, 5*time.Minute)
handler, err := newLifecycleWithClock(sets.NewString(metav1.NamespaceDefault, metav1.NamespaceSystem), cacheClock) handler, err := newLifecycleWithClock(sets.NewString(metav1.NamespaceDefault, metav1.NamespaceSystem), cacheClock)
if err != nil { if err != nil {
......
...@@ -519,7 +519,7 @@ func (storage *SimpleRESTStorage) NewList() runtime.Object { ...@@ -519,7 +519,7 @@ func (storage *SimpleRESTStorage) NewList() runtime.Object {
return &genericapitesting.SimpleList{} return &genericapitesting.SimpleList{}
} }
func (storage *SimpleRESTStorage) Create(ctx request.Context, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (storage *SimpleRESTStorage) Create(ctx request.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
storage.checkContext(ctx) storage.checkContext(ctx)
storage.created = obj.(*genericapitesting.Simple) storage.created = obj.(*genericapitesting.Simple)
if err := storage.errors["create"]; err != nil { if err := storage.errors["create"]; err != nil {
...@@ -532,7 +532,7 @@ func (storage *SimpleRESTStorage) Create(ctx request.Context, obj runtime.Object ...@@ -532,7 +532,7 @@ func (storage *SimpleRESTStorage) Create(ctx request.Context, obj runtime.Object
return obj, err return obj, err
} }
func (storage *SimpleRESTStorage) Update(ctx request.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (storage *SimpleRESTStorage) Update(ctx request.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
storage.checkContext(ctx) storage.checkContext(ctx)
obj, err := objInfo.UpdatedObject(ctx, &storage.item) obj, err := objInfo.UpdatedObject(ctx, &storage.item)
if err != nil { if err != nil {
...@@ -714,7 +714,7 @@ type NamedCreaterRESTStorage struct { ...@@ -714,7 +714,7 @@ type NamedCreaterRESTStorage struct {
createdName string createdName string
} }
func (storage *NamedCreaterRESTStorage) Create(ctx request.Context, name string, obj runtime.Object, includeUninitialized bool) (runtime.Object, error) { func (storage *NamedCreaterRESTStorage) Create(ctx request.Context, name string, obj runtime.Object, createValidation rest.ValidateObjectFunc, includeUninitialized bool) (runtime.Object, error) {
storage.checkContext(ctx) storage.checkContext(ctx)
storage.created = obj.(*genericapitesting.Simple) storage.created = obj.(*genericapitesting.Simple)
storage.createdName = name storage.createdName = name
......
...@@ -94,25 +94,22 @@ func DeleteResource(r rest.GracefulDeleter, allowsOptions bool, scope RequestSco ...@@ -94,25 +94,22 @@ func DeleteResource(r rest.GracefulDeleter, allowsOptions bool, scope RequestSco
} }
trace.Step("About to check admission control") trace.Step("About to check admission control")
if mutatingAdmission, ok := admit.(admission.MutationInterface); ok && mutatingAdmission.Handles(admission.Delete) { if admit != nil && admit.Handles(admission.Delete) {
userInfo, _ := request.UserFrom(ctx) userInfo, _ := request.UserFrom(ctx)
attrs := admission.NewAttributesRecord(nil, nil, scope.Kind, namespace, name, scope.Resource, scope.Subresource, admission.Delete, userInfo)
err = mutatingAdmission.Admit(admission.NewAttributesRecord(nil, nil, scope.Kind, namespace, name, scope.Resource, scope.Subresource, admission.Delete, userInfo)) if mutatingAdmission, ok := admit.(admission.MutationInterface); ok {
if err != nil { if err := mutatingAdmission.Admit(attrs); err != nil {
scope.err(err, w, req) scope.err(err, w, req)
return return
} }
} }
// TODO: avoid calling Handles twice if validatingAdmission, ok := admit.(admission.ValidationInterface); ok {
if validatingAdmission, ok := admit.(admission.ValidationInterface); ok && validatingAdmission.Handles(admission.Delete) { if err := validatingAdmission.ValidatingAdmit(attrs); err != nil {
userInfo, _ := request.UserFrom(ctx)
err = validatingAdmission.ValidatingAdmit(admission.NewAttributesRecord(nil, nil, scope.Kind, namespace, name, scope.Resource, scope.Subresource, admission.Delete, userInfo))
if err != nil {
scope.err(err, w, req) scope.err(err, w, req)
return return
} }
} }
}
trace.Step("About to delete object from database") trace.Step("About to delete object from database")
wasDeleted := true wasDeleted := true
......
...@@ -226,11 +226,21 @@ type UpdatedObjectInfo interface { ...@@ -226,11 +226,21 @@ type UpdatedObjectInfo interface {
// object. // object.
type ValidateObjectFunc func(obj runtime.Object) error type ValidateObjectFunc func(obj runtime.Object) error
// ValidateAllObjectFunc is a "admit everything" instance of ValidateObjectFunc.
func ValidateAllObjectFunc(obj runtime.Object) error {
return nil
}
// ValidateObjectUpdateFunc is a function to act on a given object and its predecessor. // ValidateObjectUpdateFunc is a function to act on a given object and its predecessor.
// An error may be returned if the hook cannot be completed. An UpdateObjectFunc // An error may be returned if the hook cannot be completed. An UpdateObjectFunc
// may NOT transform the provided object. // may NOT transform the provided object.
type ValidateObjectUpdateFunc func(obj, old runtime.Object) error type ValidateObjectUpdateFunc func(obj, old runtime.Object) error
// ValidateAllObjectUpdateFunc is a "admit everything" instance of ValidateObjectUpdateFunc.
func ValidateAllObjectUpdateFunc(obj, old runtime.Object) error {
return nil
}
// Updater is an object that can update an instance of a RESTful object. // Updater is an object that can update an instance of a RESTful object.
type Updater interface { type Updater interface {
// New returns an empty object that can be used with Update after request data has been put into it. // New returns an empty object that can be used with Update after request data has been put into it.
......
...@@ -72,6 +72,6 @@ func (r *StatusREST) New() runtime.Object { ...@@ -72,6 +72,6 @@ func (r *StatusREST) New() runtime.Object {
} }
// Update alters the status subset of an object. // Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo) return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
} }
...@@ -37,17 +37,17 @@ func Register(plugins *admission.Plugins) { ...@@ -37,17 +37,17 @@ func Register(plugins *admission.Plugins) {
}) })
} }
type disallowFlunder struct { type DisallowFlunder struct {
*admission.Handler *admission.Handler
lister listers.FischerLister lister listers.FischerLister
} }
var _ = wardleinitializer.WantsInternalWardleInformerFactory(&disallowFlunder{}) var _ = wardleinitializer.WantsInternalWardleInformerFactory(&DisallowFlunder{})
// Admit ensures that the object in-flight is of kind Flunder. // Admit ensures that the object in-flight is of kind Flunder.
// In addition checks that the Name is not on the banned list. // In addition checks that the Name is not on the banned list.
// The list is stored in Fischers API objects. // The list is stored in Fischers API objects.
func (d *disallowFlunder) Admit(a admission.Attributes) error { func (d *DisallowFlunder) Admit(a admission.Attributes) error {
// we are only interested in flunders // we are only interested in flunders
if a.GetKind().GroupKind() != wardle.Kind("Flunder") { if a.GetKind().GroupKind() != wardle.Kind("Flunder") {
return nil return nil
...@@ -80,12 +80,12 @@ func (d *disallowFlunder) Admit(a admission.Attributes) error { ...@@ -80,12 +80,12 @@ func (d *disallowFlunder) Admit(a admission.Attributes) error {
// SetInternalWardleInformerFactory gets Lister from SharedInformerFactory. // SetInternalWardleInformerFactory gets Lister from SharedInformerFactory.
// The lister knows how to lists Fischers. // The lister knows how to lists Fischers.
func (d *disallowFlunder) SetInternalWardleInformerFactory(f informers.SharedInformerFactory) { func (d *DisallowFlunder) SetInternalWardleInformerFactory(f informers.SharedInformerFactory) {
d.lister = f.Wardle().InternalVersion().Fischers().Lister() d.lister = f.Wardle().InternalVersion().Fischers().Lister()
} }
// Validate checks whether the plugin was correctly initialized. // Validate checks whether the plugin was correctly initialized.
func (d *disallowFlunder) Validate() error { func (d *DisallowFlunder) Validate() error {
if d.lister == nil { if d.lister == nil {
return fmt.Errorf("missing fischer lister") return fmt.Errorf("missing fischer lister")
} }
...@@ -93,8 +93,8 @@ func (d *disallowFlunder) Validate() error { ...@@ -93,8 +93,8 @@ func (d *disallowFlunder) Validate() error {
} }
// New creates a new ban flunder admission plugin // New creates a new ban flunder admission plugin
func New() (admission.Interface, error) { func New() (*DisallowFlunder, error) {
return &disallowFlunder{ return &DisallowFlunder{
Handler: admission.NewHandler(admission.Create), Handler: admission.NewHandler(admission.Create),
}, nil }, nil
} }
...@@ -83,7 +83,7 @@ func TestNodeAuthorizer(t *testing.T) { ...@@ -83,7 +83,7 @@ func TestNodeAuthorizer(t *testing.T) {
// Set up NodeRestriction admission // Set up NodeRestriction admission
nodeRestrictionAdmission := noderestriction.NewPlugin(nodeidentifier.NewDefaultNodeIdentifier()) nodeRestrictionAdmission := noderestriction.NewPlugin(nodeidentifier.NewDefaultNodeIdentifier())
nodeRestrictionAdmission.SetInternalKubeClientSet(superuserClient) nodeRestrictionAdmission.SetInternalKubeClientSet(superuserClient)
if err := nodeRestrictionAdmission.Validate(); err != nil { if err := nodeRestrictionAdmission.ValidateInitialization(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment