pkg/genericapiserver/registry/rest: cut off pkg/api dependency

This commit is contained in:
Dr. Stefan Schimanski 2017-01-29 22:21:28 +01:00
parent a5d5527e96
commit 875ed5f5ef
3 changed files with 8 additions and 9 deletions

View File

@ -21,8 +21,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apiserver/pkg/apis/example"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/kubernetes/pkg/api"
) )
// TestFillObjectMetaSystemFields validates that system populated fields are set on an object // TestFillObjectMetaSystemFields validates that system populated fields are set on an object
@ -62,14 +62,15 @@ func TestHasObjectMetaSystemFieldValues(t *testing.T) {
func TestValidNamespace(t *testing.T) { func TestValidNamespace(t *testing.T) {
ctx := genericapirequest.NewDefaultContext() ctx := genericapirequest.NewDefaultContext()
namespace, _ := genericapirequest.NamespaceFrom(ctx) namespace, _ := genericapirequest.NamespaceFrom(ctx)
resource := api.ReplicationController{} // TODO: use some genericapiserver type here instead of clientapiv1
resource := example.Pod{}
if !ValidNamespace(ctx, &resource.ObjectMeta) { if !ValidNamespace(ctx, &resource.ObjectMeta) {
t.Fatalf("expected success") t.Fatalf("expected success")
} }
if namespace != resource.Namespace { if namespace != resource.Namespace {
t.Fatalf("expected resource to have the default namespace assigned during validation") t.Fatalf("expected resource to have the default namespace assigned during validation")
} }
resource = api.ReplicationController{ObjectMeta: metav1.ObjectMeta{Namespace: "other"}} resource = example.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: "other"}}
if ValidNamespace(ctx, &resource.ObjectMeta) { if ValidNamespace(ctx, &resource.ObjectMeta) {
t.Fatalf("Expected error that resource and context errors do not match because resource has different namespace") t.Fatalf("Expected error that resource and context errors do not match because resource has different namespace")
} }

View File

@ -27,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"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/kubernetes/pkg/api"
) )
//TODO: //TODO:
@ -184,7 +183,7 @@ type UpdatedObjectInfo interface {
// Returns preconditions built from the updated object, if applicable. // Returns preconditions built from the updated object, if applicable.
// May return nil, or a preconditions object containing nil fields, // May return nil, or a preconditions object containing nil fields,
// if no preconditions can be determined from the updated object. // if no preconditions can be determined from the updated object.
Preconditions() *api.Preconditions Preconditions() *metav1.Preconditions
// UpdatedObject returns the updated object, given a context and old object. // UpdatedObject returns the updated object, given a context and old object.
// The only time an empty oldObj should be passed in is if a "create on update" is occurring (there is no oldObj). // The only time an empty oldObj should be passed in is if a "create on update" is occurring (there is no oldObj).

View File

@ -25,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request" genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/validation/genericvalidation" "k8s.io/kubernetes/pkg/api/validation/genericvalidation"
) )
@ -143,7 +142,7 @@ func DefaultUpdatedObjectInfo(obj runtime.Object, copier runtime.ObjectCopier, t
} }
// Preconditions satisfies the UpdatedObjectInfo interface. // Preconditions satisfies the UpdatedObjectInfo interface.
func (i *defaultUpdatedObjectInfo) Preconditions() *api.Preconditions { func (i *defaultUpdatedObjectInfo) Preconditions() *metav1.Preconditions {
// Attempt to get the UID out of the object // Attempt to get the UID out of the object
accessor, err := meta.Accessor(i.obj) accessor, err := meta.Accessor(i.obj)
if err != nil { if err != nil {
@ -157,7 +156,7 @@ func (i *defaultUpdatedObjectInfo) Preconditions() *api.Preconditions {
return nil return nil
} }
return &api.Preconditions{UID: &uid} return &metav1.Preconditions{UID: &uid}
} }
// UpdatedObject satisfies the UpdatedObjectInfo interface. // UpdatedObject satisfies the UpdatedObjectInfo interface.
@ -206,7 +205,7 @@ func WrapUpdatedObjectInfo(objInfo UpdatedObjectInfo, transformers ...TransformF
} }
// Preconditions satisfies the UpdatedObjectInfo interface. // Preconditions satisfies the UpdatedObjectInfo interface.
func (i *wrappedUpdatedObjectInfo) Preconditions() *api.Preconditions { func (i *wrappedUpdatedObjectInfo) Preconditions() *metav1.Preconditions {
return i.objInfo.Preconditions() return i.objInfo.Preconditions()
} }