mirror of https://github.com/k3s-io/k3s
Merge pull request #39353 from sttts/sttts-requestcontextmapper-move
Automatic merge from submit-queue (batch tested with PRs 39075, 39350, 39353) Move pkg/api.{Context,RequestContextMapper} into pkg/genericapiserver/api/request **Based on #39350**pull/6/head
commit
63eec9608d
|
@ -41,6 +41,7 @@ go_library(
|
|||
"//pkg/genericapiserver:go_default_library",
|
||||
"//pkg/genericapiserver/api/filters:go_default_library",
|
||||
"//pkg/genericapiserver/api/handlers/responsewriters:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/genericapiserver/filters:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
authhandlers "k8s.io/kubernetes/pkg/auth/handlers"
|
||||
kubeclientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
|
@ -29,6 +28,7 @@ import (
|
|||
v1listers "k8s.io/kubernetes/pkg/client/listers/core/v1"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver"
|
||||
genericapifilters "k8s.io/kubernetes/pkg/genericapiserver/api/filters"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
genericfilters "k8s.io/kubernetes/pkg/genericapiserver/filters"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
"k8s.io/kubernetes/pkg/util/wait"
|
||||
|
@ -63,7 +63,7 @@ type Config struct {
|
|||
type APIDiscoveryServer struct {
|
||||
GenericAPIServer *genericapiserver.GenericAPIServer
|
||||
|
||||
contextMapper api.RequestContextMapper
|
||||
contextMapper genericapirequest.RequestContextMapper
|
||||
|
||||
// proxyClientCert/Key are the client cert used to identify this proxy. Backing APIServices use
|
||||
// this to confirm the proxy's identity
|
||||
|
@ -198,7 +198,7 @@ func (h *handlerChainConfig) handlerChain(apiHandler http.Handler, c *genericapi
|
|||
handler = genericfilters.WithTimeoutForNonLongRunningRequests(handler, c.RequestContextMapper, c.LongRunningFunc)
|
||||
handler = genericfilters.WithMaxInFlightLimit(handler, c.MaxRequestsInFlight, c.MaxMutatingRequestsInFlight, c.RequestContextMapper, c.LongRunningFunc)
|
||||
handler = genericapifilters.WithRequestInfo(handler, genericapiserver.NewRequestInfoResolver(c), c.RequestContextMapper)
|
||||
handler = api.WithRequestContext(handler, c.RequestContextMapper)
|
||||
handler = genericapirequest.WithRequestContext(handler, c.RequestContextMapper)
|
||||
|
||||
return handler, nil
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ import (
|
|||
"net/url"
|
||||
"sync"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/client/restclient"
|
||||
"k8s.io/kubernetes/pkg/client/transport"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers/responsewriters"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
genericrest "k8s.io/kubernetes/pkg/registry/generic/rest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util/httpstream/spdy"
|
||||
|
@ -35,7 +35,7 @@ import (
|
|||
// proxyHandler provides a http.Handler which will proxy traffic to locations
|
||||
// specified by items implementing Redirector.
|
||||
type proxyHandler struct {
|
||||
contextMapper api.RequestContextMapper
|
||||
contextMapper genericapirequest.RequestContextMapper
|
||||
|
||||
// proxyClientCert/Key are the client cert used to identify this proxy. Backing APIServices use
|
||||
// this to confirm the proxy's identity
|
||||
|
@ -71,7 +71,7 @@ func (r *proxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
http.Error(w, "missing context", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
user, ok := api.UserFrom(ctx)
|
||||
user, ok := genericapirequest.UserFrom(ctx)
|
||||
if !ok {
|
||||
http.Error(w, "missing user", http.StatusInternalServerError)
|
||||
return
|
||||
|
|
|
@ -56,10 +56,10 @@ type fakeRequestContextMapper struct {
|
|||
user user.Info
|
||||
}
|
||||
|
||||
func (m *fakeRequestContextMapper) Get(req *http.Request) (api.Context, bool) {
|
||||
ctx := api.NewContext()
|
||||
func (m *fakeRequestContextMapper) Get(req *http.Request) (genericapirequest.Context, bool) {
|
||||
ctx := genericapirequest.NewContext()
|
||||
if m.user != nil {
|
||||
ctx = api.WithUser(ctx, m.user)
|
||||
ctx = genericapirequest.WithUser(ctx, m.user)
|
||||
}
|
||||
|
||||
resolver := &genericapirequest.RequestInfoFactory{
|
||||
|
@ -74,7 +74,7 @@ func (m *fakeRequestContextMapper) Get(req *http.Request) (api.Context, bool) {
|
|||
return ctx, true
|
||||
}
|
||||
|
||||
func (*fakeRequestContextMapper) Update(req *http.Request, context api.Context) error {
|
||||
func (*fakeRequestContextMapper) Update(req *http.Request, context genericapirequest.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ go_library(
|
|||
"//cmd/kubernetes-discovery/pkg/apis/apiregistration/validation:go_default_library",
|
||||
"//pkg/api: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",
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
kapi "k8s.io/kubernetes/pkg/api"
|
||||
"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"
|
||||
|
@ -42,17 +43,17 @@ func (apiServerStrategy) NamespaceScoped() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (apiServerStrategy) PrepareForCreate(ctx kapi.Context, obj runtime.Object) {
|
||||
func (apiServerStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||
_ = obj.(*apiregistration.APIService)
|
||||
}
|
||||
|
||||
func (apiServerStrategy) PrepareForUpdate(ctx kapi.Context, obj, old runtime.Object) {
|
||||
func (apiServerStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newAPIService := obj.(*apiregistration.APIService)
|
||||
oldAPIService := old.(*apiregistration.APIService)
|
||||
newAPIService.Status = oldAPIService.Status
|
||||
}
|
||||
|
||||
func (apiServerStrategy) Validate(ctx kapi.Context, obj runtime.Object) field.ErrorList {
|
||||
func (apiServerStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
|
||||
return validation.ValidateAPIService(obj.(*apiregistration.APIService))
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,7 @@ func (apiServerStrategy) AllowUnconditionalUpdate() bool {
|
|||
func (apiServerStrategy) Canonicalize(obj runtime.Object) {
|
||||
}
|
||||
|
||||
func (apiServerStrategy) ValidateUpdate(ctx kapi.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (apiServerStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateAPIServiceUpdate(obj.(*apiregistration.APIService), old.(*apiregistration.APIService))
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ go_library(
|
|||
"//cmd/libs/go2idl/client-gen/test_apis/testgroup:go_default_library",
|
||||
"//pkg/api: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/generic/registry:go_default_library",
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/test_apis/testgroup"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
|
@ -63,10 +64,12 @@ type fakeStrategy struct {
|
|||
api.NameGenerator
|
||||
}
|
||||
|
||||
func (*fakeStrategy) NamespaceScoped() bool { return false }
|
||||
func (*fakeStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {}
|
||||
func (*fakeStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList { return nil }
|
||||
func (*fakeStrategy) Canonicalize(obj runtime.Object) {}
|
||||
func (*fakeStrategy) NamespaceScoped() bool { return false }
|
||||
func (*fakeStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {}
|
||||
func (*fakeStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
|
||||
return nil
|
||||
}
|
||||
func (*fakeStrategy) Canonicalize(obj runtime.Object) {}
|
||||
|
||||
var strategy = &fakeStrategy{api.Scheme, api.SimpleNameGenerator}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ go_library(
|
|||
"//pkg/api/rest: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",
|
||||
|
@ -42,6 +43,7 @@ go_test(
|
|||
"//pkg/api/testing:go_default_library",
|
||||
"//pkg/apimachinery/registered:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -15,8 +15,8 @@ go_library(
|
|||
deps = [
|
||||
"//federation/apis/federation:go_default_library",
|
||||
"//federation/registry/cluster:go_default_library",
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/generic/registry:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
|
|
|
@ -19,8 +19,8 @@ package etcd
|
|||
import (
|
||||
"k8s.io/kubernetes/federation/apis/federation"
|
||||
"k8s.io/kubernetes/federation/registry/cluster"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
|
@ -39,7 +39,7 @@ func (r *StatusREST) New() runtime.Object {
|
|||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,17 +21,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 Cluster objects.
|
||||
type Registry interface {
|
||||
ListClusters(ctx api.Context, options *api.ListOptions) (*federation.ClusterList, error)
|
||||
WatchCluster(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
|
||||
GetCluster(ctx api.Context, name string, options *metav1.GetOptions) (*federation.Cluster, error)
|
||||
CreateCluster(ctx api.Context, cluster *federation.Cluster) error
|
||||
UpdateCluster(ctx api.Context, cluster *federation.Cluster) error
|
||||
DeleteCluster(ctx api.Context, name string) error
|
||||
ListClusters(ctx genericapirequest.Context, options *api.ListOptions) (*federation.ClusterList, error)
|
||||
WatchCluster(ctx genericapirequest.Context, options *api.ListOptions) (watch.Interface, error)
|
||||
GetCluster(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*federation.Cluster, error)
|
||||
CreateCluster(ctx genericapirequest.Context, cluster *federation.Cluster) error
|
||||
UpdateCluster(ctx genericapirequest.Context, cluster *federation.Cluster) error
|
||||
DeleteCluster(ctx genericapirequest.Context, name string) error
|
||||
}
|
||||
|
||||
// storage puts strong typing around storage calls
|
||||
|
@ -45,7 +46,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
|
|||
return &storage{s}
|
||||
}
|
||||
|
||||
func (s *storage) ListClusters(ctx api.Context, options *api.ListOptions) (*federation.ClusterList, error) {
|
||||
func (s *storage) ListClusters(ctx genericapirequest.Context, options *api.ListOptions) (*federation.ClusterList, error) {
|
||||
obj, err := s.List(ctx, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -53,11 +54,11 @@ func (s *storage) ListClusters(ctx api.Context, options *api.ListOptions) (*fede
|
|||
return obj.(*federation.ClusterList), nil
|
||||
}
|
||||
|
||||
func (s *storage) WatchCluster(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
func (s *storage) WatchCluster(ctx genericapirequest.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
return s.Watch(ctx, options)
|
||||
}
|
||||
|
||||
func (s *storage) GetCluster(ctx api.Context, name string, options *metav1.GetOptions) (*federation.Cluster, error) {
|
||||
func (s *storage) GetCluster(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*federation.Cluster, error) {
|
||||
obj, err := s.Get(ctx, name, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -65,17 +66,17 @@ func (s *storage) GetCluster(ctx api.Context, name string, options *metav1.GetOp
|
|||
return obj.(*federation.Cluster), nil
|
||||
}
|
||||
|
||||
func (s *storage) CreateCluster(ctx api.Context, cluster *federation.Cluster) error {
|
||||
func (s *storage) CreateCluster(ctx genericapirequest.Context, cluster *federation.Cluster) error {
|
||||
_, err := s.Create(ctx, cluster)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *storage) UpdateCluster(ctx api.Context, cluster *federation.Cluster) error {
|
||||
func (s *storage) UpdateCluster(ctx genericapirequest.Context, cluster *federation.Cluster) error {
|
||||
_, _, err := s.Update(ctx, cluster.Name, rest.DefaultUpdatedObjectInfo(cluster, api.Scheme))
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *storage) DeleteCluster(ctx api.Context, name string) error {
|
||||
func (s *storage) DeleteCluster(ctx genericapirequest.Context, name string) error {
|
||||
_, err := s.Delete(ctx, name, nil)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"k8s.io/kubernetes/federation/apis/federation/validation"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"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"
|
||||
|
@ -63,13 +64,13 @@ func MatchCluster(label labels.Selector, field fields.Selector) apistorage.Selec
|
|||
}
|
||||
|
||||
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
|
||||
func (clusterStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
func (clusterStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||
cluster := obj.(*federation.Cluster)
|
||||
cluster.Status = federation.ClusterStatus{}
|
||||
}
|
||||
|
||||
// Validate validates a new cluster.
|
||||
func (clusterStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
func (clusterStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
|
||||
cluster := obj.(*federation.Cluster)
|
||||
return validation.ValidateCluster(cluster)
|
||||
}
|
||||
|
@ -84,14 +85,14 @@ func (clusterStrategy) AllowCreateOnUpdate() bool {
|
|||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (clusterStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (clusterStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
cluster := obj.(*federation.Cluster)
|
||||
oldCluster := old.(*federation.Cluster)
|
||||
cluster.Status = oldCluster.Status
|
||||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (clusterStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (clusterStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateClusterUpdate(obj.(*federation.Cluster), old.(*federation.Cluster))
|
||||
}
|
||||
func (clusterStrategy) AllowUnconditionalUpdate() bool {
|
||||
|
@ -104,16 +105,16 @@ type clusterStatusStrategy struct {
|
|||
|
||||
var StatusStrategy = clusterStatusStrategy{Strategy}
|
||||
|
||||
func (clusterStatusStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
func (clusterStatusStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||
_ = obj.(*federation.Cluster)
|
||||
}
|
||||
func (clusterStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (clusterStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
cluster := obj.(*federation.Cluster)
|
||||
oldCluster := old.(*federation.Cluster)
|
||||
cluster.Spec = oldCluster.Spec
|
||||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (clusterStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (clusterStatusStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateClusterStatusUpdate(obj.(*federation.Cluster), old.(*federation.Cluster))
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
)
|
||||
|
||||
|
@ -70,7 +71,7 @@ func invalidNewCluster() *federation.Cluster {
|
|||
}
|
||||
|
||||
func TestClusterStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if Strategy.NamespaceScoped() {
|
||||
t.Errorf("Cluster should not be namespace scoped")
|
||||
}
|
||||
|
@ -104,7 +105,7 @@ func TestClusterStrategy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClusterStatusStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if StatusStrategy.NamespaceScoped() {
|
||||
t.Errorf("Cluster should not be namespace scoped")
|
||||
}
|
||||
|
|
|
@ -179,6 +179,7 @@ pkg/credentialprovider/aws
|
|||
pkg/genericapiserver/api/audit
|
||||
pkg/genericapiserver/api/handlers/responsewriters
|
||||
pkg/genericapiserver/api/openapi
|
||||
pkg/genericapiserver/api/request
|
||||
pkg/genericapiserver/filters
|
||||
pkg/genericapiserver/mux
|
||||
pkg/genericapiserver/routes
|
||||
|
|
|
@ -11,7 +11,6 @@ load(
|
|||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"context.go",
|
||||
"conversion.go",
|
||||
"defaults.go",
|
||||
"doc.go",
|
||||
|
@ -22,7 +21,6 @@ go_library(
|
|||
"meta.go",
|
||||
"ref.go",
|
||||
"register.go",
|
||||
"requestcontext.go",
|
||||
"resource_helpers.go",
|
||||
"types.go",
|
||||
"zz_generated.deepcopy.go",
|
||||
|
@ -32,9 +30,9 @@ go_library(
|
|||
"//pkg/api/meta:go_default_library",
|
||||
"//pkg/api/resource:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/auth/user:go_default_library",
|
||||
"//pkg/conversion:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
|
@ -48,8 +46,6 @@ go_library(
|
|||
"//pkg/util/uuid:go_default_library",
|
||||
"//pkg/util/validation/field:go_default_library",
|
||||
"//vendor:github.com/davecgh/go-spew/spew",
|
||||
"//vendor:github.com/golang/glog",
|
||||
"//vendor:golang.org/x/net/context",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -75,7 +71,6 @@ go_test(
|
|||
go_test(
|
||||
name = "go_default_xtest",
|
||||
srcs = [
|
||||
"context_test.go",
|
||||
"conversion_test.go",
|
||||
"copy_test.go",
|
||||
"deep_copy_test.go",
|
||||
|
@ -96,8 +91,8 @@ go_test(
|
|||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/apis/extensions/v1beta1:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/auth/user:go_default_library",
|
||||
"//pkg/conversion:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
"//pkg/runtime/serializer/protobuf:go_default_library",
|
||||
|
|
|
@ -20,17 +20,18 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/conversion"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util/uuid"
|
||||
)
|
||||
|
||||
// FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.
|
||||
func FillObjectMetaSystemFields(ctx Context, meta *ObjectMeta) {
|
||||
func FillObjectMetaSystemFields(ctx genericapirequest.Context, meta *ObjectMeta) {
|
||||
meta.CreationTimestamp = metav1.Now()
|
||||
// allows admission controllers to assign a UID earlier in the request processing
|
||||
// to support tracking resources pending creation.
|
||||
uid, found := UIDFrom(ctx)
|
||||
uid, found := genericapirequest.UIDFrom(ctx)
|
||||
if !found {
|
||||
uid = uuid.NewUUID()
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
"k8s.io/kubernetes/pkg/util/uuid"
|
||||
|
@ -35,7 +36,7 @@ var _ meta.Object = &api.ObjectMeta{}
|
|||
|
||||
// TestFillObjectMetaSystemFields validates that system populated fields are set on an object
|
||||
func TestFillObjectMetaSystemFields(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
resource := api.ObjectMeta{}
|
||||
api.FillObjectMetaSystemFields(ctx, &resource)
|
||||
if resource.CreationTimestamp.Time.IsZero() {
|
||||
|
@ -45,7 +46,7 @@ func TestFillObjectMetaSystemFields(t *testing.T) {
|
|||
}
|
||||
// verify we can inject a UID
|
||||
uid := uuid.NewUUID()
|
||||
ctx = api.WithUID(ctx, uid)
|
||||
ctx = genericapirequest.WithUID(ctx, uid)
|
||||
resource = api.ObjectMeta{}
|
||||
api.FillObjectMetaSystemFields(ctx, &resource)
|
||||
if resource.UID != uid {
|
||||
|
@ -55,7 +56,7 @@ func TestFillObjectMetaSystemFields(t *testing.T) {
|
|||
|
||||
// TestHasObjectMetaSystemFieldValues validates that true is returned if and only if all fields are populated
|
||||
func TestHasObjectMetaSystemFieldValues(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
resource := api.ObjectMeta{}
|
||||
if api.HasObjectMetaSystemFieldValues(&resource) {
|
||||
t.Errorf("the resource does not have all fields yet populated, but incorrectly reports it does")
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
// Returns string version of ResourceName.
|
||||
|
@ -227,3 +228,13 @@ func PodRequestsAndLimits(pod *Pod) (reqs map[ResourceName]resource.Quantity, li
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ValidNamespace returns false if the namespace on the context differs from the resource. If the resource has no namespace, it is set to the value in the context.
|
||||
// TODO(sttts): move into pkg/genericapiserver/api
|
||||
func ValidNamespace(ctx genericapirequest.Context, resource *ObjectMeta) bool {
|
||||
ns, ok := genericapirequest.NamespaceFrom(ctx)
|
||||
if len(resource.Namespace) == 0 {
|
||||
resource.Namespace = ns
|
||||
}
|
||||
return ns == resource.Namespace && ok
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ go_library(
|
|||
"//pkg/api/validation:go_default_library",
|
||||
"//pkg/api/validation/path:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
"//pkg/util/validation/field:go_default_library",
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/validation"
|
||||
path "k8s.io/kubernetes/pkg/api/validation/path"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
"k8s.io/kubernetes/pkg/util/validation/field"
|
||||
|
@ -41,10 +42,10 @@ type RESTCreateStrategy interface {
|
|||
// the object. For example: remove fields that are not to be persisted,
|
||||
// sort order-insensitive list fields, etc. This should not remove fields
|
||||
// whose presence would be considered a validation error.
|
||||
PrepareForCreate(ctx api.Context, obj runtime.Object)
|
||||
PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object)
|
||||
// Validate is invoked after default fields in the object have been filled in before
|
||||
// the object is persisted. This method should not mutate the object.
|
||||
Validate(ctx api.Context, obj runtime.Object) field.ErrorList
|
||||
Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList
|
||||
// Canonicalize is invoked after validation has succeeded but before the
|
||||
// object has been persisted. This method may mutate the object.
|
||||
Canonicalize(obj runtime.Object)
|
||||
|
@ -53,7 +54,7 @@ type RESTCreateStrategy interface {
|
|||
// BeforeCreate ensures that common operations for all resources are performed on creation. It only returns
|
||||
// errors that can be converted to api.Status. It invokes PrepareForCreate, then GenerateName, then Validate.
|
||||
// It returns nil if the object should be created.
|
||||
func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Object) error {
|
||||
func BeforeCreate(strategy RESTCreateStrategy, ctx genericapirequest.Context, obj runtime.Object) error {
|
||||
objectMeta, kind, kerr := objectMetaAndKind(strategy, obj)
|
||||
if kerr != nil {
|
||||
return kerr
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
)
|
||||
|
@ -52,7 +53,7 @@ type GarbageCollectionDeleteStrategy interface {
|
|||
type RESTGracefulDeleteStrategy interface {
|
||||
// CheckGracefulDelete should return true if the object can be gracefully deleted and set
|
||||
// any default values on the DeleteOptions.
|
||||
CheckGracefulDelete(ctx api.Context, obj runtime.Object, options *api.DeleteOptions) bool
|
||||
CheckGracefulDelete(ctx genericapirequest.Context, obj runtime.Object, options *api.DeleteOptions) bool
|
||||
}
|
||||
|
||||
// BeforeDelete tests whether the object can be gracefully deleted. If graceful is set the object
|
||||
|
@ -61,7 +62,7 @@ type RESTGracefulDeleteStrategy interface {
|
|||
// condition cannot be checked or the gracePeriodSeconds is invalid. The options argument may be updated with
|
||||
// default values if graceful is true. Second place where we set deletionTimestamp is pkg/registry/generic/registry/store.go
|
||||
// this function is responsible for setting deletionTimestamp during gracefulDeletion, other one for cascading deletions.
|
||||
func BeforeDelete(strategy RESTDeleteStrategy, ctx api.Context, obj runtime.Object, options *api.DeleteOptions) (graceful, gracefulPending bool, err error) {
|
||||
func BeforeDelete(strategy RESTDeleteStrategy, ctx genericapirequest.Context, obj runtime.Object, options *api.DeleteOptions) (graceful, gracefulPending bool, err error) {
|
||||
objectMeta, gvk, kerr := objectMetaAndKind(strategy, obj)
|
||||
if kerr != nil {
|
||||
return false, false, kerr
|
||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
package rest
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
|
@ -25,5 +25,5 @@ import (
|
|||
type RESTExportStrategy interface {
|
||||
// Export strips fields that can not be set by the user. If 'exact' is false
|
||||
// fields specific to the cluster are also stripped
|
||||
Export(ctx api.Context, obj runtime.Object, exact bool) error
|
||||
Export(ctx genericapirequest.Context, obj runtime.Object, exact bool) error
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
|
@ -70,7 +71,7 @@ type Lister interface {
|
|||
// This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object)
|
||||
NewList() runtime.Object
|
||||
// List selects resources in the storage which match to the selector. 'options' can be nil.
|
||||
List(ctx api.Context, options *api.ListOptions) (runtime.Object, error)
|
||||
List(ctx genericapirequest.Context, options *api.ListOptions) (runtime.Object, error)
|
||||
}
|
||||
|
||||
// Exporter is an object that knows how to strip a RESTful resource for export
|
||||
|
@ -78,7 +79,7 @@ type Exporter interface {
|
|||
// Export an object. Fields that are not user specified (e.g. Status, ObjectMeta.ResourceVersion) are stripped out
|
||||
// Returns the stripped object. If 'exact' is true, fields that are specific to the cluster (e.g. namespace) are
|
||||
// retained, otherwise they are stripped also.
|
||||
Export(ctx api.Context, name string, opts metav1.ExportOptions) (runtime.Object, error)
|
||||
Export(ctx genericapirequest.Context, name string, opts metav1.ExportOptions) (runtime.Object, error)
|
||||
}
|
||||
|
||||
// Getter is an object that can retrieve a named RESTful resource.
|
||||
|
@ -86,7 +87,7 @@ type Getter interface {
|
|||
// Get finds a resource in the storage by name and returns it.
|
||||
// Although it can return an arbitrary error value, IsNotFound(err) is true for the
|
||||
// returned error value err when the specified resource is not found.
|
||||
Get(ctx api.Context, name string, options *metav1.GetOptions) (runtime.Object, error)
|
||||
Get(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (runtime.Object, error)
|
||||
}
|
||||
|
||||
// GetterWithOptions is an object that retrieve a named RESTful resource and takes
|
||||
|
@ -99,7 +100,7 @@ type GetterWithOptions interface {
|
|||
// The options object passed to it is of the same type returned by the NewGetOptions
|
||||
// method.
|
||||
// TODO: Pass metav1.GetOptions.
|
||||
Get(ctx api.Context, name string, options runtime.Object) (runtime.Object, error)
|
||||
Get(ctx genericapirequest.Context, name string, options runtime.Object) (runtime.Object, error)
|
||||
|
||||
// NewGetOptions returns an empty options object that will be used to pass
|
||||
// options to the Get method. It may return a bool and a string, if true, the
|
||||
|
@ -117,7 +118,7 @@ type Deleter interface {
|
|||
// returned error value err when the specified resource is not found.
|
||||
// Delete *may* return the object that was deleted, or a status object indicating additional
|
||||
// information about deletion.
|
||||
Delete(ctx api.Context, name string) (runtime.Object, error)
|
||||
Delete(ctx genericapirequest.Context, name string) (runtime.Object, error)
|
||||
}
|
||||
|
||||
// GracefulDeleter knows how to pass deletion options to allow delayed deletion of a
|
||||
|
@ -130,7 +131,7 @@ type GracefulDeleter interface {
|
|||
// returned error value err when the specified resource is not found.
|
||||
// Delete *may* return the object that was deleted, or a status object indicating additional
|
||||
// information about deletion.
|
||||
Delete(ctx api.Context, name string, options *api.DeleteOptions) (runtime.Object, error)
|
||||
Delete(ctx genericapirequest.Context, name string, options *api.DeleteOptions) (runtime.Object, error)
|
||||
}
|
||||
|
||||
// GracefulDeleteAdapter adapts the Deleter interface to GracefulDeleter
|
||||
|
@ -139,7 +140,7 @@ type GracefulDeleteAdapter struct {
|
|||
}
|
||||
|
||||
// Delete implements RESTGracefulDeleter in terms of Deleter
|
||||
func (w GracefulDeleteAdapter) Delete(ctx api.Context, name string, options *api.DeleteOptions) (runtime.Object, error) {
|
||||
func (w GracefulDeleteAdapter) Delete(ctx genericapirequest.Context, name string, options *api.DeleteOptions) (runtime.Object, error) {
|
||||
return w.Deleter.Delete(ctx, name)
|
||||
}
|
||||
|
||||
|
@ -151,7 +152,7 @@ type CollectionDeleter interface {
|
|||
// them or return an invalid request error.
|
||||
// DeleteCollection may not be atomic - i.e. it may delete some objects and still
|
||||
// return an error after it. On success, returns a list of deleted objects.
|
||||
DeleteCollection(ctx api.Context, options *api.DeleteOptions, listOptions *api.ListOptions) (runtime.Object, error)
|
||||
DeleteCollection(ctx genericapirequest.Context, options *api.DeleteOptions, listOptions *api.ListOptions) (runtime.Object, error)
|
||||
}
|
||||
|
||||
// Creater is an object that can create an instance of a RESTful object.
|
||||
|
@ -161,7 +162,7 @@ type Creater interface {
|
|||
New() runtime.Object
|
||||
|
||||
// Create creates a new version of a resource.
|
||||
Create(ctx api.Context, obj runtime.Object) (runtime.Object, error)
|
||||
Create(ctx genericapirequest.Context, obj runtime.Object) (runtime.Object, error)
|
||||
}
|
||||
|
||||
// NamedCreater is an object that can create an instance of a RESTful object using a name parameter.
|
||||
|
@ -173,7 +174,7 @@ type NamedCreater interface {
|
|||
// Create creates a new version of a resource. It expects a name parameter from the path.
|
||||
// This is needed for create operations on subresources which include the name of the parent
|
||||
// resource in the path.
|
||||
Create(ctx api.Context, name string, obj runtime.Object) (runtime.Object, error)
|
||||
Create(ctx genericapirequest.Context, name string, obj runtime.Object) (runtime.Object, error)
|
||||
}
|
||||
|
||||
// UpdatedObjectInfo provides information about an updated object to an Updater.
|
||||
|
@ -186,7 +187,7 @@ type UpdatedObjectInfo interface {
|
|||
|
||||
// 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).
|
||||
UpdatedObject(ctx api.Context, oldObj runtime.Object) (newObj runtime.Object, err error)
|
||||
UpdatedObject(ctx genericapirequest.Context, oldObj runtime.Object) (newObj runtime.Object, err error)
|
||||
}
|
||||
|
||||
// Updater is an object that can update an instance of a RESTful object.
|
||||
|
@ -198,14 +199,14 @@ type Updater interface {
|
|||
// Update finds a resource in the storage and updates it. Some implementations
|
||||
// may allow updates creates the object - they should set the created boolean
|
||||
// to true.
|
||||
Update(ctx api.Context, name string, objInfo UpdatedObjectInfo) (runtime.Object, bool, error)
|
||||
Update(ctx genericapirequest.Context, name string, objInfo UpdatedObjectInfo) (runtime.Object, bool, error)
|
||||
}
|
||||
|
||||
// CreaterUpdater is a storage object that must support both create and update.
|
||||
// Go prevents embedded interfaces that implement the same method.
|
||||
type CreaterUpdater interface {
|
||||
Creater
|
||||
Update(ctx api.Context, name string, objInfo UpdatedObjectInfo) (runtime.Object, bool, error)
|
||||
Update(ctx genericapirequest.Context, name string, objInfo UpdatedObjectInfo) (runtime.Object, bool, error)
|
||||
}
|
||||
|
||||
// CreaterUpdater must satisfy the Updater interface.
|
||||
|
@ -224,7 +225,7 @@ type Watcher interface {
|
|||
// are supported; an error should be returned if 'field' tries to select on a field that
|
||||
// isn't supported. 'resourceVersion' allows for continuing/starting a watch at a
|
||||
// particular version.
|
||||
Watch(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
|
||||
Watch(ctx genericapirequest.Context, options *api.ListOptions) (watch.Interface, error)
|
||||
}
|
||||
|
||||
// StandardStorage is an interface covering the common verbs. Provided for testing whether a
|
||||
|
@ -241,7 +242,7 @@ type StandardStorage interface {
|
|||
// Redirector know how to return a remote resource's location.
|
||||
type Redirector interface {
|
||||
// ResourceLocation should return the remote location of the given resource, and an optional transport to use to request it, or an error.
|
||||
ResourceLocation(ctx api.Context, id string) (remoteLocation *url.URL, transport http.RoundTripper, err error)
|
||||
ResourceLocation(ctx genericapirequest.Context, id string) (remoteLocation *url.URL, transport http.RoundTripper, err error)
|
||||
}
|
||||
|
||||
// Responder abstracts the normal response behavior for a REST method and is passed to callers that
|
||||
|
@ -261,7 +262,7 @@ type Connecter interface {
|
|||
// code and body, so the ServeHTTP method should exit after invoking the responder. The Handler will
|
||||
// be used for a single API request and then discarded. The Responder is guaranteed to write to the
|
||||
// same http.ResponseWriter passed to ServeHTTP.
|
||||
Connect(ctx api.Context, id string, options runtime.Object, r Responder) (http.Handler, error)
|
||||
Connect(ctx genericapirequest.Context, id string, options runtime.Object, r Responder) (http.Handler, error)
|
||||
|
||||
// NewConnectOptions returns an empty options object that will be used to pass
|
||||
// options to the Connect method. If nil, then a nil options object is passed to
|
||||
|
|
|
@ -19,6 +19,7 @@ go_library(
|
|||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/conversion:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/types:go_default_library",
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/conversion"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
|
@ -96,11 +97,11 @@ func (t *Tester) TestNamespace() string {
|
|||
|
||||
// TestContext returns a namespaced context that will be used when making storage calls.
|
||||
// Namespace is determined by TestNamespace()
|
||||
func (t *Tester) TestContext() api.Context {
|
||||
func (t *Tester) TestContext() genericapirequest.Context {
|
||||
if t.clusterScope {
|
||||
return api.NewContext()
|
||||
return genericapirequest.NewContext()
|
||||
}
|
||||
return api.WithNamespace(api.NewContext(), t.TestNamespace())
|
||||
return genericapirequest.WithNamespace(genericapirequest.NewContext(), t.TestNamespace())
|
||||
}
|
||||
|
||||
func (t *Tester) getObjectMetaOrFail(obj runtime.Object) *api.ObjectMeta {
|
||||
|
@ -117,7 +118,7 @@ func (t *Tester) setObjectMeta(obj runtime.Object, name string) {
|
|||
if t.clusterScope {
|
||||
meta.Namespace = api.NamespaceNone
|
||||
} else {
|
||||
meta.Namespace = api.NamespaceValue(t.TestContext())
|
||||
meta.Namespace = genericapirequest.NamespaceValue(t.TestContext())
|
||||
}
|
||||
meta.GenerateName = ""
|
||||
meta.Generation = 1
|
||||
|
@ -133,11 +134,11 @@ func copyOrDie(obj runtime.Object) runtime.Object {
|
|||
|
||||
type AssignFunc func([]runtime.Object) []runtime.Object
|
||||
type EmitFunc func(runtime.Object, string) error
|
||||
type GetFunc func(api.Context, runtime.Object) (runtime.Object, error)
|
||||
type GetFunc func(genericapirequest.Context, runtime.Object) (runtime.Object, error)
|
||||
type InitWatchFunc func()
|
||||
type InjectErrFunc func(err error)
|
||||
type IsErrorFunc func(err error) bool
|
||||
type CreateFunc func(api.Context, runtime.Object) error
|
||||
type CreateFunc func(genericapirequest.Context, runtime.Object) error
|
||||
type SetRVFunc func(uint64)
|
||||
type UpdateFunc func(runtime.Object) runtime.Object
|
||||
|
||||
|
@ -223,7 +224,7 @@ func (t *Tester) TestWatch(
|
|||
// =============================================================================
|
||||
// Creation tests.
|
||||
|
||||
func (t *Tester) delete(ctx api.Context, obj runtime.Object) error {
|
||||
func (t *Tester) delete(ctx genericapirequest.Context, obj runtime.Object) error {
|
||||
objectMeta, err := api.ObjectMetaFor(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -332,7 +333,7 @@ func (t *Tester) testCreateHasMetadata(valid runtime.Object) {
|
|||
|
||||
func (t *Tester) testCreateIgnoresContextNamespace(valid runtime.Object) {
|
||||
// Ignore non-empty namespace in context
|
||||
ctx := api.WithNamespace(api.NewContext(), "not-default2")
|
||||
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), "not-default2")
|
||||
|
||||
// Ideally, we'd get an error back here, but at least verify the namespace wasn't persisted
|
||||
created, err := t.storage.(rest.Creater).Create(ctx, copyOrDie(valid))
|
||||
|
@ -351,7 +352,7 @@ func (t *Tester) testCreateIgnoresMismatchedNamespace(valid runtime.Object) {
|
|||
|
||||
// Ignore non-empty namespace in object meta
|
||||
objectMeta.Namespace = "not-default"
|
||||
ctx := api.WithNamespace(api.NewContext(), "not-default2")
|
||||
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), "not-default2")
|
||||
|
||||
// Ideally, we'd get an error back here, but at least verify the namespace wasn't persisted
|
||||
created, err := t.storage.(rest.Creater).Create(ctx, copyOrDie(valid))
|
||||
|
@ -580,7 +581,7 @@ func (t *Tester) testUpdateRetrievesOldObject(obj runtime.Object, createFn Creat
|
|||
// Make sure a custom transform is called, and sees the expected updatedObject and oldObject
|
||||
// This tests the mechanism used to pass the old and new object to admission
|
||||
calledUpdatedObject := 0
|
||||
noopTransform := func(_ api.Context, updatedObject runtime.Object, oldObject runtime.Object) (runtime.Object, error) {
|
||||
noopTransform := func(_ genericapirequest.Context, updatedObject runtime.Object, oldObject runtime.Object) (runtime.Object, error) {
|
||||
if !reflect.DeepEqual(storedFoo, oldObject) {
|
||||
t.Errorf("Expected\n\t%#v\ngot\n\t%#v", storedFoo, oldObject)
|
||||
}
|
||||
|
@ -622,7 +623,7 @@ func (t *Tester) testUpdatePropagatesUpdatedObjectError(obj runtime.Object, crea
|
|||
|
||||
// Make sure our transform is called, and sees the expected updatedObject and oldObject
|
||||
propagateErr := fmt.Errorf("custom updated object error for %v", foo)
|
||||
noopTransform := func(_ api.Context, updatedObject runtime.Object, oldObject runtime.Object) (runtime.Object, error) {
|
||||
noopTransform := func(_ genericapirequest.Context, updatedObject runtime.Object, oldObject runtime.Object) (runtime.Object, error) {
|
||||
return nil, propagateErr
|
||||
}
|
||||
|
||||
|
@ -1029,15 +1030,15 @@ func (t *Tester) testGetDifferentNamespace(obj runtime.Object) {
|
|||
objMeta := t.getObjectMetaOrFail(obj)
|
||||
objMeta.Name = t.namer(5)
|
||||
|
||||
ctx1 := api.WithNamespace(api.NewContext(), "bar3")
|
||||
objMeta.Namespace = api.NamespaceValue(ctx1)
|
||||
ctx1 := genericapirequest.WithNamespace(genericapirequest.NewContext(), "bar3")
|
||||
objMeta.Namespace = genericapirequest.NamespaceValue(ctx1)
|
||||
_, err := t.storage.(rest.Creater).Create(ctx1, obj)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
ctx2 := api.WithNamespace(api.NewContext(), "bar4")
|
||||
objMeta.Namespace = api.NamespaceValue(ctx2)
|
||||
ctx2 := genericapirequest.WithNamespace(genericapirequest.NewContext(), "bar4")
|
||||
objMeta.Namespace = genericapirequest.NamespaceValue(ctx2)
|
||||
_, err = t.storage.(rest.Creater).Create(ctx2, obj)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
|
@ -1051,8 +1052,8 @@ func (t *Tester) testGetDifferentNamespace(obj runtime.Object) {
|
|||
if got1Meta.Name != objMeta.Name {
|
||||
t.Errorf("unexpected name of object: %#v, expected: %s", got1, objMeta.Name)
|
||||
}
|
||||
if got1Meta.Namespace != api.NamespaceValue(ctx1) {
|
||||
t.Errorf("unexpected namespace of object: %#v, expected: %s", got1, api.NamespaceValue(ctx1))
|
||||
if got1Meta.Namespace != genericapirequest.NamespaceValue(ctx1) {
|
||||
t.Errorf("unexpected namespace of object: %#v, expected: %s", got1, genericapirequest.NamespaceValue(ctx1))
|
||||
}
|
||||
|
||||
got2, err := t.storage.(rest.Getter).Get(ctx2, objMeta.Name, &metav1.GetOptions{})
|
||||
|
@ -1063,8 +1064,8 @@ func (t *Tester) testGetDifferentNamespace(obj runtime.Object) {
|
|||
if got2Meta.Name != objMeta.Name {
|
||||
t.Errorf("unexpected name of object: %#v, expected: %s", got2, objMeta.Name)
|
||||
}
|
||||
if got2Meta.Namespace != api.NamespaceValue(ctx2) {
|
||||
t.Errorf("unexpected namespace of object: %#v, expected: %s", got2, api.NamespaceValue(ctx2))
|
||||
if got2Meta.Namespace != genericapirequest.NamespaceValue(ctx2) {
|
||||
t.Errorf("unexpected namespace of object: %#v, expected: %s", got2, genericapirequest.NamespaceValue(ctx2))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1090,11 +1091,11 @@ func (t *Tester) testGetFound(obj runtime.Object) {
|
|||
}
|
||||
|
||||
func (t *Tester) testGetMimatchedNamespace(obj runtime.Object) {
|
||||
ctx1 := api.WithNamespace(api.NewContext(), "bar1")
|
||||
ctx2 := api.WithNamespace(api.NewContext(), "bar2")
|
||||
ctx1 := genericapirequest.WithNamespace(genericapirequest.NewContext(), "bar1")
|
||||
ctx2 := genericapirequest.WithNamespace(genericapirequest.NewContext(), "bar2")
|
||||
objMeta := t.getObjectMetaOrFail(obj)
|
||||
objMeta.Name = t.namer(4)
|
||||
objMeta.Namespace = api.NamespaceValue(ctx1)
|
||||
objMeta.Namespace = genericapirequest.NamespaceValue(ctx1)
|
||||
_, err := t.storage.(rest.Creater).Create(ctx1, obj)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
|
@ -1181,7 +1182,7 @@ func (t *Tester) testListMatchLabels(obj runtime.Object, assignFn AssignFunc) {
|
|||
foo4 := copyOrDie(obj)
|
||||
foo4Meta := t.getObjectMetaOrFail(foo4)
|
||||
foo4Meta.Name = "foo4"
|
||||
foo4Meta.Namespace = api.NamespaceValue(ctx)
|
||||
foo4Meta.Namespace = genericapirequest.NamespaceValue(ctx)
|
||||
foo4Meta.Labels = testLabels
|
||||
|
||||
objs := ([]runtime.Object{foo3, foo4})
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/api/validation"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util/validation/field"
|
||||
)
|
||||
|
@ -41,11 +42,11 @@ type RESTUpdateStrategy interface {
|
|||
// the object. For example: remove fields that are not to be persisted,
|
||||
// sort order-insensitive list fields, etc. This should not remove fields
|
||||
// whose presence would be considered a validation error.
|
||||
PrepareForUpdate(ctx api.Context, obj, old runtime.Object)
|
||||
PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object)
|
||||
// ValidateUpdate is invoked after default fields in the object have been
|
||||
// filled in before the object is persisted. This method should not mutate
|
||||
// the object.
|
||||
ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList
|
||||
ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList
|
||||
// Canonicalize is invoked after validation has succeeded but before the
|
||||
// object has been persisted. This method may mutate the object.
|
||||
Canonicalize(obj runtime.Object)
|
||||
|
@ -74,7 +75,7 @@ func validateCommonFields(obj, old runtime.Object) (field.ErrorList, error) {
|
|||
// BeforeUpdate ensures that common operations for all resources are performed on update. It only returns
|
||||
// errors that can be converted to api.Status. It will invoke update validation with the provided existing
|
||||
// and updated objects.
|
||||
func BeforeUpdate(strategy RESTUpdateStrategy, ctx api.Context, obj, old runtime.Object) error {
|
||||
func BeforeUpdate(strategy RESTUpdateStrategy, ctx genericapirequest.Context, obj, old runtime.Object) error {
|
||||
objectMeta, kind, kerr := objectMetaAndKind(strategy, obj)
|
||||
if kerr != nil {
|
||||
return kerr
|
||||
|
@ -115,7 +116,7 @@ func BeforeUpdate(strategy RESTUpdateStrategy, ctx api.Context, obj, old runtime
|
|||
}
|
||||
|
||||
// TransformFunc is a function to transform and return newObj
|
||||
type TransformFunc func(ctx api.Context, newObj runtime.Object, oldObj runtime.Object) (transformedNewObj runtime.Object, err error)
|
||||
type TransformFunc func(ctx genericapirequest.Context, newObj runtime.Object, oldObj runtime.Object) (transformedNewObj runtime.Object, err error)
|
||||
|
||||
// defaultUpdatedObjectInfo implements UpdatedObjectInfo
|
||||
type defaultUpdatedObjectInfo struct {
|
||||
|
@ -157,7 +158,7 @@ func (i *defaultUpdatedObjectInfo) Preconditions() *api.Preconditions {
|
|||
|
||||
// UpdatedObject satisfies the UpdatedObjectInfo interface.
|
||||
// It returns a copy of the held obj, passed through any configured transformers.
|
||||
func (i *defaultUpdatedObjectInfo) UpdatedObject(ctx api.Context, oldObj runtime.Object) (runtime.Object, error) {
|
||||
func (i *defaultUpdatedObjectInfo) UpdatedObject(ctx genericapirequest.Context, oldObj runtime.Object) (runtime.Object, error) {
|
||||
var err error
|
||||
// Start with the configured object
|
||||
newObj := i.obj
|
||||
|
@ -207,7 +208,7 @@ func (i *wrappedUpdatedObjectInfo) Preconditions() *api.Preconditions {
|
|||
|
||||
// UpdatedObject satisfies the UpdatedObjectInfo interface.
|
||||
// It delegates to the wrapped objInfo and passes the result through any configured transformers.
|
||||
func (i *wrappedUpdatedObjectInfo) UpdatedObject(ctx api.Context, oldObj runtime.Object) (runtime.Object, error) {
|
||||
func (i *wrappedUpdatedObjectInfo) UpdatedObject(ctx genericapirequest.Context, oldObj runtime.Object) (runtime.Object, error) {
|
||||
newObj, err := i.objInfo.UpdatedObject(ctx, oldObj)
|
||||
if err != nil {
|
||||
return newObj, err
|
||||
|
|
|
@ -17,12 +17,12 @@ go_library(
|
|||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/api/validation:go_default_library",
|
||||
"//pkg/api/validation/path:go_default_library",
|
||||
"//pkg/apis/rbac:go_default_library",
|
||||
"//pkg/auth/user:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/serviceaccount:go_default_library",
|
||||
"//pkg/util/errors:go_default_library",
|
||||
"//pkg/util/validation/field:go_default_library",
|
||||
|
|
|
@ -21,10 +21,10 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
apierrors "k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/apis/rbac"
|
||||
"k8s.io/kubernetes/pkg/auth/user"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/serviceaccount"
|
||||
utilerrors "k8s.io/kubernetes/pkg/util/errors"
|
||||
)
|
||||
|
@ -41,14 +41,14 @@ type AuthorizationRuleResolver interface {
|
|||
}
|
||||
|
||||
// ConfirmNoEscalation determines if the roles for a given user in a given namespace encompass the provided role.
|
||||
func ConfirmNoEscalation(ctx api.Context, ruleResolver AuthorizationRuleResolver, rules []rbac.PolicyRule) error {
|
||||
func ConfirmNoEscalation(ctx genericapirequest.Context, ruleResolver AuthorizationRuleResolver, rules []rbac.PolicyRule) error {
|
||||
ruleResolutionErrors := []error{}
|
||||
|
||||
user, ok := api.UserFrom(ctx)
|
||||
user, ok := genericapirequest.UserFrom(ctx)
|
||||
if !ok {
|
||||
return fmt.Errorf("no user on context")
|
||||
}
|
||||
namespace, _ := api.NamespaceFrom(ctx)
|
||||
namespace, _ := genericapirequest.NamespaceFrom(ctx)
|
||||
|
||||
ownerRules, err := ruleResolver.RulesFor(user, namespace)
|
||||
if err != nil {
|
||||
|
@ -59,7 +59,7 @@ func ConfirmNoEscalation(ctx api.Context, ruleResolver AuthorizationRuleResolver
|
|||
|
||||
ownerRightsCover, missingRights := Covers(ownerRules, rules)
|
||||
if !ownerRightsCover {
|
||||
user, _ := api.UserFrom(ctx)
|
||||
user, _ := genericapirequest.UserFrom(ctx)
|
||||
return apierrors.NewUnauthorized(fmt.Sprintf("attempt to grant extra privileges: %v user=%v ownerrules=%v ruleResolutionErrors=%v", missingRights, user, ownerRules, ruleResolutionErrors))
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -13,8 +13,8 @@ go_library(
|
|||
srcs = ["handlers.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/auth/authenticator:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//vendor:github.com/golang/glog",
|
||||
"//vendor:github.com/prometheus/client_golang/prometheus",
|
||||
],
|
||||
|
@ -26,8 +26,8 @@ go_test(
|
|||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/auth/authenticator:go_default_library",
|
||||
"//pkg/auth/user:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -23,8 +23,8 @@ import (
|
|||
"github.com/golang/glog"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/auth/authenticator"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -45,12 +45,12 @@ func init() {
|
|||
// stores any such user found onto the provided context for the request. If authentication fails or returns an error
|
||||
// the failed handler is used. On success, "Authorization" header is removed from the request and handler
|
||||
// is invoked to serve the request.
|
||||
func WithAuthentication(handler http.Handler, mapper api.RequestContextMapper, auth authenticator.Request, failed http.Handler) http.Handler {
|
||||
func WithAuthentication(handler http.Handler, mapper genericapirequest.RequestContextMapper, auth authenticator.Request, failed http.Handler) http.Handler {
|
||||
if auth == nil {
|
||||
glog.Warningf("Authentication is disabled")
|
||||
return handler
|
||||
}
|
||||
return api.WithRequestContext(
|
||||
return genericapirequest.WithRequestContext(
|
||||
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
user, ok, err := auth.AuthenticateRequest(req)
|
||||
if err != nil || !ok {
|
||||
|
@ -65,7 +65,7 @@ func WithAuthentication(handler http.Handler, mapper api.RequestContextMapper, a
|
|||
req.Header.Del("Authorization")
|
||||
|
||||
if ctx, ok := mapper.Get(req); ok {
|
||||
mapper.Update(req, api.WithUser(ctx, user))
|
||||
mapper.Update(req, genericapirequest.WithUser(ctx, user))
|
||||
}
|
||||
|
||||
authenticatedUserCounter.WithLabelValues(compressUsername(user.GetName())).Inc()
|
||||
|
|
|
@ -22,21 +22,21 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/auth/authenticator"
|
||||
"k8s.io/kubernetes/pkg/auth/user"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
func TestAuthenticateRequest(t *testing.T) {
|
||||
success := make(chan struct{})
|
||||
contextMapper := api.NewRequestContextMapper()
|
||||
contextMapper := genericapirequest.NewRequestContextMapper()
|
||||
auth := WithAuthentication(
|
||||
http.HandlerFunc(func(_ http.ResponseWriter, req *http.Request) {
|
||||
ctx, ok := contextMapper.Get(req)
|
||||
if ctx == nil || !ok {
|
||||
t.Errorf("no context stored on contextMapper: %#v", contextMapper)
|
||||
}
|
||||
user, ok := api.UserFrom(ctx)
|
||||
user, ok := genericapirequest.UserFrom(ctx)
|
||||
if user == nil || !ok {
|
||||
t.Errorf("no user stored in context: %#v", ctx)
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func TestAuthenticateRequest(t *testing.T) {
|
|||
auth.ServeHTTP(httptest.NewRecorder(), &http.Request{Header: map[string][]string{"Authorization": {"Something"}}})
|
||||
|
||||
<-success
|
||||
empty, err := api.IsEmpty(contextMapper)
|
||||
empty, err := genericapirequest.IsEmpty(contextMapper)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func TestAuthenticateRequest(t *testing.T) {
|
|||
|
||||
func TestAuthenticateRequestFailed(t *testing.T) {
|
||||
failed := make(chan struct{})
|
||||
contextMapper := api.NewRequestContextMapper()
|
||||
contextMapper := genericapirequest.NewRequestContextMapper()
|
||||
auth := WithAuthentication(
|
||||
http.HandlerFunc(func(_ http.ResponseWriter, req *http.Request) {
|
||||
t.Errorf("unexpected call to handler")
|
||||
|
@ -88,7 +88,7 @@ func TestAuthenticateRequestFailed(t *testing.T) {
|
|||
auth.ServeHTTP(httptest.NewRecorder(), &http.Request{})
|
||||
|
||||
<-failed
|
||||
empty, err := api.IsEmpty(contextMapper)
|
||||
empty, err := genericapirequest.IsEmpty(contextMapper)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func TestAuthenticateRequestFailed(t *testing.T) {
|
|||
|
||||
func TestAuthenticateRequestError(t *testing.T) {
|
||||
failed := make(chan struct{})
|
||||
contextMapper := api.NewRequestContextMapper()
|
||||
contextMapper := genericapirequest.NewRequestContextMapper()
|
||||
auth := WithAuthentication(
|
||||
http.HandlerFunc(func(_ http.ResponseWriter, req *http.Request) {
|
||||
t.Errorf("unexpected call to handler")
|
||||
|
@ -116,7 +116,7 @@ func TestAuthenticateRequestError(t *testing.T) {
|
|||
auth.ServeHTTP(httptest.NewRecorder(), &http.Request{})
|
||||
|
||||
<-failed
|
||||
empty, err := api.IsEmpty(contextMapper)
|
||||
empty, err := genericapirequest.IsEmpty(contextMapper)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ go_library(
|
|||
"//pkg/client/retry:go_default_library",
|
||||
"//pkg/controller/informers:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/core/secret:go_default_library",
|
||||
"//pkg/registry/core/secret/etcd:go_default_library",
|
||||
"//pkg/registry/core/serviceaccount:go_default_library",
|
||||
|
|
|
@ -17,10 +17,10 @@ limitations under the License.
|
|||
package serviceaccount
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/registry/core/secret"
|
||||
secretetcd "k8s.io/kubernetes/pkg/registry/core/secret/etcd"
|
||||
serviceaccountregistry "k8s.io/kubernetes/pkg/registry/core/serviceaccount"
|
||||
|
@ -61,7 +61,7 @@ func NewGetterFromRegistries(serviceAccounts serviceaccountregistry.Registry, se
|
|||
return ®istryGetter{serviceAccounts, secrets}
|
||||
}
|
||||
func (r *registryGetter) GetServiceAccount(namespace, name string) (*v1.ServiceAccount, error) {
|
||||
ctx := api.WithNamespace(api.NewContext(), namespace)
|
||||
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), namespace)
|
||||
internalServiceAccount, err := r.serviceAccounts.GetServiceAccount(ctx, name, &metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -72,7 +72,7 @@ func (r *registryGetter) GetServiceAccount(namespace, name string) (*v1.ServiceA
|
|||
|
||||
}
|
||||
func (r *registryGetter) GetSecret(namespace, name string) (*v1.Secret, error) {
|
||||
ctx := api.WithNamespace(api.NewContext(), namespace)
|
||||
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), namespace)
|
||||
internalSecret, err := r.secrets.GetSecret(ctx, name, &metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -107,6 +107,7 @@ go_test(
|
|||
"//pkg/auth/authorizer:go_default_library",
|
||||
"//pkg/auth/user:go_default_library",
|
||||
"//pkg/generated/openapi:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/genericapiserver/options:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
|
|
|
@ -31,6 +31,7 @@ go_library(
|
|||
"//pkg/genericapiserver/api/handlers/negotiation:go_default_library",
|
||||
"//pkg/genericapiserver/api/handlers/responsewriters:go_default_library",
|
||||
"//pkg/genericapiserver/api/metrics:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
"//pkg/util/errors:go_default_library",
|
||||
|
|
|
@ -85,7 +85,7 @@ var accessor = meta.NewAccessor()
|
|||
var selfLinker runtime.SelfLinker = accessor
|
||||
var mapper, namespaceMapper meta.RESTMapper // The mappers with namespace and with legacy namespace scopes.
|
||||
var admissionControl admission.Interface
|
||||
var requestContextMapper api.RequestContextMapper
|
||||
var requestContextMapper request.RequestContextMapper
|
||||
|
||||
func interfacesFor(version schema.GroupVersion) (*meta.VersionInterfaces, error) {
|
||||
switch version {
|
||||
|
@ -209,7 +209,7 @@ func init() {
|
|||
mapper = nsMapper
|
||||
namespaceMapper = nsMapper
|
||||
admissionControl = admit.NewAlwaysAdmit()
|
||||
requestContextMapper = api.NewRequestContextMapper()
|
||||
requestContextMapper = request.NewRequestContextMapper()
|
||||
|
||||
api.Scheme.AddFieldLabelConversionFunc(grouplessGroupVersion.String(), "Simple",
|
||||
func(label, value string) (string, string, error) {
|
||||
|
@ -380,7 +380,7 @@ type SimpleRESTStorage struct {
|
|||
injectedFunction func(obj runtime.Object) (returnObj runtime.Object, err error)
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Export(ctx api.Context, name string, opts metav1.ExportOptions) (runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Export(ctx request.Context, name string, opts metav1.ExportOptions) (runtime.Object, error) {
|
||||
obj, err := storage.Get(ctx, name, &metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -395,7 +395,7 @@ func (storage *SimpleRESTStorage) Export(ctx api.Context, name string, opts meta
|
|||
return obj, storage.errors["export"]
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) List(ctx api.Context, options *api.ListOptions) (runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) List(ctx request.Context, options *api.ListOptions) (runtime.Object, error) {
|
||||
storage.checkContext(ctx)
|
||||
result := &genericapitesting.SimpleList{
|
||||
Items: storage.list,
|
||||
|
@ -442,7 +442,7 @@ func (h *OutputConnect) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
w.Write([]byte(h.response))
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Get(ctx api.Context, id string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Get(ctx request.Context, id string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
storage.checkContext(ctx)
|
||||
if id == "binary" {
|
||||
return storage.stream, storage.errors["get"]
|
||||
|
@ -454,11 +454,11 @@ func (storage *SimpleRESTStorage) Get(ctx api.Context, id string, options *metav
|
|||
return copied, storage.errors["get"]
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) checkContext(ctx api.Context) {
|
||||
storage.actualNamespace, storage.namespacePresent = api.NamespaceFrom(ctx)
|
||||
func (storage *SimpleRESTStorage) checkContext(ctx request.Context) {
|
||||
storage.actualNamespace, storage.namespacePresent = request.NamespaceFrom(ctx)
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Delete(ctx api.Context, id string, options *api.DeleteOptions) (runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Delete(ctx request.Context, id string, options *api.DeleteOptions) (runtime.Object, error) {
|
||||
storage.checkContext(ctx)
|
||||
storage.deleted = id
|
||||
storage.deleteOptions = options
|
||||
|
@ -481,7 +481,7 @@ func (storage *SimpleRESTStorage) NewList() runtime.Object {
|
|||
return &genericapitesting.SimpleList{}
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Create(ctx request.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
storage.checkContext(ctx)
|
||||
storage.created = obj.(*genericapitesting.Simple)
|
||||
if err := storage.errors["create"]; err != nil {
|
||||
|
@ -494,7 +494,7 @@ func (storage *SimpleRESTStorage) Create(ctx api.Context, obj runtime.Object) (r
|
|||
return obj, err
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Update(ctx api.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
func (storage *SimpleRESTStorage) Update(ctx request.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
storage.checkContext(ctx)
|
||||
obj, err := objInfo.UpdatedObject(ctx, &storage.item)
|
||||
if err != nil {
|
||||
|
@ -511,7 +511,7 @@ func (storage *SimpleRESTStorage) Update(ctx api.Context, name string, objInfo r
|
|||
}
|
||||
|
||||
// Implement ResourceWatcher.
|
||||
func (storage *SimpleRESTStorage) Watch(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
func (storage *SimpleRESTStorage) Watch(ctx request.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
storage.lock.Lock()
|
||||
defer storage.lock.Unlock()
|
||||
storage.checkContext(ctx)
|
||||
|
@ -527,7 +527,7 @@ func (storage *SimpleRESTStorage) Watch(ctx api.Context, options *api.ListOption
|
|||
if options != nil {
|
||||
storage.requestedResourceVersion = options.ResourceVersion
|
||||
}
|
||||
storage.requestedResourceNamespace = api.NamespaceValue(ctx)
|
||||
storage.requestedResourceNamespace = request.NamespaceValue(ctx)
|
||||
if err := storage.errors["watch"]; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -545,10 +545,10 @@ func (storage *SimpleRESTStorage) Watcher() *watch.FakeWatcher {
|
|||
var _ = rest.Redirector(&SimpleRESTStorage{})
|
||||
|
||||
// Implement Redirector.
|
||||
func (storage *SimpleRESTStorage) ResourceLocation(ctx api.Context, id string) (*url.URL, http.RoundTripper, error) {
|
||||
func (storage *SimpleRESTStorage) ResourceLocation(ctx request.Context, id string) (*url.URL, http.RoundTripper, error) {
|
||||
storage.checkContext(ctx)
|
||||
// validate that the namespace context on the request matches the expected input
|
||||
storage.requestedResourceNamespace = api.NamespaceValue(ctx)
|
||||
storage.requestedResourceNamespace = request.NamespaceValue(ctx)
|
||||
if storage.expectedResourceNamespace != storage.requestedResourceNamespace {
|
||||
return nil, nil, fmt.Errorf("Expected request namespace %s, but got namespace %s", storage.expectedResourceNamespace, storage.requestedResourceNamespace)
|
||||
}
|
||||
|
@ -580,7 +580,7 @@ func (s *ConnecterRESTStorage) New() runtime.Object {
|
|||
return &genericapitesting.Simple{}
|
||||
}
|
||||
|
||||
func (s *ConnecterRESTStorage) Connect(ctx api.Context, id string, options runtime.Object, responder rest.Responder) (http.Handler, error) {
|
||||
func (s *ConnecterRESTStorage) Connect(ctx request.Context, id string, options runtime.Object, responder rest.Responder) (http.Handler, error) {
|
||||
s.receivedConnectOptions = options
|
||||
s.receivedID = id
|
||||
s.receivedResponder = responder
|
||||
|
@ -605,7 +605,7 @@ type LegacyRESTStorage struct {
|
|||
*SimpleRESTStorage
|
||||
}
|
||||
|
||||
func (storage LegacyRESTStorage) Delete(ctx api.Context, id string) (runtime.Object, error) {
|
||||
func (storage LegacyRESTStorage) Delete(ctx request.Context, id string) (runtime.Object, error) {
|
||||
return storage.SimpleRESTStorage.Delete(ctx, id, nil)
|
||||
}
|
||||
|
||||
|
@ -630,7 +630,7 @@ type GetWithOptionsRESTStorage struct {
|
|||
takesPath string
|
||||
}
|
||||
|
||||
func (r *GetWithOptionsRESTStorage) Get(ctx api.Context, name string, options runtime.Object) (runtime.Object, error) {
|
||||
func (r *GetWithOptionsRESTStorage) Get(ctx request.Context, name string, options runtime.Object) (runtime.Object, error) {
|
||||
if _, ok := options.(*genericapitesting.SimpleGetOptions); !ok {
|
||||
return nil, fmt.Errorf("Unexpected options object: %#v", options)
|
||||
}
|
||||
|
@ -652,7 +652,7 @@ type NamedCreaterRESTStorage struct {
|
|||
createdName string
|
||||
}
|
||||
|
||||
func (storage *NamedCreaterRESTStorage) Create(ctx api.Context, name string, obj runtime.Object) (runtime.Object, error) {
|
||||
func (storage *NamedCreaterRESTStorage) Create(ctx request.Context, name string, obj runtime.Object) (runtime.Object, error) {
|
||||
storage.checkContext(ctx)
|
||||
storage.created = obj.(*genericapitesting.Simple)
|
||||
storage.createdName = name
|
||||
|
@ -679,7 +679,7 @@ func (storage *SimpleTypedStorage) New() runtime.Object {
|
|||
return storage.baseType
|
||||
}
|
||||
|
||||
func (storage *SimpleTypedStorage) Get(ctx api.Context, id string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
func (storage *SimpleTypedStorage) Get(ctx request.Context, id string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
storage.checkContext(ctx)
|
||||
copied, err := api.Scheme.Copy(storage.item)
|
||||
if err != nil {
|
||||
|
@ -688,8 +688,8 @@ func (storage *SimpleTypedStorage) Get(ctx api.Context, id string, options *meta
|
|||
return copied, storage.errors["get"]
|
||||
}
|
||||
|
||||
func (storage *SimpleTypedStorage) checkContext(ctx api.Context) {
|
||||
storage.actualNamespace, storage.namespacePresent = api.NamespaceFrom(ctx)
|
||||
func (storage *SimpleTypedStorage) checkContext(ctx request.Context) {
|
||||
storage.actualNamespace, storage.namespacePresent = request.NamespaceFrom(ctx)
|
||||
}
|
||||
|
||||
func extractBody(response *http.Response, object runtime.Object) (string, error) {
|
||||
|
@ -3255,7 +3255,7 @@ func (storage *SimpleXGSubresourceRESTStorage) New() runtime.Object {
|
|||
return &SimpleXGSubresource{}
|
||||
}
|
||||
|
||||
func (storage *SimpleXGSubresourceRESTStorage) Get(ctx api.Context, id string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
func (storage *SimpleXGSubresourceRESTStorage) Get(ctx request.Context, id string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
copied, err := api.Scheme.Copy(&storage.item)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -3400,7 +3400,7 @@ func BenchmarkUpdateProtobuf(b *testing.B) {
|
|||
|
||||
func newTestServer(handler http.Handler) *httptest.Server {
|
||||
handler = genericapifilters.WithRequestInfo(handler, newTestRequestInfoResolver(), requestContextMapper)
|
||||
handler = api.WithRequestContext(handler, requestContextMapper)
|
||||
handler = request.WithRequestContext(handler, requestContextMapper)
|
||||
return httptest.NewServer(handler)
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ go_test(
|
|||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/apis/authentication:go_default_library",
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/auth/authorizer:go_default_library",
|
||||
|
|
|
@ -29,9 +29,9 @@ import (
|
|||
"github.com/golang/glog"
|
||||
"github.com/pborman/uuid"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
authenticationapi "k8s.io/kubernetes/pkg/apis/authentication"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers/responsewriters"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
utilnet "k8s.io/kubernetes/pkg/util/net"
|
||||
)
|
||||
|
||||
|
@ -89,7 +89,7 @@ var _ http.Hijacker = &fancyResponseWriterDelegator{}
|
|||
// 2. the response line containing:
|
||||
// - the unique id from 1
|
||||
// - response code
|
||||
func WithAudit(handler http.Handler, requestContextMapper api.RequestContextMapper, out io.Writer) http.Handler {
|
||||
func WithAudit(handler http.Handler, requestContextMapper request.RequestContextMapper, out io.Writer) http.Handler {
|
||||
if out == nil {
|
||||
return handler
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/auth/user"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
@ -105,10 +104,10 @@ type fakeRequestContextMapper struct {
|
|||
user *user.DefaultInfo
|
||||
}
|
||||
|
||||
func (m *fakeRequestContextMapper) Get(req *http.Request) (api.Context, bool) {
|
||||
ctx := api.NewContext()
|
||||
func (m *fakeRequestContextMapper) Get(req *http.Request) (request.Context, bool) {
|
||||
ctx := request.NewContext()
|
||||
if m.user != nil {
|
||||
ctx = api.WithUser(ctx, m.user)
|
||||
ctx = request.WithUser(ctx, m.user)
|
||||
}
|
||||
|
||||
resolver := newTestRequestInfoResolver()
|
||||
|
@ -120,7 +119,7 @@ func (m *fakeRequestContextMapper) Get(req *http.Request) (api.Context, bool) {
|
|||
return ctx, true
|
||||
}
|
||||
|
||||
func (*fakeRequestContextMapper) Update(req *http.Request, context api.Context) error {
|
||||
func (*fakeRequestContextMapper) Update(req *http.Request, context request.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -22,14 +22,13 @@ import (
|
|||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/auth/authorizer"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers/responsewriters"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
// WithAuthorizationCheck passes all authorized requests on to handler, and returns a forbidden error otherwise.
|
||||
func WithAuthorization(handler http.Handler, requestContextMapper api.RequestContextMapper, a authorizer.Authorizer) http.Handler {
|
||||
func WithAuthorization(handler http.Handler, requestContextMapper request.RequestContextMapper, a authorizer.Authorizer) http.Handler {
|
||||
if a == nil {
|
||||
glog.Warningf("Authorization is disabled")
|
||||
return handler
|
||||
|
@ -61,10 +60,10 @@ func WithAuthorization(handler http.Handler, requestContextMapper api.RequestCon
|
|||
})
|
||||
}
|
||||
|
||||
func GetAuthorizerAttributes(ctx api.Context) (authorizer.Attributes, error) {
|
||||
func GetAuthorizerAttributes(ctx request.Context) (authorizer.Attributes, error) {
|
||||
attribs := authorizer.AttributesRecord{}
|
||||
|
||||
user, ok := api.UserFrom(ctx)
|
||||
user, ok := request.UserFrom(ctx)
|
||||
if ok {
|
||||
attribs.User = user
|
||||
}
|
||||
|
|
|
@ -23,14 +23,14 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
"k8s.io/kubernetes/pkg/auth/authorizer"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers/responsewriters"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
func TestGetAuthorizerAttributes(t *testing.T) {
|
||||
mapper := api.NewRequestContextMapper()
|
||||
mapper := request.NewRequestContextMapper()
|
||||
|
||||
testcases := map[string]struct {
|
||||
Verb string
|
||||
|
@ -117,7 +117,7 @@ func TestGetAuthorizerAttributes(t *testing.T) {
|
|||
attribs, err = GetAuthorizerAttributes(ctx)
|
||||
})
|
||||
handler = WithRequestInfo(handler, newTestRequestInfoResolver(), mapper)
|
||||
handler = api.WithRequestContext(handler, mapper)
|
||||
handler = request.WithRequestContext(handler, mapper)
|
||||
handler.ServeHTTP(httptest.NewRecorder(), req)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -29,12 +29,13 @@ import (
|
|||
"k8s.io/kubernetes/pkg/auth/authorizer"
|
||||
"k8s.io/kubernetes/pkg/auth/user"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers/responsewriters"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/httplog"
|
||||
"k8s.io/kubernetes/pkg/serviceaccount"
|
||||
)
|
||||
|
||||
// WithImpersonation is a filter that will inspect and check requests that attempt to change the user.Info for their requests
|
||||
func WithImpersonation(handler http.Handler, requestContextMapper api.RequestContextMapper, a authorizer.Authorizer) http.Handler {
|
||||
func WithImpersonation(handler http.Handler, requestContextMapper request.RequestContextMapper, a authorizer.Authorizer) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
impersonationRequests, err := buildImpersonationRequests(req.Header)
|
||||
if err != nil {
|
||||
|
@ -52,7 +53,7 @@ func WithImpersonation(handler http.Handler, requestContextMapper api.RequestCon
|
|||
responsewriters.InternalError(w, req, errors.New("no context found for request"))
|
||||
return
|
||||
}
|
||||
requestor, exists := api.UserFrom(ctx)
|
||||
requestor, exists := request.UserFrom(ctx)
|
||||
if !exists {
|
||||
responsewriters.InternalError(w, req, errors.New("no user found for request"))
|
||||
return
|
||||
|
@ -120,9 +121,9 @@ func WithImpersonation(handler http.Handler, requestContextMapper api.RequestCon
|
|||
Groups: groups,
|
||||
Extra: userExtra,
|
||||
}
|
||||
requestContextMapper.Update(req, api.WithUser(ctx, newUser))
|
||||
requestContextMapper.Update(req, request.WithUser(ctx, newUser))
|
||||
|
||||
oldUser, _ := api.UserFrom(ctx)
|
||||
oldUser, _ := request.UserFrom(ctx)
|
||||
httplog.LogOf(req, w).Addf("%v is acting as %v", oldUser, newUser)
|
||||
|
||||
// clear all the impersonation headers from the request
|
||||
|
|
|
@ -24,10 +24,10 @@ import (
|
|||
"sync"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
authenticationapi "k8s.io/kubernetes/pkg/apis/authentication"
|
||||
"k8s.io/kubernetes/pkg/auth/authorizer"
|
||||
"k8s.io/kubernetes/pkg/auth/user"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
type impersonateAuthorizer struct{}
|
||||
|
@ -264,14 +264,14 @@ func TestImpersonationFilter(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
requestContextMapper := api.NewRequestContextMapper()
|
||||
var ctx api.Context
|
||||
requestContextMapper := request.NewRequestContextMapper()
|
||||
var ctx request.Context
|
||||
var actualUser user.Info
|
||||
var lock sync.Mutex
|
||||
|
||||
doNothingHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
currentCtx, _ := requestContextMapper.Get(req)
|
||||
user, exists := api.UserFrom(currentCtx)
|
||||
user, exists := request.UserFrom(currentCtx)
|
||||
if !exists {
|
||||
actualUser = nil
|
||||
return
|
||||
|
@ -291,7 +291,7 @@ func TestImpersonationFilter(t *testing.T) {
|
|||
requestContextMapper.Update(req, ctx)
|
||||
currentCtx, _ := requestContextMapper.Get(req)
|
||||
|
||||
user, exists := api.UserFrom(currentCtx)
|
||||
user, exists := request.UserFrom(currentCtx)
|
||||
if !exists {
|
||||
actualUser = nil
|
||||
return
|
||||
|
@ -302,7 +302,7 @@ func TestImpersonationFilter(t *testing.T) {
|
|||
delegate.ServeHTTP(w, req)
|
||||
})
|
||||
}(WithImpersonation(doNothingHandler, requestContextMapper, impersonateAuthorizer{}))
|
||||
handler = api.WithRequestContext(handler, requestContextMapper)
|
||||
handler = request.WithRequestContext(handler, requestContextMapper)
|
||||
|
||||
server := httptest.NewServer(handler)
|
||||
defer server.Close()
|
||||
|
@ -311,7 +311,7 @@ func TestImpersonationFilter(t *testing.T) {
|
|||
func() {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
ctx = api.WithUser(api.NewContext(), tc.user)
|
||||
ctx = request.WithUser(request.NewContext(), tc.user)
|
||||
}()
|
||||
|
||||
req, err := http.NewRequest("GET", server.URL, nil)
|
||||
|
|
|
@ -21,13 +21,12 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers/responsewriters"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
// WithRequestInfo attaches a RequestInfo to the context.
|
||||
func WithRequestInfo(handler http.Handler, resolver *request.RequestInfoFactory, requestContextMapper api.RequestContextMapper) http.Handler {
|
||||
func WithRequestInfo(handler http.Handler, resolver *request.RequestInfoFactory, requestContextMapper request.RequestContextMapper) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
ctx, ok := requestContextMapper.Get(req)
|
||||
if !ok {
|
||||
|
|
|
@ -24,12 +24,12 @@ import (
|
|||
"github.com/emicklei/go-restful"
|
||||
|
||||
"k8s.io/kubernetes/pkg/admission"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
apierrors "k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
utilerrors "k8s.io/kubernetes/pkg/util/errors"
|
||||
|
@ -68,7 +68,7 @@ type APIGroupVersion struct {
|
|||
Linker runtime.SelfLinker
|
||||
|
||||
Admit admission.Interface
|
||||
Context api.RequestContextMapper
|
||||
Context request.RequestContextMapper
|
||||
|
||||
MinRequestTimeout time.Duration
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ go_test(
|
|||
"//pkg/api/testapi:go_default_library",
|
||||
"//pkg/api/v1:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
"//pkg/types:go_default_library",
|
||||
|
|
|
@ -49,7 +49,7 @@ type ProxyHandler struct {
|
|||
Prefix string
|
||||
Storage map[string]rest.Storage
|
||||
Serializer runtime.NegotiatedSerializer
|
||||
Mapper api.RequestContextMapper
|
||||
Mapper request.RequestContextMapper
|
||||
}
|
||||
|
||||
func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
|
@ -87,7 +87,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
verb = requestInfo.Verb
|
||||
namespace, resource, parts := requestInfo.Namespace, requestInfo.Resource, requestInfo.Parts
|
||||
|
||||
ctx = api.WithNamespace(ctx, namespace)
|
||||
ctx = request.WithNamespace(ctx, namespace)
|
||||
if len(parts) < 2 {
|
||||
responsewriters.NotFound(w, req)
|
||||
httpCode = http.StatusNotFound
|
||||
|
|
|
@ -8,6 +8,19 @@ load(
|
|||
"go_test",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["status_test.go"],
|
||||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
|
@ -30,16 +43,3 @@ go_library(
|
|||
"//pkg/util/wsstream:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["status_test.go"],
|
||||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -36,6 +36,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers/negotiation"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers/responsewriters"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
|
@ -48,7 +49,7 @@ import (
|
|||
)
|
||||
|
||||
// ContextFunc returns a Context given a request - a context must be returned
|
||||
type ContextFunc func(req *restful.Request) api.Context
|
||||
type ContextFunc func(req *restful.Request) request.Context
|
||||
|
||||
// ScopeNamer handles accessing names from requests and objects
|
||||
type ScopeNamer interface {
|
||||
|
@ -94,7 +95,7 @@ func (scope *RequestScope) err(err error, w http.ResponseWriter, req *http.Reque
|
|||
|
||||
// getterFunc performs a get request with the given context and object name. The request
|
||||
// may be used to deserialize an options object to pass to the getter.
|
||||
type getterFunc func(ctx api.Context, name string, req *restful.Request) (runtime.Object, error)
|
||||
type getterFunc func(ctx request.Context, name string, req *restful.Request) (runtime.Object, error)
|
||||
|
||||
// maxRetryWhenPatchConflicts is the maximum number of conflicts retry during a patch operation before returning failure
|
||||
const maxRetryWhenPatchConflicts = 5
|
||||
|
@ -110,7 +111,7 @@ func getResourceHandler(scope RequestScope, getter getterFunc) restful.RouteFunc
|
|||
return
|
||||
}
|
||||
ctx := scope.ContextFunc(req)
|
||||
ctx = api.WithNamespace(ctx, namespace)
|
||||
ctx = request.WithNamespace(ctx, namespace)
|
||||
|
||||
result, err := getter(ctx, name, req)
|
||||
if err != nil {
|
||||
|
@ -128,7 +129,7 @@ func getResourceHandler(scope RequestScope, getter getterFunc) restful.RouteFunc
|
|||
// GetResource returns a function that handles retrieving a single resource from a rest.Storage object.
|
||||
func GetResource(r rest.Getter, e rest.Exporter, scope RequestScope) restful.RouteFunction {
|
||||
return getResourceHandler(scope,
|
||||
func(ctx api.Context, name string, req *restful.Request) (runtime.Object, error) {
|
||||
func(ctx request.Context, name string, req *restful.Request) (runtime.Object, error) {
|
||||
// For performance tracking purposes.
|
||||
trace := util.NewTrace("Get " + req.Request.URL.Path)
|
||||
defer trace.LogIfLong(500 * time.Millisecond)
|
||||
|
@ -158,7 +159,7 @@ func GetResource(r rest.Getter, e rest.Exporter, scope RequestScope) restful.Rou
|
|||
// GetResourceWithOptions returns a function that handles retrieving a single resource from a rest.Storage object.
|
||||
func GetResourceWithOptions(r rest.GetterWithOptions, scope RequestScope) restful.RouteFunction {
|
||||
return getResourceHandler(scope,
|
||||
func(ctx api.Context, name string, req *restful.Request) (runtime.Object, error) {
|
||||
func(ctx request.Context, name string, req *restful.Request) (runtime.Object, error) {
|
||||
opts, subpath, subpathKey := r.NewGetOptions()
|
||||
if err := getRequestOptions(req, scope, opts, subpath, subpathKey); err != nil {
|
||||
return nil, err
|
||||
|
@ -194,7 +195,7 @@ func ConnectResource(connecter rest.Connecter, scope RequestScope, admit admissi
|
|||
return
|
||||
}
|
||||
ctx := scope.ContextFunc(req)
|
||||
ctx = api.WithNamespace(ctx, namespace)
|
||||
ctx = request.WithNamespace(ctx, namespace)
|
||||
opts, subpath, subpathKey := connecter.NewConnectOptions()
|
||||
if err := getRequestOptions(req, scope, opts, subpath, subpathKey); err != nil {
|
||||
scope.err(err, res.ResponseWriter, req.Request)
|
||||
|
@ -206,7 +207,7 @@ func ConnectResource(connecter rest.Connecter, scope RequestScope, admit admissi
|
|||
Options: opts,
|
||||
ResourcePath: restPath,
|
||||
}
|
||||
userInfo, _ := api.UserFrom(ctx)
|
||||
userInfo, _ := request.UserFrom(ctx)
|
||||
|
||||
err = admit.Admit(admission.NewAttributesRecord(connectRequest, nil, scope.Kind, namespace, name, scope.Resource, scope.Subresource, admission.Connect, userInfo))
|
||||
if err != nil {
|
||||
|
@ -261,7 +262,7 @@ func ListResource(r rest.Lister, rw rest.Watcher, scope RequestScope, forceWatch
|
|||
}
|
||||
|
||||
ctx := scope.ContextFunc(req)
|
||||
ctx = api.WithNamespace(ctx, namespace)
|
||||
ctx = request.WithNamespace(ctx, namespace)
|
||||
|
||||
opts := api.ListOptions{}
|
||||
if err := scope.ParameterCodec.DecodeParameters(req.Request.URL.Query(), scope.Kind.GroupVersion(), &opts); err != nil {
|
||||
|
@ -364,7 +365,7 @@ func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.Object
|
|||
}
|
||||
|
||||
ctx := scope.ContextFunc(req)
|
||||
ctx = api.WithNamespace(ctx, namespace)
|
||||
ctx = request.WithNamespace(ctx, namespace)
|
||||
|
||||
gv := scope.Kind.GroupVersion()
|
||||
s, err := negotiation.NegotiateInputSerializer(req.Request, scope.Serializer)
|
||||
|
@ -397,7 +398,7 @@ func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.Object
|
|||
trace.Step("Conversion done")
|
||||
|
||||
if admit != nil && admit.Handles(admission.Create) {
|
||||
userInfo, _ := api.UserFrom(ctx)
|
||||
userInfo, _ := request.UserFrom(ctx)
|
||||
|
||||
err = admit.Admit(admission.NewAttributesRecord(obj, nil, scope.Kind, namespace, name, scope.Resource, scope.Subresource, admission.Create, userInfo))
|
||||
if err != nil {
|
||||
|
@ -444,7 +445,7 @@ type namedCreaterAdapter struct {
|
|||
rest.Creater
|
||||
}
|
||||
|
||||
func (c *namedCreaterAdapter) Create(ctx api.Context, name string, obj runtime.Object) (runtime.Object, error) {
|
||||
func (c *namedCreaterAdapter) Create(ctx request.Context, name string, obj runtime.Object) (runtime.Object, error) {
|
||||
return c.Creater.Create(ctx, obj)
|
||||
}
|
||||
|
||||
|
@ -466,7 +467,7 @@ func PatchResource(r rest.Patcher, scope RequestScope, typer runtime.ObjectTyper
|
|||
}
|
||||
|
||||
ctx := scope.ContextFunc(req)
|
||||
ctx = api.WithNamespace(ctx, namespace)
|
||||
ctx = request.WithNamespace(ctx, namespace)
|
||||
|
||||
versionedObj, err := converter.ConvertToVersion(r.New(), scope.Kind.GroupVersion())
|
||||
if err != nil {
|
||||
|
@ -501,7 +502,7 @@ func PatchResource(r rest.Patcher, scope RequestScope, typer runtime.ObjectTyper
|
|||
|
||||
updateAdmit := func(updatedObject runtime.Object, currentObject runtime.Object) error {
|
||||
if admit != nil && admit.Handles(admission.Update) {
|
||||
userInfo, _ := api.UserFrom(ctx)
|
||||
userInfo, _ := request.UserFrom(ctx)
|
||||
return admit.Admit(admission.NewAttributesRecord(updatedObject, currentObject, scope.Kind, namespace, name, scope.Resource, scope.Subresource, admission.Update, userInfo))
|
||||
}
|
||||
|
||||
|
@ -528,7 +529,7 @@ type updateAdmissionFunc func(updatedObject runtime.Object, currentObject runtim
|
|||
|
||||
// patchResource divides PatchResource for easier unit testing
|
||||
func patchResource(
|
||||
ctx api.Context,
|
||||
ctx request.Context,
|
||||
admit updateAdmissionFunc,
|
||||
timeout time.Duration,
|
||||
versionedObj runtime.Object,
|
||||
|
@ -542,7 +543,7 @@ func patchResource(
|
|||
codec runtime.Codec,
|
||||
) (runtime.Object, error) {
|
||||
|
||||
namespace := api.NamespaceValue(ctx)
|
||||
namespace := request.NamespaceValue(ctx)
|
||||
|
||||
var (
|
||||
originalObjJS []byte
|
||||
|
@ -552,7 +553,7 @@ func patchResource(
|
|||
|
||||
// applyPatch is called every time GuaranteedUpdate asks for the updated object,
|
||||
// and is given the currently persisted object as input.
|
||||
applyPatch := func(_ api.Context, _, currentObject runtime.Object) (runtime.Object, error) {
|
||||
applyPatch := func(_ request.Context, _, currentObject runtime.Object) (runtime.Object, error) {
|
||||
// Make sure we actually have a persisted currentObject
|
||||
if hasUID, err := hasUID(currentObject); err != nil {
|
||||
return nil, err
|
||||
|
@ -643,7 +644,7 @@ func patchResource(
|
|||
|
||||
// applyAdmission is called every time GuaranteedUpdate asks for the updated object,
|
||||
// and is given the currently persisted object and the patched object as input.
|
||||
applyAdmission := func(ctx api.Context, patchedObject runtime.Object, currentObject runtime.Object) (runtime.Object, error) {
|
||||
applyAdmission := func(ctx request.Context, patchedObject runtime.Object, currentObject runtime.Object) (runtime.Object, error) {
|
||||
return patchedObject, admit(patchedObject, currentObject)
|
||||
}
|
||||
|
||||
|
@ -677,7 +678,7 @@ func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectType
|
|||
return
|
||||
}
|
||||
ctx := scope.ContextFunc(req)
|
||||
ctx = api.WithNamespace(ctx, namespace)
|
||||
ctx = request.WithNamespace(ctx, namespace)
|
||||
|
||||
body, err := readBody(req.Request)
|
||||
if err != nil {
|
||||
|
@ -713,8 +714,8 @@ func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectType
|
|||
|
||||
var transformers []rest.TransformFunc
|
||||
if admit != nil && admit.Handles(admission.Update) {
|
||||
transformers = append(transformers, func(ctx api.Context, newObj, oldObj runtime.Object) (runtime.Object, error) {
|
||||
userInfo, _ := api.UserFrom(ctx)
|
||||
transformers = append(transformers, func(ctx request.Context, newObj, oldObj runtime.Object) (runtime.Object, error) {
|
||||
userInfo, _ := request.UserFrom(ctx)
|
||||
return newObj, admit.Admit(admission.NewAttributesRecord(newObj, oldObj, scope.Kind, namespace, name, scope.Resource, scope.Subresource, admission.Update, userInfo))
|
||||
})
|
||||
}
|
||||
|
@ -764,7 +765,7 @@ func DeleteResource(r rest.GracefulDeleter, allowsOptions bool, scope RequestSco
|
|||
return
|
||||
}
|
||||
ctx := scope.ContextFunc(req)
|
||||
ctx = api.WithNamespace(ctx, namespace)
|
||||
ctx = request.WithNamespace(ctx, namespace)
|
||||
|
||||
options := &api.DeleteOptions{}
|
||||
if allowsOptions {
|
||||
|
@ -800,7 +801,7 @@ func DeleteResource(r rest.GracefulDeleter, allowsOptions bool, scope RequestSco
|
|||
}
|
||||
|
||||
if admit != nil && admit.Handles(admission.Delete) {
|
||||
userInfo, _ := api.UserFrom(ctx)
|
||||
userInfo, _ := request.UserFrom(ctx)
|
||||
|
||||
err = admit.Admit(admission.NewAttributesRecord(nil, nil, scope.Kind, namespace, name, scope.Resource, scope.Subresource, admission.Delete, userInfo))
|
||||
if err != nil {
|
||||
|
@ -858,10 +859,10 @@ func DeleteCollection(r rest.CollectionDeleter, checkBody bool, scope RequestSco
|
|||
}
|
||||
|
||||
ctx := scope.ContextFunc(req)
|
||||
ctx = api.WithNamespace(ctx, namespace)
|
||||
ctx = request.WithNamespace(ctx, namespace)
|
||||
|
||||
if admit != nil && admit.Handles(admission.Delete) {
|
||||
userInfo, _ := api.UserFrom(ctx)
|
||||
userInfo, _ := request.UserFrom(ctx)
|
||||
|
||||
err = admit.Admit(admission.NewAttributesRecord(nil, nil, scope.Kind, namespace, "", scope.Resource, scope.Subresource, admission.Delete, userInfo))
|
||||
if err != nil {
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
|
@ -83,7 +84,7 @@ func (p *testPatcher) New() runtime.Object {
|
|||
return &api.Pod{}
|
||||
}
|
||||
|
||||
func (p *testPatcher) Update(ctx api.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
func (p *testPatcher) Update(ctx request.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
currentPod := p.startingPod
|
||||
if p.numUpdates > 0 {
|
||||
currentPod = p.updatePod
|
||||
|
@ -102,7 +103,7 @@ func (p *testPatcher) Update(ctx api.Context, name string, objInfo rest.UpdatedO
|
|||
return inPod, false, nil
|
||||
}
|
||||
|
||||
func (p *testPatcher) Get(ctx api.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
func (p *testPatcher) Get(ctx request.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
p.t.Fatal("Unexpected call to testPatcher.Get")
|
||||
return nil, errors.New("Unexpected call to testPatcher.Get")
|
||||
}
|
||||
|
@ -182,8 +183,8 @@ func (tc *patchTestCase) Run(t *testing.T) {
|
|||
testPatcher.startingPod = tc.startingPod
|
||||
testPatcher.updatePod = tc.updatePod
|
||||
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx = api.WithNamespace(ctx, namespace)
|
||||
ctx := request.NewDefaultContext()
|
||||
ctx = request.WithNamespace(ctx, namespace)
|
||||
|
||||
namer := &testNamer{namespace, name}
|
||||
copier := runtime.ObjectCopier(api.Scheme)
|
||||
|
|
|
@ -37,6 +37,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/handlers/negotiation"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/metrics"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
utilstrings "k8s.io/kubernetes/pkg/util/strings"
|
||||
|
@ -341,14 +342,14 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||
}
|
||||
|
||||
var ctxFn handlers.ContextFunc
|
||||
ctxFn = func(req *restful.Request) api.Context {
|
||||
ctxFn = func(req *restful.Request) request.Context {
|
||||
if context == nil {
|
||||
return api.WithUserAgent(api.NewContext(), req.HeaderParameter("User-Agent"))
|
||||
return request.WithUserAgent(request.NewContext(), req.HeaderParameter("User-Agent"))
|
||||
}
|
||||
if ctx, ok := context.Get(req.Request); ok {
|
||||
return api.WithUserAgent(ctx, req.HeaderParameter("User-Agent"))
|
||||
return request.WithUserAgent(ctx, req.HeaderParameter("User-Agent"))
|
||||
}
|
||||
return api.WithUserAgent(api.NewContext(), req.HeaderParameter("User-Agent"))
|
||||
return request.WithUserAgent(request.NewContext(), req.HeaderParameter("User-Agent"))
|
||||
}
|
||||
|
||||
allowWatchList := isWatcher && isLister // watching on lists is allowed only for kinds that support both watch and list.
|
||||
|
|
|
@ -11,13 +11,18 @@ load(
|
|||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"context.go",
|
||||
"doc.go",
|
||||
"requestcontext.go",
|
||||
"requestinfo.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/auth/user:go_default_library",
|
||||
"//pkg/types:go_default_library",
|
||||
"//pkg/util/sets:go_default_library",
|
||||
"//vendor:github.com/golang/glog",
|
||||
"//vendor:golang.org/x/net/context",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -26,9 +31,17 @@ go_test(
|
|||
srcs = ["requestinfo_test.go"],
|
||||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = ["//pkg/util/sets:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_xtest",
|
||||
srcs = ["context_test.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/testapi:go_default_library",
|
||||
"//pkg/util/sets:go_default_library",
|
||||
"//pkg/auth/user:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/types:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package api
|
||||
package request
|
||||
|
||||
import (
|
||||
stderrs "errors"
|
||||
|
@ -62,6 +62,8 @@ const (
|
|||
|
||||
// userAgentKey is the context key for the request user agent.
|
||||
userAgentKey
|
||||
|
||||
namespaceDefault = "default" // TODO(sttts): solve import cycle when using api.NamespaceDefault
|
||||
)
|
||||
|
||||
// NewContext instantiates a base context object for request flows.
|
||||
|
@ -71,7 +73,7 @@ func NewContext() Context {
|
|||
|
||||
// NewDefaultContext instantiates a base context object for request flows in the default namespace
|
||||
func NewDefaultContext() Context {
|
||||
return WithNamespace(NewContext(), NamespaceDefault)
|
||||
return WithNamespace(NewContext(), namespaceDefault)
|
||||
}
|
||||
|
||||
// WithValue returns a copy of parent in which the value associated with key is val.
|
||||
|
@ -100,20 +102,11 @@ func NamespaceValue(ctx Context) string {
|
|||
return namespace
|
||||
}
|
||||
|
||||
// ValidNamespace returns false if the namespace on the context differs from the resource. If the resource has no namespace, it is set to the value in the context.
|
||||
func ValidNamespace(ctx Context, resource *ObjectMeta) bool {
|
||||
ns, ok := NamespaceFrom(ctx)
|
||||
if len(resource.Namespace) == 0 {
|
||||
resource.Namespace = ns
|
||||
}
|
||||
return ns == resource.Namespace && ok
|
||||
}
|
||||
|
||||
// WithNamespaceDefaultIfNone returns a context whose namespace is the default if and only if the parent context has no namespace value
|
||||
func WithNamespaceDefaultIfNone(parent Context) Context {
|
||||
namespace, ok := NamespaceFrom(parent)
|
||||
if !ok || len(namespace) == 0 {
|
||||
return WithNamespace(parent, NamespaceDefault)
|
||||
return WithNamespace(parent, namespaceDefault)
|
||||
}
|
||||
return parent
|
||||
}
|
|
@ -14,20 +14,21 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package api_test
|
||||
package request_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/auth/user"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
)
|
||||
|
||||
// TestNamespaceContext validates that a namespace can be get/set on a context object
|
||||
func TestNamespaceContext(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
result, ok := api.NamespaceFrom(ctx)
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
result, ok := genericapirequest.NamespaceFrom(ctx)
|
||||
if !ok {
|
||||
t.Fatalf("Error getting namespace")
|
||||
}
|
||||
|
@ -35,8 +36,8 @@ func TestNamespaceContext(t *testing.T) {
|
|||
t.Fatalf("Expected: %s, Actual: %s", api.NamespaceDefault, result)
|
||||
}
|
||||
|
||||
ctx = api.NewContext()
|
||||
result, ok = api.NamespaceFrom(ctx)
|
||||
ctx = genericapirequest.NewContext()
|
||||
result, ok = genericapirequest.NamespaceFrom(ctx)
|
||||
if ok {
|
||||
t.Fatalf("Should not be ok because there is no namespace on the context")
|
||||
}
|
||||
|
@ -44,8 +45,8 @@ func TestNamespaceContext(t *testing.T) {
|
|||
|
||||
// TestValidNamespace validates that namespace rules are enforced on a resource prior to create or update
|
||||
func TestValidNamespace(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
namespace, _ := api.NamespaceFrom(ctx)
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
namespace, _ := genericapirequest.NamespaceFrom(ctx)
|
||||
resource := api.ReplicationController{}
|
||||
if !api.ValidNamespace(ctx, &resource.ObjectMeta) {
|
||||
t.Fatalf("expected success")
|
||||
|
@ -57,13 +58,13 @@ func TestValidNamespace(t *testing.T) {
|
|||
if api.ValidNamespace(ctx, &resource.ObjectMeta) {
|
||||
t.Fatalf("Expected error that resource and context errors do not match because resource has different namespace")
|
||||
}
|
||||
ctx = api.NewContext()
|
||||
ctx = genericapirequest.NewContext()
|
||||
if api.ValidNamespace(ctx, &resource.ObjectMeta) {
|
||||
t.Fatalf("Expected error that resource and context errors do not match since context has no namespace")
|
||||
}
|
||||
|
||||
ctx = api.NewContext()
|
||||
ns := api.NamespaceValue(ctx)
|
||||
ctx = genericapirequest.NewContext()
|
||||
ns := genericapirequest.NamespaceValue(ctx)
|
||||
if ns != "" {
|
||||
t.Fatalf("Expected the empty string")
|
||||
}
|
||||
|
@ -71,12 +72,12 @@ func TestValidNamespace(t *testing.T) {
|
|||
|
||||
//TestUserContext validates that a userinfo can be get/set on a context object
|
||||
func TestUserContext(t *testing.T) {
|
||||
ctx := api.NewContext()
|
||||
_, ok := api.UserFrom(ctx)
|
||||
ctx := genericapirequest.NewContext()
|
||||
_, ok := genericapirequest.UserFrom(ctx)
|
||||
if ok {
|
||||
t.Fatalf("Should not be ok because there is no user.Info on the context")
|
||||
}
|
||||
ctx = api.WithUser(
|
||||
ctx = genericapirequest.WithUser(
|
||||
ctx,
|
||||
&user.DefaultInfo{
|
||||
Name: "bob",
|
||||
|
@ -86,7 +87,7 @@ func TestUserContext(t *testing.T) {
|
|||
},
|
||||
)
|
||||
|
||||
result, ok := api.UserFrom(ctx)
|
||||
result, ok := genericapirequest.UserFrom(ctx)
|
||||
if !ok {
|
||||
t.Fatalf("Error getting user info")
|
||||
}
|
||||
|
@ -122,16 +123,16 @@ func TestUserContext(t *testing.T) {
|
|||
|
||||
//TestUIDContext validates that a UID can be get/set on a context object
|
||||
func TestUIDContext(t *testing.T) {
|
||||
ctx := api.NewContext()
|
||||
_, ok := api.UIDFrom(ctx)
|
||||
ctx := genericapirequest.NewContext()
|
||||
_, ok := genericapirequest.UIDFrom(ctx)
|
||||
if ok {
|
||||
t.Fatalf("Should not be ok because there is no UID on the context")
|
||||
}
|
||||
ctx = api.WithUID(
|
||||
ctx = genericapirequest.WithUID(
|
||||
ctx,
|
||||
types.UID("testUID"),
|
||||
)
|
||||
_, ok = api.UIDFrom(ctx)
|
||||
_, ok = genericapirequest.UIDFrom(ctx)
|
||||
if !ok {
|
||||
t.Fatalf("Error getting UID")
|
||||
}
|
||||
|
@ -139,17 +140,17 @@ func TestUIDContext(t *testing.T) {
|
|||
|
||||
//TestUserAgentContext validates that a useragent can be get/set on a context object
|
||||
func TestUserAgentContext(t *testing.T) {
|
||||
ctx := api.NewContext()
|
||||
_, ok := api.UserAgentFrom(ctx)
|
||||
ctx := genericapirequest.NewContext()
|
||||
_, ok := genericapirequest.UserAgentFrom(ctx)
|
||||
if ok {
|
||||
t.Fatalf("Should not be ok because there is no UserAgent on the context")
|
||||
}
|
||||
|
||||
ctx = api.WithUserAgent(
|
||||
ctx = genericapirequest.WithUserAgent(
|
||||
ctx,
|
||||
"TestUserAgent",
|
||||
)
|
||||
result, ok := api.UserAgentFrom(ctx)
|
||||
result, ok := genericapirequest.UserAgentFrom(ctx)
|
||||
if !ok {
|
||||
t.Fatalf("Error getting UserAgent")
|
||||
}
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package api
|
||||
package request
|
||||
|
||||
import (
|
||||
"errors"
|
|
@ -21,7 +21,6 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
)
|
||||
|
||||
|
@ -177,7 +176,7 @@ func (r *RequestInfoFactory) NewRequestInfo(req *http.Request) (*RequestInfo, er
|
|||
}
|
||||
}
|
||||
} else {
|
||||
requestInfo.Namespace = api.NamespaceNone
|
||||
requestInfo.Namespace = "" // TODO(sttts): solve import cycle when using api.NamespaceNone
|
||||
}
|
||||
|
||||
// parsing successful, so we now know the proper value for .Parts
|
||||
|
@ -222,12 +221,12 @@ type requestInfoKeyType int
|
|||
const requestInfoKey requestInfoKeyType = iota
|
||||
|
||||
// WithRequestInfo returns a copy of parent in which the request info value is set
|
||||
func WithRequestInfo(parent api.Context, info *RequestInfo) api.Context {
|
||||
return api.WithValue(parent, requestInfoKey, info)
|
||||
func WithRequestInfo(parent Context, info *RequestInfo) Context {
|
||||
return WithValue(parent, requestInfoKey, info)
|
||||
}
|
||||
|
||||
// RequestInfoFrom returns the value of the RequestInfo key on the ctx
|
||||
func RequestInfoFrom(ctx api.Context) (*RequestInfo, bool) {
|
||||
func RequestInfoFrom(ctx Context) (*RequestInfo, bool) {
|
||||
info, ok := ctx.Value(requestInfoKey).(*RequestInfo)
|
||||
return info, ok
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
)
|
||||
|
||||
|
@ -32,15 +30,8 @@ func (fakeRL) Stop() {}
|
|||
func (f fakeRL) TryAccept() bool { return bool(f) }
|
||||
func (f fakeRL) Accept() {}
|
||||
|
||||
func getPath(resource, namespace, name string) string {
|
||||
return testapi.Default.ResourcePath(resource, namespace, name)
|
||||
}
|
||||
|
||||
func pathWithPrefix(prefix, resource, namespace, name string) string {
|
||||
return testapi.Default.ResourcePathWithPrefix(prefix, resource, namespace, name)
|
||||
}
|
||||
|
||||
func TestGetAPIRequestInfo(t *testing.T) {
|
||||
namespaceAll := "" // TODO(sttts): solve import cycle when using api.NamespaceAll
|
||||
successCases := []struct {
|
||||
method string
|
||||
url string
|
||||
|
@ -62,8 +53,8 @@ func TestGetAPIRequestInfo(t *testing.T) {
|
|||
{"GET", "/api/v1/namespaces/other/pods", "list", "api", "", "v1", "other", "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/namespaces/other/pods/foo", "get", "api", "", "v1", "other", "pods", "", "foo", []string{"pods", "foo"}},
|
||||
{"HEAD", "/api/v1/namespaces/other/pods/foo", "get", "api", "", "v1", "other", "pods", "", "foo", []string{"pods", "foo"}},
|
||||
{"GET", "/api/v1/pods", "list", "api", "", "v1", api.NamespaceAll, "pods", "", "", []string{"pods"}},
|
||||
{"HEAD", "/api/v1/pods", "list", "api", "", "v1", api.NamespaceAll, "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/pods", "list", "api", "", "v1", namespaceAll, "pods", "", "", []string{"pods"}},
|
||||
{"HEAD", "/api/v1/pods", "list", "api", "", "v1", namespaceAll, "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/namespaces/other/pods/foo", "get", "api", "", "v1", "other", "pods", "", "foo", []string{"pods", "foo"}},
|
||||
{"GET", "/api/v1/namespaces/other/pods", "list", "api", "", "v1", "other", "pods", "", "", []string{"pods"}},
|
||||
|
||||
|
@ -72,9 +63,9 @@ func TestGetAPIRequestInfo(t *testing.T) {
|
|||
{"GET", "/api/v1/proxy/namespaces/other/pods/foo/subpath/not/a/subresource", "proxy", "api", "", "v1", "other", "pods", "", "foo", []string{"pods", "foo", "subpath", "not", "a", "subresource"}},
|
||||
{"GET", "/api/v1/redirect/namespaces/other/pods/foo", "redirect", "api", "", "v1", "other", "pods", "", "foo", []string{"pods", "foo"}},
|
||||
{"GET", "/api/v1/redirect/namespaces/other/pods/foo/subpath/not/a/subresource", "redirect", "api", "", "v1", "other", "pods", "", "foo", []string{"pods", "foo", "subpath", "not", "a", "subresource"}},
|
||||
{"GET", "/api/v1/watch/pods", "watch", "api", "", "v1", api.NamespaceAll, "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/pods?watch=true", "watch", "api", "", "v1", api.NamespaceAll, "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/pods?watch=false", "list", "api", "", "v1", api.NamespaceAll, "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/watch/pods", "watch", "api", "", "v1", namespaceAll, "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/pods?watch=true", "watch", "api", "", "v1", namespaceAll, "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/pods?watch=false", "list", "api", "", "v1", namespaceAll, "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/watch/namespaces/other/pods", "watch", "api", "", "v1", "other", "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/namespaces/other/pods?watch=1", "watch", "api", "", "v1", "other", "pods", "", "", []string{"pods"}},
|
||||
{"GET", "/api/v1/namespaces/other/pods?watch=0", "list", "api", "", "v1", "other", "pods", "", "", []string{"pods"}},
|
||||
|
|
|
@ -126,7 +126,7 @@ type Config struct {
|
|||
LegacyAPIGroupPrefixes sets.String
|
||||
// RequestContextMapper maps requests to contexts. Exported so downstream consumers can provider their own mappers
|
||||
// TODO confirm that anyone downstream actually uses this and doesn't just need an accessor
|
||||
RequestContextMapper api.RequestContextMapper
|
||||
RequestContextMapper apirequest.RequestContextMapper
|
||||
// Serializer is required and provides the interface for serializing and converting objects to and from the wire
|
||||
// The default (api.Codecs) usually works fine.
|
||||
Serializer runtime.NegotiatedSerializer
|
||||
|
@ -195,7 +195,7 @@ func NewConfig() *Config {
|
|||
config := &Config{
|
||||
Serializer: api.Codecs,
|
||||
ReadWritePort: 6443,
|
||||
RequestContextMapper: api.NewRequestContextMapper(),
|
||||
RequestContextMapper: apirequest.NewRequestContextMapper(),
|
||||
BuildHandlerChainsFunc: DefaultBuildHandlerChain,
|
||||
LegacyAPIGroupPrefixes: sets.NewString(DefaultLegacyAPIPrefix),
|
||||
HealthzChecks: []healthz.HealthzChecker{healthz.PingHealthz},
|
||||
|
@ -563,7 +563,7 @@ func DefaultBuildHandlerChain(apiHandler http.Handler, c *Config) (secure, insec
|
|||
handler = genericfilters.WithTimeoutForNonLongRunningRequests(handler, c.RequestContextMapper, c.LongRunningFunc)
|
||||
handler = genericfilters.WithMaxInFlightLimit(handler, c.MaxRequestsInFlight, c.MaxMutatingRequestsInFlight, c.RequestContextMapper, c.LongRunningFunc)
|
||||
handler = genericapifilters.WithRequestInfo(handler, NewRequestInfoResolver(c), c.RequestContextMapper)
|
||||
handler = api.WithRequestContext(handler, c.RequestContextMapper)
|
||||
handler = apirequest.WithRequestContext(handler, c.RequestContextMapper)
|
||||
return handler
|
||||
}
|
||||
audit := func(handler http.Handler) http.Handler {
|
||||
|
|
|
@ -41,7 +41,6 @@ go_test(
|
|||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/genericapiserver/api/filters:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
|
|
|
@ -20,9 +20,9 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
apirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/httplog"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
|
||||
|
@ -46,7 +46,7 @@ func WithMaxInFlightLimit(
|
|||
handler http.Handler,
|
||||
nonMutatingLimit int,
|
||||
mutatingLimit int,
|
||||
requestContextMapper api.RequestContextMapper,
|
||||
requestContextMapper genericapirequest.RequestContextMapper,
|
||||
longRunningRequestCheck LongRunningRequestCheck,
|
||||
) http.Handler {
|
||||
if nonMutatingLimit == 0 && mutatingLimit == 0 {
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
"sync"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
apifilters "k8s.io/kubernetes/pkg/genericapiserver/api/filters"
|
||||
apirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
|
@ -35,7 +34,7 @@ func createMaxInflightServer(callsWg, blockWg *sync.WaitGroup, disableCallsWg *b
|
|||
|
||||
longRunningRequestCheck := BasicLongRunningRequestCheck(sets.NewString("watch"), sets.NewString("proxy"))
|
||||
|
||||
requestContextMapper := api.NewRequestContextMapper()
|
||||
requestContextMapper := apirequest.NewRequestContextMapper()
|
||||
requestInfoFactory := &apirequest.RequestInfoFactory{APIPrefixes: sets.NewString("apis", "api"), GrouplessAPIPrefixes: sets.NewString("api")}
|
||||
handler := WithMaxInFlightLimit(
|
||||
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -57,7 +56,7 @@ func createMaxInflightServer(callsWg, blockWg *sync.WaitGroup, disableCallsWg *b
|
|||
longRunningRequestCheck,
|
||||
)
|
||||
handler = apifilters.WithRequestInfo(handler, requestInfoFactory, requestContextMapper)
|
||||
handler = api.WithRequestContext(handler, requestContextMapper)
|
||||
handler = apirequest.WithRequestContext(handler, requestContextMapper)
|
||||
|
||||
return httptest.NewServer(handler)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
apierrors "k8s.io/kubernetes/pkg/api/errors"
|
||||
apirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/httplog"
|
||||
|
@ -30,7 +29,7 @@ import (
|
|||
)
|
||||
|
||||
// WithPanicRecovery wraps an http Handler to recover and log panics.
|
||||
func WithPanicRecovery(handler http.Handler, requestContextMapper api.RequestContextMapper) http.Handler {
|
||||
func WithPanicRecovery(handler http.Handler, requestContextMapper apirequest.RequestContextMapper) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
defer runtime.HandleCrash(func(err interface{}) {
|
||||
http.Error(w, "This request caused apisever to panic. Look in log for details.", http.StatusInternalServerError)
|
||||
|
|
|
@ -35,7 +35,7 @@ const globalTimeout = time.Minute
|
|||
var errConnKilled = fmt.Errorf("kill connection/stream")
|
||||
|
||||
// WithTimeoutForNonLongRunningRequests times out non-long-running requests after the time given by globalTimeout.
|
||||
func WithTimeoutForNonLongRunningRequests(handler http.Handler, requestContextMapper api.RequestContextMapper, longRunning LongRunningRequestCheck) http.Handler {
|
||||
func WithTimeoutForNonLongRunningRequests(handler http.Handler, requestContextMapper apirequest.RequestContextMapper, longRunning LongRunningRequestCheck) http.Handler {
|
||||
if longRunning == nil {
|
||||
return handler
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import (
|
|||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/client/restclient"
|
||||
genericapi "k8s.io/kubernetes/pkg/genericapiserver/api"
|
||||
apirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
genericmux "k8s.io/kubernetes/pkg/genericapiserver/mux"
|
||||
openapicommon "k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/routes"
|
||||
|
@ -95,7 +96,7 @@ type GenericAPIServer struct {
|
|||
admissionControl admission.Interface
|
||||
|
||||
// requestContextMapper provides a way to get the context for a request. It may be nil.
|
||||
requestContextMapper api.RequestContextMapper
|
||||
requestContextMapper apirequest.RequestContextMapper
|
||||
|
||||
// The registered APIs
|
||||
HandlerContainer *genericmux.APIContainer
|
||||
|
@ -152,7 +153,7 @@ func init() {
|
|||
|
||||
// RequestContextMapper is exposed so that third party resource storage can be build in a different location.
|
||||
// TODO refactor third party resource storage
|
||||
func (s *GenericAPIServer) RequestContextMapper() api.RequestContextMapper {
|
||||
func (s *GenericAPIServer) RequestContextMapper() apirequest.RequestContextMapper {
|
||||
return s.requestContextMapper
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/auth/authorizer"
|
||||
"k8s.io/kubernetes/pkg/auth/user"
|
||||
openapigen "k8s.io/kubernetes/pkg/generated/openapi"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
|
||||
|
@ -55,7 +56,7 @@ func setUp(t *testing.T) (*etcdtesting.EtcdTestServer, Config, *assert.Assertion
|
|||
|
||||
config := NewConfig()
|
||||
config.PublicAddress = net.ParseIP("192.168.10.4")
|
||||
config.RequestContextMapper = api.NewRequestContextMapper()
|
||||
config.RequestContextMapper = genericapirequest.NewRequestContextMapper()
|
||||
config.LegacyAPIGroupPrefixes = sets.NewString("/api")
|
||||
|
||||
config.OpenAPIConfig = DefaultOpenAPIConfig(openapigen.OpenAPIDefinitions)
|
||||
|
@ -601,7 +602,7 @@ func (p *testGetterStorage) New() runtime.Object {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *testGetterStorage) Get(ctx api.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
func (p *testGetterStorage) Get(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ go_library(
|
|||
srcs = ["kubelet_client.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/v1:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/client/restclient:go_default_library",
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/client/restclient"
|
||||
|
@ -62,7 +61,7 @@ type ConnectionInfo struct {
|
|||
|
||||
// ConnectionInfoGetter provides ConnectionInfo for the kubelet running on a named node
|
||||
type ConnectionInfoGetter interface {
|
||||
GetConnectionInfo(ctx api.Context, nodeName types.NodeName) (*ConnectionInfo, error)
|
||||
GetConnectionInfo(nodeName types.NodeName) (*ConnectionInfo, error)
|
||||
}
|
||||
|
||||
func MakeTransport(config *KubeletClientConfig) (http.RoundTripper, error) {
|
||||
|
@ -153,7 +152,7 @@ func NewNodeConnectionInfoGetter(nodes NodeGetter, config KubeletClientConfig) (
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (k *NodeConnectionInfoGetter) GetConnectionInfo(ctx api.Context, nodeName types.NodeName) (*ConnectionInfo, error) {
|
||||
func (k *NodeConnectionInfoGetter) GetConnectionInfo(nodeName types.NodeName) (*ConnectionInfo, error) {
|
||||
node, err := k.nodes.Get(string(nodeName), metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -117,6 +117,7 @@ go_test(
|
|||
"//pkg/client/testing/core:go_default_library",
|
||||
"//pkg/generated/openapi:go_default_library",
|
||||
"//pkg/genericapiserver:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/kubelet/client:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
|
|
|
@ -46,6 +46,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/client/restclient"
|
||||
openapigen "k8s.io/kubernetes/pkg/generated/openapi"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
|
@ -88,7 +89,7 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
|
|||
config.GenericConfig.LoopbackClientConfig = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: api.Codecs}}
|
||||
config.GenericConfig.PublicAddress = net.ParseIP("192.168.10.4")
|
||||
config.GenericConfig.LegacyAPIGroupPrefixes = sets.NewString("/api")
|
||||
config.GenericConfig.RequestContextMapper = api.NewRequestContextMapper()
|
||||
config.GenericConfig.RequestContextMapper = genericapirequest.NewRequestContextMapper()
|
||||
config.GenericConfig.LoopbackClientConfig = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: api.Codecs}}
|
||||
config.GenericConfig.EnableMetrics = true
|
||||
config.EnableCoreControllers = false
|
||||
|
|
|
@ -21,6 +21,7 @@ go_library(
|
|||
"//pkg/genericapiserver:go_default_library",
|
||||
"//pkg/genericapiserver/api:go_default_library",
|
||||
"//pkg/genericapiserver/api/handlers:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/extensions/rest:go_default_library",
|
||||
"//pkg/registry/extensions/thirdpartyresourcedata:go_default_library",
|
||||
"//pkg/registry/extensions/thirdpartyresourcedata/etcd:go_default_library",
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/genericapiserver"
|
||||
genericapi "k8s.io/kubernetes/pkg/genericapiserver/api"
|
||||
genericapihandlers "k8s.io/kubernetes/pkg/genericapiserver/api/handlers"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
extensionsrest "k8s.io/kubernetes/pkg/registry/extensions/rest"
|
||||
"k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata"
|
||||
thirdpartyresourcedataetcd "k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/etcd"
|
||||
|
@ -163,7 +164,7 @@ func (m *ThirdPartyResourceServer) RemoveThirdPartyResource(path string) error {
|
|||
}
|
||||
|
||||
func (m *ThirdPartyResourceServer) removeAllThirdPartyResources(registry *thirdpartyresourcedataetcd.REST) error {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
existingData, err := registry.List(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -20,6 +20,7 @@ go_library(
|
|||
"//pkg/apis/apps:go_default_library",
|
||||
"//pkg/apis/apps/validation: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",
|
||||
|
@ -37,5 +38,6 @@ go_test(
|
|||
"//pkg/api:go_default_library",
|
||||
"//pkg/apis/apps:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -13,10 +13,10 @@ go_library(
|
|||
srcs = ["etcd.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/apis/apps:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/apps/petset:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/generic/registry:go_default_library",
|
||||
|
@ -35,6 +35,7 @@ go_test(
|
|||
"//pkg/apis/apps: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",
|
||||
|
|
|
@ -17,10 +17,10 @@ limitations under the License.
|
|||
package etcd
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
appsapi "k8s.io/kubernetes/pkg/apis/apps"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/registry/apps/petset"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
|
@ -67,11 +67,11 @@ 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)
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/apis/apps"
|
||||
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"
|
||||
|
@ -39,7 +40,7 @@ func newStorage(t *testing.T) (*REST, *StatusREST, *etcdtesting.EtcdTestServer)
|
|||
|
||||
// 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) {
|
||||
ctx := api.WithNamespace(api.NewContext(), ps.Namespace)
|
||||
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), ps.Namespace)
|
||||
obj, err := storage.Create(ctx, &ps)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create StatefulSet, %v", err)
|
||||
|
@ -99,7 +100,7 @@ func TestStatusUpdate(t *testing.T) {
|
|||
storage, statusStorage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.Store.DestroyFunc()
|
||||
ctx := api.WithNamespace(api.NewContext(), api.NamespaceDefault)
|
||||
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), api.NamespaceDefault)
|
||||
key := "/statefulsets/" + api.NamespaceDefault + "/foo"
|
||||
validStatefulSet := validNewStatefulSet()
|
||||
if err := storage.Storage.Create(ctx, key, validStatefulSet, nil, 0); err != nil {
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/apis/apps"
|
||||
"k8s.io/kubernetes/pkg/apis/apps/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"
|
||||
|
@ -46,7 +47,7 @@ func (statefulSetStrategy) NamespaceScoped() bool {
|
|||
}
|
||||
|
||||
// PrepareForCreate clears the status of an StatefulSet before creation.
|
||||
func (statefulSetStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
func (statefulSetStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||
statefulSet := obj.(*apps.StatefulSet)
|
||||
// create cannot set status
|
||||
statefulSet.Status = apps.StatefulSetStatus{}
|
||||
|
@ -55,7 +56,7 @@ func (statefulSetStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object)
|
|||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (statefulSetStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (statefulSetStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newStatefulSet := obj.(*apps.StatefulSet)
|
||||
oldStatefulSet := old.(*apps.StatefulSet)
|
||||
// Update is not allowed to set status
|
||||
|
@ -71,7 +72,7 @@ func (statefulSetStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Ob
|
|||
}
|
||||
|
||||
// Validate validates a new StatefulSet.
|
||||
func (statefulSetStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
func (statefulSetStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
|
||||
statefulSet := obj.(*apps.StatefulSet)
|
||||
return validation.ValidateStatefulSet(statefulSet)
|
||||
}
|
||||
|
@ -86,7 +87,7 @@ func (statefulSetStrategy) AllowCreateOnUpdate() bool {
|
|||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (statefulSetStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (statefulSetStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
validationErrorList := validation.ValidateStatefulSet(obj.(*apps.StatefulSet))
|
||||
updateErrorList := validation.ValidateStatefulSetUpdate(obj.(*apps.StatefulSet), old.(*apps.StatefulSet))
|
||||
return append(validationErrorList, updateErrorList...)
|
||||
|
@ -128,7 +129,7 @@ type statefulSetStatusStrategy struct {
|
|||
var StatusStrategy = statefulSetStatusStrategy{Strategy}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update of status
|
||||
func (statefulSetStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (statefulSetStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newStatefulSet := obj.(*apps.StatefulSet)
|
||||
oldStatefulSet := old.(*apps.StatefulSet)
|
||||
// status changes are not allowed to update spec
|
||||
|
@ -136,7 +137,7 @@ func (statefulSetStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runt
|
|||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user updating status
|
||||
func (statefulSetStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (statefulSetStatusStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
// TODO: Validate status updates.
|
||||
return validation.ValidateStatefulSetStatusUpdate(obj.(*apps.StatefulSet), old.(*apps.StatefulSet))
|
||||
}
|
||||
|
|
|
@ -22,10 +22,11 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/apps"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
func TestStatefulSetStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if !Strategy.NamespaceScoped() {
|
||||
t.Errorf("StatefulSet must be namespace scoped")
|
||||
}
|
||||
|
@ -88,7 +89,7 @@ func TestStatefulSetStrategy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStatefulSetStatusStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if !StatusStrategy.NamespaceScoped() {
|
||||
t.Errorf("StatefulSet must be namespace scoped")
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ go_library(
|
|||
srcs = ["storage.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/apis/authentication:go_default_library",
|
||||
"//pkg/auth/authenticator:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -20,10 +20,10 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
apierrors "k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/apis/authentication"
|
||||
"k8s.io/kubernetes/pkg/auth/authenticator"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
|
@ -39,12 +39,12 @@ func (r *REST) New() runtime.Object {
|
|||
return &authentication.TokenReview{}
|
||||
}
|
||||
|
||||
func (r *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
tokenReview, ok := obj.(*authentication.TokenReview)
|
||||
if !ok {
|
||||
return nil, apierrors.NewBadRequest(fmt.Sprintf("not a TokenReview: %#v", obj))
|
||||
}
|
||||
namespace := api.NamespaceValue(ctx)
|
||||
namespace := genericapirequest.NamespaceValue(ctx)
|
||||
if len(namespace) != 0 {
|
||||
return nil, apierrors.NewBadRequest(fmt.Sprintf("namespace is not allowed on this type: %v", namespace))
|
||||
}
|
||||
|
|
|
@ -12,11 +12,11 @@ go_library(
|
|||
srcs = ["rest.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/apis/authorization:go_default_library",
|
||||
"//pkg/apis/authorization/validation:go_default_library",
|
||||
"//pkg/auth/authorizer:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/authorization/util:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
],
|
||||
|
|
|
@ -19,11 +19,11 @@ package localsubjectaccessreview
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
kapi "k8s.io/kubernetes/pkg/api"
|
||||
kapierrors "k8s.io/kubernetes/pkg/api/errors"
|
||||
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
|
||||
authorizationvalidation "k8s.io/kubernetes/pkg/apis/authorization/validation"
|
||||
"k8s.io/kubernetes/pkg/auth/authorizer"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
authorizationutil "k8s.io/kubernetes/pkg/registry/authorization/util"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
@ -40,7 +40,7 @@ func (r *REST) New() runtime.Object {
|
|||
return &authorizationapi.LocalSubjectAccessReview{}
|
||||
}
|
||||
|
||||
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
localSubjectAccessReview, ok := obj.(*authorizationapi.LocalSubjectAccessReview)
|
||||
if !ok {
|
||||
return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a LocaLocalSubjectAccessReview: %#v", obj))
|
||||
|
@ -48,7 +48,7 @@ func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, err
|
|||
if errs := authorizationvalidation.ValidateLocalSubjectAccessReview(localSubjectAccessReview); len(errs) > 0 {
|
||||
return nil, kapierrors.NewInvalid(authorizationapi.Kind(localSubjectAccessReview.Kind), "", errs)
|
||||
}
|
||||
namespace := kapi.NamespaceValue(ctx)
|
||||
namespace := genericapirequest.NamespaceValue(ctx)
|
||||
if len(namespace) == 0 {
|
||||
return nil, kapierrors.NewBadRequest(fmt.Sprintf("namespace is required on this type: %v", namespace))
|
||||
}
|
||||
|
|
|
@ -12,11 +12,11 @@ go_library(
|
|||
srcs = ["rest.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/apis/authorization:go_default_library",
|
||||
"//pkg/apis/authorization/validation:go_default_library",
|
||||
"//pkg/auth/authorizer:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/authorization/util:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
],
|
||||
|
|
|
@ -19,11 +19,11 @@ package selfsubjectaccessreview
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
apierrors "k8s.io/kubernetes/pkg/api/errors"
|
||||
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
|
||||
authorizationvalidation "k8s.io/kubernetes/pkg/apis/authorization/validation"
|
||||
"k8s.io/kubernetes/pkg/auth/authorizer"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
authorizationutil "k8s.io/kubernetes/pkg/registry/authorization/util"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
@ -40,7 +40,7 @@ func (r *REST) New() runtime.Object {
|
|||
return &authorizationapi.SelfSubjectAccessReview{}
|
||||
}
|
||||
|
||||
func (r *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
selfSAR, ok := obj.(*authorizationapi.SelfSubjectAccessReview)
|
||||
if !ok {
|
||||
return nil, apierrors.NewBadRequest(fmt.Sprintf("not a SelfSubjectAccessReview: %#v", obj))
|
||||
|
@ -48,7 +48,7 @@ func (r *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, erro
|
|||
if errs := authorizationvalidation.ValidateSelfSubjectAccessReview(selfSAR); len(errs) > 0 {
|
||||
return nil, apierrors.NewInvalid(authorizationapi.Kind(selfSAR.Kind), "", errs)
|
||||
}
|
||||
userToCheck, exists := api.UserFrom(ctx)
|
||||
userToCheck, exists := genericapirequest.UserFrom(ctx)
|
||||
if !exists {
|
||||
return nil, apierrors.NewBadRequest("no user present on request")
|
||||
}
|
||||
|
|
|
@ -12,11 +12,11 @@ go_library(
|
|||
srcs = ["rest.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/apis/authorization:go_default_library",
|
||||
"//pkg/apis/authorization/validation:go_default_library",
|
||||
"//pkg/auth/authorizer:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/authorization/util:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
],
|
||||
|
|
|
@ -19,11 +19,11 @@ package subjectaccessreview
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
kapi "k8s.io/kubernetes/pkg/api"
|
||||
kapierrors "k8s.io/kubernetes/pkg/api/errors"
|
||||
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
|
||||
authorizationvalidation "k8s.io/kubernetes/pkg/apis/authorization/validation"
|
||||
"k8s.io/kubernetes/pkg/auth/authorizer"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
authorizationutil "k8s.io/kubernetes/pkg/registry/authorization/util"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
@ -40,7 +40,7 @@ func (r *REST) New() runtime.Object {
|
|||
return &authorizationapi.SubjectAccessReview{}
|
||||
}
|
||||
|
||||
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
func (r *REST) Create(ctx genericapirequest.Context, obj runtime.Object) (runtime.Object, error) {
|
||||
subjectAccessReview, ok := obj.(*authorizationapi.SubjectAccessReview)
|
||||
if !ok {
|
||||
return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a SubjectAccessReview: %#v", obj))
|
||||
|
|
|
@ -20,6 +20,7 @@ go_library(
|
|||
"//pkg/apis/autoscaling:go_default_library",
|
||||
"//pkg/apis/autoscaling/validation:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/storage:go_default_library",
|
||||
|
|
|
@ -13,10 +13,10 @@ go_library(
|
|||
srcs = ["etcd.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/apis/autoscaling:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/autoscaling/horizontalpodautoscaler:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/generic/registry:go_default_library",
|
||||
|
|
|
@ -17,10 +17,10 @@ limitations under the License.
|
|||
package etcd
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/registry/autoscaling/horizontalpodautoscaler"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
|
@ -66,11 +66,11 @@ 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)
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling/validation"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/storage"
|
||||
|
@ -45,7 +46,7 @@ func (autoscalerStrategy) NamespaceScoped() bool {
|
|||
}
|
||||
|
||||
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
|
||||
func (autoscalerStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
func (autoscalerStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||
newHPA := obj.(*autoscaling.HorizontalPodAutoscaler)
|
||||
|
||||
// create cannot set status
|
||||
|
@ -53,7 +54,7 @@ func (autoscalerStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object)
|
|||
}
|
||||
|
||||
// Validate validates a new autoscaler.
|
||||
func (autoscalerStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
func (autoscalerStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
|
||||
autoscaler := obj.(*autoscaling.HorizontalPodAutoscaler)
|
||||
return validation.ValidateHorizontalPodAutoscaler(autoscaler)
|
||||
}
|
||||
|
@ -68,7 +69,7 @@ func (autoscalerStrategy) AllowCreateOnUpdate() bool {
|
|||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (autoscalerStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (autoscalerStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newHPA := obj.(*autoscaling.HorizontalPodAutoscaler)
|
||||
oldHPA := old.(*autoscaling.HorizontalPodAutoscaler)
|
||||
// Update is not allowed to set status
|
||||
|
@ -76,7 +77,7 @@ func (autoscalerStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Obj
|
|||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (autoscalerStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (autoscalerStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateHorizontalPodAutoscalerUpdate(obj.(*autoscaling.HorizontalPodAutoscaler), old.(*autoscaling.HorizontalPodAutoscaler))
|
||||
}
|
||||
|
||||
|
@ -111,13 +112,13 @@ type autoscalerStatusStrategy struct {
|
|||
|
||||
var StatusStrategy = autoscalerStatusStrategy{Strategy}
|
||||
|
||||
func (autoscalerStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (autoscalerStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newAutoscaler := obj.(*autoscaling.HorizontalPodAutoscaler)
|
||||
oldAutoscaler := old.(*autoscaling.HorizontalPodAutoscaler)
|
||||
// status changes are not allowed to update spec
|
||||
newAutoscaler.Spec = oldAutoscaler.Spec
|
||||
}
|
||||
|
||||
func (autoscalerStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (autoscalerStatusStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateHorizontalPodAutoscalerStatusUpdate(obj.(*autoscaling.HorizontalPodAutoscaler), old.(*autoscaling.HorizontalPodAutoscaler))
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ go_library(
|
|||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/batch/validation: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",
|
||||
|
@ -38,5 +39,6 @@ go_test(
|
|||
"//pkg/api/testing:go_default_library",
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -13,10 +13,10 @@ go_library(
|
|||
srcs = ["etcd.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/batch/cronjob:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/generic/registry:go_default_library",
|
||||
|
|
|
@ -17,10 +17,10 @@ limitations under the License.
|
|||
package etcd
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/registry/batch/cronjob"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
|
@ -68,11 +68,11 @@ 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)
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
"k8s.io/kubernetes/pkg/apis/batch/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,20 +46,20 @@ func (scheduledJobStrategy) NamespaceScoped() bool {
|
|||
}
|
||||
|
||||
// PrepareForCreate clears the status of a scheduled job before creation.
|
||||
func (scheduledJobStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
func (scheduledJobStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||
scheduledJob := obj.(*batch.CronJob)
|
||||
scheduledJob.Status = batch.CronJobStatus{}
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (scheduledJobStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (scheduledJobStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newCronJob := obj.(*batch.CronJob)
|
||||
oldCronJob := old.(*batch.CronJob)
|
||||
newCronJob.Status = oldCronJob.Status
|
||||
}
|
||||
|
||||
// Validate validates a new scheduled job.
|
||||
func (scheduledJobStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
func (scheduledJobStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
|
||||
scheduledJob := obj.(*batch.CronJob)
|
||||
return validation.ValidateCronJob(scheduledJob)
|
||||
}
|
||||
|
@ -77,7 +78,7 @@ func (scheduledJobStrategy) AllowCreateOnUpdate() bool {
|
|||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (scheduledJobStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (scheduledJobStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateCronJob(obj.(*batch.CronJob))
|
||||
}
|
||||
|
||||
|
@ -87,13 +88,13 @@ type scheduledJobStatusStrategy struct {
|
|||
|
||||
var StatusStrategy = scheduledJobStatusStrategy{Strategy}
|
||||
|
||||
func (scheduledJobStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (scheduledJobStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newJob := obj.(*batch.CronJob)
|
||||
oldJob := old.(*batch.CronJob)
|
||||
newJob.Spec = oldJob.Spec
|
||||
}
|
||||
|
||||
func (scheduledJobStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (scheduledJobStatusStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return field.ErrorList{}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
func newBool(a bool) *bool {
|
||||
|
@ -32,7 +33,7 @@ func newBool(a bool) *bool {
|
|||
}
|
||||
|
||||
func TestCronJobStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if !Strategy.NamespaceScoped() {
|
||||
t.Errorf("CronJob must be namespace scoped")
|
||||
}
|
||||
|
@ -94,7 +95,7 @@ func TestCronJobStrategy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCronJobStatusStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if !StatusStrategy.NamespaceScoped() {
|
||||
t.Errorf("CronJob must be namespace scoped")
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ go_library(
|
|||
"//pkg/apis/batch/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",
|
||||
|
@ -40,6 +41,7 @@ go_test(
|
|||
"//pkg/api/testing:go_default_library",
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/types:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -13,10 +13,10 @@ go_library(
|
|||
srcs = ["etcd.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/batch/job:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/generic/registry:go_default_library",
|
||||
|
|
|
@ -17,10 +17,10 @@ limitations under the License.
|
|||
package etcd
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/registry/batch/job"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
|
@ -83,11 +83,11 @@ 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)
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/apis/batch/validation"
|
||||
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/runtime"
|
||||
|
@ -47,20 +48,20 @@ func (jobStrategy) NamespaceScoped() bool {
|
|||
}
|
||||
|
||||
// PrepareForCreate clears the status of a job before creation.
|
||||
func (jobStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
func (jobStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||
job := obj.(*batch.Job)
|
||||
job.Status = batch.JobStatus{}
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (jobStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (jobStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newJob := obj.(*batch.Job)
|
||||
oldJob := old.(*batch.Job)
|
||||
newJob.Status = oldJob.Status
|
||||
}
|
||||
|
||||
// Validate validates a new job.
|
||||
func (jobStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
func (jobStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
|
||||
job := obj.(*batch.Job)
|
||||
// TODO: move UID generation earlier and do this in defaulting logic?
|
||||
if job.Spec.ManualSelector == nil || *job.Spec.ManualSelector == false {
|
||||
|
@ -133,7 +134,7 @@ func (jobStrategy) AllowCreateOnUpdate() bool {
|
|||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (jobStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (jobStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
validationErrorList := validation.ValidateJob(obj.(*batch.Job))
|
||||
updateErrorList := validation.ValidateJobUpdate(obj.(*batch.Job), old.(*batch.Job))
|
||||
return append(validationErrorList, updateErrorList...)
|
||||
|
@ -145,13 +146,13 @@ type jobStatusStrategy struct {
|
|||
|
||||
var StatusStrategy = jobStatusStrategy{Strategy}
|
||||
|
||||
func (jobStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (jobStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newJob := obj.(*batch.Job)
|
||||
oldJob := old.(*batch.Job)
|
||||
newJob.Spec = oldJob.Spec
|
||||
}
|
||||
|
||||
func (jobStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (jobStatusStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateJobUpdateStatus(obj.(*batch.Job), old.(*batch.Job))
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
)
|
||||
|
||||
|
@ -35,7 +36,7 @@ func newBool(a bool) *bool {
|
|||
}
|
||||
|
||||
func TestJobStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if !Strategy.NamespaceScoped() {
|
||||
t.Errorf("Job must be namespace scoped")
|
||||
}
|
||||
|
@ -102,7 +103,7 @@ func TestJobStrategy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestJobStrategyWithGeneration(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
|
||||
theUID := types.UID("1a2b3c4d5e6f7g8h9i0k")
|
||||
|
||||
|
@ -152,7 +153,7 @@ func TestJobStrategyWithGeneration(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestJobStatusStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if !StatusStrategy.NamespaceScoped() {
|
||||
t.Errorf("Job must be namespace scoped")
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue