mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
pkg/genericapiserver/registry/rest: cut off pkg/api dependency
This commit is contained in:
parent
a5d5527e96
commit
875ed5f5ef
@ -21,8 +21,8 @@ import (
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
"k8s.io/apiserver/pkg/apis/example"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
// 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) {
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
namespace, _ := genericapirequest.NamespaceFrom(ctx)
|
||||
resource := api.ReplicationController{}
|
||||
// TODO: use some genericapiserver type here instead of clientapiv1
|
||||
resource := example.Pod{}
|
||||
if !ValidNamespace(ctx, &resource.ObjectMeta) {
|
||||
t.Fatalf("expected success")
|
||||
}
|
||||
if namespace != resource.Namespace {
|
||||
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) {
|
||||
t.Fatalf("Expected error that resource and context errors do not match because resource has different namespace")
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
//TODO:
|
||||
@ -184,7 +183,7 @@ type UpdatedObjectInfo interface {
|
||||
// Returns preconditions built from the updated object, if applicable.
|
||||
// May return nil, or a preconditions object containing nil fields,
|
||||
// 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.
|
||||
// The only time an empty oldObj should be passed in is if a "create on update" is occurring (there is no oldObj).
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"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.
|
||||
func (i *defaultUpdatedObjectInfo) Preconditions() *api.Preconditions {
|
||||
func (i *defaultUpdatedObjectInfo) Preconditions() *metav1.Preconditions {
|
||||
// Attempt to get the UID out of the object
|
||||
accessor, err := meta.Accessor(i.obj)
|
||||
if err != nil {
|
||||
@ -157,7 +156,7 @@ func (i *defaultUpdatedObjectInfo) Preconditions() *api.Preconditions {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &api.Preconditions{UID: &uid}
|
||||
return &metav1.Preconditions{UID: &uid}
|
||||
}
|
||||
|
||||
// UpdatedObject satisfies the UpdatedObjectInfo interface.
|
||||
@ -206,7 +205,7 @@ func WrapUpdatedObjectInfo(objInfo UpdatedObjectInfo, transformers ...TransformF
|
||||
}
|
||||
|
||||
// Preconditions satisfies the UpdatedObjectInfo interface.
|
||||
func (i *wrappedUpdatedObjectInfo) Preconditions() *api.Preconditions {
|
||||
func (i *wrappedUpdatedObjectInfo) Preconditions() *metav1.Preconditions {
|
||||
return i.objInfo.Preconditions()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user