mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
Move pkg/api.{Context,RequestContextMapper} into pkg/genericapiserver/api/request
This commit is contained in:
@@ -22,6 +22,7 @@ go_library(
|
||||
"//pkg/api/validation:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
@@ -41,5 +42,6 @@ go_test(
|
||||
"//pkg/api/testing:go_default_library",
|
||||
"//pkg/apimachinery/registered:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -18,6 +18,7 @@ go_library(
|
||||
"//pkg/api/errors/storage:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/core/namespace:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/generic/registry:go_default_library",
|
||||
@@ -35,6 +36,7 @@ go_test(
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/registrytest:go_default_library",
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
storageerr "k8s.io/kubernetes/pkg/api/errors/storage"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/registry/core/namespace"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
@@ -78,7 +79,7 @@ func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST, *Finaliz
|
||||
}
|
||||
|
||||
// Delete enforces life-cycle rules for namespace termination
|
||||
func (r *REST) Delete(ctx api.Context, name string, options *api.DeleteOptions) (runtime.Object, error) {
|
||||
func (r *REST) Delete(ctx genericapirequest.Context, name string, options *api.DeleteOptions) (runtime.Object, error) {
|
||||
nsObj, err := r.Get(ctx, name, &metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -174,12 +175,12 @@ func (r *StatusREST) New() runtime.Object {
|
||||
}
|
||||
|
||||
// Get retrieves the object from the storage. It is required to support Patch.
|
||||
func (r *StatusREST) Get(ctx api.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
func (r *StatusREST) Get(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
return r.store.Get(ctx, name, options)
|
||||
}
|
||||
|
||||
// Update alters the status subset of an object.
|
||||
func (r *StatusREST) Update(ctx api.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
return r.store.Update(ctx, name, objInfo)
|
||||
}
|
||||
|
||||
@@ -188,6 +189,6 @@ func (r *FinalizeREST) New() runtime.Object {
|
||||
}
|
||||
|
||||
// Update alters the status finalizers subset of an object.
|
||||
func (r *FinalizeREST) Update(ctx api.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
func (r *FinalizeREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
return r.store.Update(ctx, name, objInfo)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
@@ -65,7 +66,7 @@ func TestCreateSetsFields(t *testing.T) {
|
||||
defer server.Terminate(t)
|
||||
defer storage.Store.DestroyFunc()
|
||||
namespace := validNewNamespace()
|
||||
ctx := api.NewContext()
|
||||
ctx := genericapirequest.NewContext()
|
||||
_, err := storage.Create(ctx, namespace)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -141,7 +142,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
|
||||
defer server.Terminate(t)
|
||||
defer storage.Store.DestroyFunc()
|
||||
key := "namespaces/foo"
|
||||
ctx := api.NewContext()
|
||||
ctx := genericapirequest.NewContext()
|
||||
now := metav1.Now()
|
||||
namespace := &api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
@@ -166,7 +167,7 @@ func TestDeleteNamespaceWithCompleteFinalizers(t *testing.T) {
|
||||
defer server.Terminate(t)
|
||||
defer storage.Store.DestroyFunc()
|
||||
key := "namespaces/foo"
|
||||
ctx := api.NewContext()
|
||||
ctx := genericapirequest.NewContext()
|
||||
now := metav1.Now()
|
||||
namespace := &api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
|
||||
@@ -20,17 +20,18 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
// Registry is an interface implemented by things that know how to store Namespace objects.
|
||||
type Registry interface {
|
||||
ListNamespaces(ctx api.Context, options *api.ListOptions) (*api.NamespaceList, error)
|
||||
WatchNamespaces(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
|
||||
GetNamespace(ctx api.Context, namespaceID string, options *metav1.GetOptions) (*api.Namespace, error)
|
||||
CreateNamespace(ctx api.Context, namespace *api.Namespace) error
|
||||
UpdateNamespace(ctx api.Context, namespace *api.Namespace) error
|
||||
DeleteNamespace(ctx api.Context, namespaceID string) error
|
||||
ListNamespaces(ctx genericapirequest.Context, options *api.ListOptions) (*api.NamespaceList, error)
|
||||
WatchNamespaces(ctx genericapirequest.Context, options *api.ListOptions) (watch.Interface, error)
|
||||
GetNamespace(ctx genericapirequest.Context, namespaceID string, options *metav1.GetOptions) (*api.Namespace, error)
|
||||
CreateNamespace(ctx genericapirequest.Context, namespace *api.Namespace) error
|
||||
UpdateNamespace(ctx genericapirequest.Context, namespace *api.Namespace) error
|
||||
DeleteNamespace(ctx genericapirequest.Context, namespaceID string) error
|
||||
}
|
||||
|
||||
// storage puts strong typing around storage calls
|
||||
@@ -44,7 +45,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
|
||||
return &storage{s}
|
||||
}
|
||||
|
||||
func (s *storage) ListNamespaces(ctx api.Context, options *api.ListOptions) (*api.NamespaceList, error) {
|
||||
func (s *storage) ListNamespaces(ctx genericapirequest.Context, options *api.ListOptions) (*api.NamespaceList, error) {
|
||||
obj, err := s.List(ctx, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -52,11 +53,11 @@ func (s *storage) ListNamespaces(ctx api.Context, options *api.ListOptions) (*ap
|
||||
return obj.(*api.NamespaceList), nil
|
||||
}
|
||||
|
||||
func (s *storage) WatchNamespaces(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
func (s *storage) WatchNamespaces(ctx genericapirequest.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
return s.Watch(ctx, options)
|
||||
}
|
||||
|
||||
func (s *storage) GetNamespace(ctx api.Context, namespaceName string, options *metav1.GetOptions) (*api.Namespace, error) {
|
||||
func (s *storage) GetNamespace(ctx genericapirequest.Context, namespaceName string, options *metav1.GetOptions) (*api.Namespace, error) {
|
||||
obj, err := s.Get(ctx, namespaceName, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -64,17 +65,17 @@ func (s *storage) GetNamespace(ctx api.Context, namespaceName string, options *m
|
||||
return obj.(*api.Namespace), nil
|
||||
}
|
||||
|
||||
func (s *storage) CreateNamespace(ctx api.Context, namespace *api.Namespace) error {
|
||||
func (s *storage) CreateNamespace(ctx genericapirequest.Context, namespace *api.Namespace) error {
|
||||
_, err := s.Create(ctx, namespace)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *storage) UpdateNamespace(ctx api.Context, namespace *api.Namespace) error {
|
||||
func (s *storage) UpdateNamespace(ctx genericapirequest.Context, namespace *api.Namespace) error {
|
||||
_, _, err := s.Update(ctx, namespace.Name, rest.DefaultUpdatedObjectInfo(namespace, api.Scheme))
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *storage) DeleteNamespace(ctx api.Context, namespaceID string) error {
|
||||
func (s *storage) DeleteNamespace(ctx genericapirequest.Context, namespaceID string) error {
|
||||
_, err := s.Delete(ctx, namespaceID, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/validation"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
@@ -45,7 +46,7 @@ func (namespaceStrategy) NamespaceScoped() bool {
|
||||
}
|
||||
|
||||
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
|
||||
func (namespaceStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
func (namespaceStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||
// on create, status is active
|
||||
namespace := obj.(*api.Namespace)
|
||||
namespace.Status = api.NamespaceStatus{
|
||||
@@ -70,7 +71,7 @@ func (namespaceStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (namespaceStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (namespaceStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newNamespace := obj.(*api.Namespace)
|
||||
oldNamespace := old.(*api.Namespace)
|
||||
newNamespace.Spec.Finalizers = oldNamespace.Spec.Finalizers
|
||||
@@ -78,7 +79,7 @@ func (namespaceStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Obje
|
||||
}
|
||||
|
||||
// Validate validates a new namespace.
|
||||
func (namespaceStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
func (namespaceStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
|
||||
namespace := obj.(*api.Namespace)
|
||||
return validation.ValidateNamespace(namespace)
|
||||
}
|
||||
@@ -93,7 +94,7 @@ func (namespaceStrategy) AllowCreateOnUpdate() bool {
|
||||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (namespaceStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (namespaceStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
errorList := validation.ValidateNamespace(obj.(*api.Namespace))
|
||||
return append(errorList, validation.ValidateNamespaceUpdate(obj.(*api.Namespace), old.(*api.Namespace))...)
|
||||
}
|
||||
@@ -108,13 +109,13 @@ type namespaceStatusStrategy struct {
|
||||
|
||||
var StatusStrategy = namespaceStatusStrategy{Strategy}
|
||||
|
||||
func (namespaceStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (namespaceStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newNamespace := obj.(*api.Namespace)
|
||||
oldNamespace := old.(*api.Namespace)
|
||||
newNamespace.Spec = oldNamespace.Spec
|
||||
}
|
||||
|
||||
func (namespaceStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (namespaceStatusStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateNamespaceStatusUpdate(obj.(*api.Namespace), old.(*api.Namespace))
|
||||
}
|
||||
|
||||
@@ -124,12 +125,12 @@ type namespaceFinalizeStrategy struct {
|
||||
|
||||
var FinalizeStrategy = namespaceFinalizeStrategy{Strategy}
|
||||
|
||||
func (namespaceFinalizeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (namespaceFinalizeStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateNamespaceFinalizeUpdate(obj.(*api.Namespace), old.(*api.Namespace))
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (namespaceFinalizeStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (namespaceFinalizeStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newNamespace := obj.(*api.Namespace)
|
||||
oldNamespace := old.(*api.Namespace)
|
||||
newNamespace.Status = oldNamespace.Status
|
||||
|
||||
@@ -23,10 +23,11 @@ import (
|
||||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
func TestNamespaceStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if Strategy.NamespaceScoped() {
|
||||
t.Errorf("Namespaces should not be namespace scoped")
|
||||
}
|
||||
@@ -66,7 +67,7 @@ func TestNamespaceStrategy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNamespaceStatusStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if StatusStrategy.NamespaceScoped() {
|
||||
t.Errorf("Namespaces should not be namespace scoped")
|
||||
}
|
||||
@@ -100,7 +101,7 @@ func TestNamespaceStatusStrategy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNamespaceFinalizeStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if FinalizeStrategy.NamespaceScoped() {
|
||||
t.Errorf("Namespaces should not be namespace scoped")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user