Skip to content

Commit 9619cd1

Browse files
deads2kironcladlou
authored andcommitted
UPSTREAM: 51803: make url parsing in apiserver configurable
:100644 100644 52823f8... 4c79a8a... M staging/src/k8s.io/apiserver/pkg/endpoints/filters/requestinfo.go :100644 100644 bbfc547... 989517c... M staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go :100644 100644 0d19af7... 87a8251... M staging/src/k8s.io/apiserver/pkg/server/config.go :100644 100644 b8aed64... 66e508c... M staging/src/k8s.io/apiserver/pkg/server/genericapiserver_test.go
1 parent a678589 commit 9619cd1

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

staging/src/k8s.io/apiserver/pkg/endpoints/filters/requestinfo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
// WithRequestInfo attaches a RequestInfo to the context.
29-
func WithRequestInfo(handler http.Handler, resolver *request.RequestInfoFactory, requestContextMapper request.RequestContextMapper) http.Handler {
29+
func WithRequestInfo(handler http.Handler, resolver request.RequestInfoResolver, requestContextMapper request.RequestContextMapper) http.Handler {
3030
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
3131
ctx, ok := requestContextMapper.Get(req)
3232
if !ok {

staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import (
2424
"k8s.io/apimachinery/pkg/util/sets"
2525
)
2626

27+
type RequestInfoResolver interface {
28+
NewRequestInfo(req *http.Request) (*RequestInfo, error)
29+
}
30+
2731
// RequestInfo holds information parsed from the http.Request
2832
type RequestInfo struct {
2933
// IsResourceRequest indicates whether or not the request is for an API resource or subresource

staging/src/k8s.io/apiserver/pkg/server/config.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ type Config struct {
137137
// RequestContextMapper maps requests to contexts. Exported so downstream consumers can provider their own mappers
138138
// TODO confirm that anyone downstream actually uses this and doesn't just need an accessor
139139
RequestContextMapper apirequest.RequestContextMapper
140+
// RequestInfoResolver is used to assign attributes (used by admission and authorization) based on a request URL.
141+
// Use-cases that are like kubelets may need to customize this.
142+
RequestInfoResolver apirequest.RequestInfoResolver
140143
// Serializer is required and provides the interface for serializing and converting objects to and from the wire
141144
// The default (api.Codecs) usually works fine.
142145
Serializer runtime.NegotiatedSerializer
@@ -364,6 +367,10 @@ func (c *Config) Complete() completedConfig {
364367
c.Authorizer = authorizerunion.New(tokenAuthorizer, c.Authorizer)
365368
}
366369

370+
if c.RequestInfoResolver == nil {
371+
c.RequestInfoResolver = NewRequestInfoResolver(c)
372+
}
373+
367374
return completedConfig{c}
368375
}
369376

@@ -477,7 +484,7 @@ func DefaultBuildHandlerChain(apiHandler http.Handler, c *Config) http.Handler {
477484
handler = genericfilters.WithCORS(handler, c.CorsAllowedOriginList, nil, nil, nil, "true")
478485
handler = genericfilters.WithPanicRecovery(handler)
479486
handler = genericfilters.WithTimeoutForNonLongRunningRequests(handler, c.RequestContextMapper, c.LongRunningFunc, c.RequestTimeout)
480-
handler = genericapifilters.WithRequestInfo(handler, NewRequestInfoResolver(c), c.RequestContextMapper)
487+
handler = genericapifilters.WithRequestInfo(handler, c.RequestInfoResolver, c.RequestContextMapper)
481488
handler = apirequest.WithRequestContext(handler, c.RequestContextMapper)
482489
return handler
483490
}

staging/src/k8s.io/apiserver/pkg/server/genericapiserver_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func setUp(t *testing.T) (*etcdtesting.EtcdTestServer, Config, *assert.Assertion
107107
// },
108108
// }
109109
config.SwaggerConfig = DefaultSwaggerConfig()
110+
config.Complete()
110111

111112
return etcdServer, *config, assert.New(t)
112113
}

0 commit comments

Comments
 (0)