mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Remove unnecessary typer from create/update handlers
This commit is contained in:
parent
bbfa29921c
commit
5e23dd0517
@ -240,9 +240,9 @@ func (r *crdHandler) serveResource(w http.ResponseWriter, req *http.Request, req
|
|||||||
http.Error(w, fmt.Sprintf("%v not allowed while CustomResourceDefinition is terminating", requestInfo.Verb), http.StatusMethodNotAllowed)
|
http.Error(w, fmt.Sprintf("%v not allowed while CustomResourceDefinition is terminating", requestInfo.Verb), http.StatusMethodNotAllowed)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return handlers.CreateResource(storage, requestScope, discovery.NewUnstructuredObjectTyper(nil), r.admission)
|
return handlers.CreateResource(storage, requestScope, r.admission)
|
||||||
case "update":
|
case "update":
|
||||||
return handlers.UpdateResource(storage, requestScope, discovery.NewUnstructuredObjectTyper(nil), r.admission)
|
return handlers.UpdateResource(storage, requestScope, r.admission)
|
||||||
case "patch":
|
case "patch":
|
||||||
return handlers.PatchResource(storage, requestScope, r.admission, unstructured.UnstructuredObjectConverter{}, supportedTypes)
|
return handlers.PatchResource(storage, requestScope, r.admission, unstructured.UnstructuredObjectConverter{}, supportedTypes)
|
||||||
case "delete":
|
case "delete":
|
||||||
@ -265,7 +265,7 @@ func (r *crdHandler) serveStatus(w http.ResponseWriter, req *http.Request, reque
|
|||||||
case "get":
|
case "get":
|
||||||
return handlers.GetResource(storage, nil, requestScope)
|
return handlers.GetResource(storage, nil, requestScope)
|
||||||
case "update":
|
case "update":
|
||||||
return handlers.UpdateResource(storage, requestScope, discovery.NewUnstructuredObjectTyper(nil), r.admission)
|
return handlers.UpdateResource(storage, requestScope, r.admission)
|
||||||
case "patch":
|
case "patch":
|
||||||
return handlers.PatchResource(storage, requestScope, r.admission, unstructured.UnstructuredObjectConverter{}, supportedTypes)
|
return handlers.PatchResource(storage, requestScope, r.admission, unstructured.UnstructuredObjectConverter{}, supportedTypes)
|
||||||
default:
|
default:
|
||||||
@ -282,7 +282,7 @@ func (r *crdHandler) serveScale(w http.ResponseWriter, req *http.Request, reques
|
|||||||
case "get":
|
case "get":
|
||||||
return handlers.GetResource(storage, nil, requestScope)
|
return handlers.GetResource(storage, nil, requestScope)
|
||||||
case "update":
|
case "update":
|
||||||
return handlers.UpdateResource(storage, requestScope, discovery.NewUnstructuredObjectTyper(nil), r.admission)
|
return handlers.UpdateResource(storage, requestScope, r.admission)
|
||||||
case "patch":
|
case "patch":
|
||||||
return handlers.PatchResource(storage, requestScope, r.admission, unstructured.UnstructuredObjectConverter{}, supportedTypes)
|
return handlers.PatchResource(storage, requestScope, r.admission, unstructured.UnstructuredObjectConverter{}, supportedTypes)
|
||||||
default:
|
default:
|
||||||
|
@ -34,7 +34,7 @@ import (
|
|||||||
utiltrace "k8s.io/apiserver/pkg/util/trace"
|
utiltrace "k8s.io/apiserver/pkg/util/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.ObjectTyper, admit admission.Interface, includeName bool) http.HandlerFunc {
|
func createHandler(r rest.NamedCreater, scope RequestScope, admit admission.Interface, includeName bool) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, req *http.Request) {
|
return func(w http.ResponseWriter, req *http.Request) {
|
||||||
// For performance tracking purposes.
|
// For performance tracking purposes.
|
||||||
trace := utiltrace.New("Create " + req.URL.Path)
|
trace := utiltrace.New("Create " + req.URL.Path)
|
||||||
@ -79,7 +79,7 @@ func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.Object
|
|||||||
trace.Step("About to convert to expected version")
|
trace.Step("About to convert to expected version")
|
||||||
obj, gvk, err := decoder.Decode(body, &defaultGVK, original)
|
obj, gvk, err := decoder.Decode(body, &defaultGVK, original)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = transformDecodeError(typer, err, original, gvk, body)
|
err = transformDecodeError(scope.Typer, err, original, gvk, body)
|
||||||
scope.err(err, w, req)
|
scope.err(err, w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -150,13 +150,13 @@ func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.Object
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateNamedResource returns a function that will handle a resource creation with name.
|
// CreateNamedResource returns a function that will handle a resource creation with name.
|
||||||
func CreateNamedResource(r rest.NamedCreater, scope RequestScope, typer runtime.ObjectTyper, admission admission.Interface) http.HandlerFunc {
|
func CreateNamedResource(r rest.NamedCreater, scope RequestScope, admission admission.Interface) http.HandlerFunc {
|
||||||
return createHandler(r, scope, typer, admission, true)
|
return createHandler(r, scope, admission, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateResource returns a function that will handle a resource creation.
|
// CreateResource returns a function that will handle a resource creation.
|
||||||
func CreateResource(r rest.Creater, scope RequestScope, typer runtime.ObjectTyper, admission admission.Interface) http.HandlerFunc {
|
func CreateResource(r rest.Creater, scope RequestScope, admission admission.Interface) http.HandlerFunc {
|
||||||
return createHandler(&namedCreaterAdapter{r}, scope, typer, admission, false)
|
return createHandler(&namedCreaterAdapter{r}, scope, admission, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
type namedCreaterAdapter struct {
|
type namedCreaterAdapter struct {
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// UpdateResource returns a function that will handle a resource update
|
// UpdateResource returns a function that will handle a resource update
|
||||||
func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectTyper, admit admission.Interface) http.HandlerFunc {
|
func UpdateResource(r rest.Updater, scope RequestScope, admit admission.Interface) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, req *http.Request) {
|
return func(w http.ResponseWriter, req *http.Request) {
|
||||||
// For performance tracking purposes.
|
// For performance tracking purposes.
|
||||||
trace := utiltrace.New("Update " + req.URL.Path)
|
trace := utiltrace.New("Update " + req.URL.Path)
|
||||||
@ -67,7 +67,7 @@ func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectType
|
|||||||
decoder := scope.Serializer.DecoderToVersion(s.Serializer, schema.GroupVersion{Group: defaultGVK.Group, Version: runtime.APIVersionInternal})
|
decoder := scope.Serializer.DecoderToVersion(s.Serializer, schema.GroupVersion{Group: defaultGVK.Group, Version: runtime.APIVersionInternal})
|
||||||
obj, gvk, err := decoder.Decode(body, &defaultGVK, original)
|
obj, gvk, err := decoder.Decode(body, &defaultGVK, original)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = transformDecodeError(typer, err, original, gvk, body)
|
err = transformDecodeError(scope.Typer, err, original, gvk, body)
|
||||||
scope.err(err, w, req)
|
scope.err(err, w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -646,7 +646,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||||||
if hasSubresource {
|
if hasSubresource {
|
||||||
doc = "replace " + subresource + " of the specified " + kind
|
doc = "replace " + subresource + " of the specified " + kind
|
||||||
}
|
}
|
||||||
handler := metrics.InstrumentRouteFunc(action.Verb, resource, subresource, requestScope, restfulUpdateResource(updater, reqScope, a.group.Typer, admit))
|
handler := metrics.InstrumentRouteFunc(action.Verb, resource, subresource, requestScope, restfulUpdateResource(updater, reqScope, admit))
|
||||||
route := ws.PUT(action.Path).To(handler).
|
route := ws.PUT(action.Path).To(handler).
|
||||||
Doc(doc).
|
Doc(doc).
|
||||||
Param(ws.QueryParameter("pretty", "If 'true', then the output is pretty printed.")).
|
Param(ws.QueryParameter("pretty", "If 'true', then the output is pretty printed.")).
|
||||||
@ -685,9 +685,9 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||||||
case "POST": // Create a resource.
|
case "POST": // Create a resource.
|
||||||
var handler restful.RouteFunction
|
var handler restful.RouteFunction
|
||||||
if isNamedCreater {
|
if isNamedCreater {
|
||||||
handler = restfulCreateNamedResource(namedCreater, reqScope, a.group.Typer, admit)
|
handler = restfulCreateNamedResource(namedCreater, reqScope, admit)
|
||||||
} else {
|
} else {
|
||||||
handler = restfulCreateResource(creater, reqScope, a.group.Typer, admit)
|
handler = restfulCreateResource(creater, reqScope, admit)
|
||||||
}
|
}
|
||||||
handler = metrics.InstrumentRouteFunc(action.Verb, resource, subresource, requestScope, handler)
|
handler = metrics.InstrumentRouteFunc(action.Verb, resource, subresource, requestScope, handler)
|
||||||
article := getArticleForNoun(kind, " ")
|
article := getArticleForNoun(kind, " ")
|
||||||
@ -1016,15 +1016,15 @@ func restfulListResource(r rest.Lister, rw rest.Watcher, scope handlers.RequestS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func restfulCreateNamedResource(r rest.NamedCreater, scope handlers.RequestScope, typer runtime.ObjectTyper, admit admission.Interface) restful.RouteFunction {
|
func restfulCreateNamedResource(r rest.NamedCreater, scope handlers.RequestScope, admit admission.Interface) restful.RouteFunction {
|
||||||
return func(req *restful.Request, res *restful.Response) {
|
return func(req *restful.Request, res *restful.Response) {
|
||||||
handlers.CreateNamedResource(r, scope, typer, admit)(res.ResponseWriter, req.Request)
|
handlers.CreateNamedResource(r, scope, admit)(res.ResponseWriter, req.Request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func restfulCreateResource(r rest.Creater, scope handlers.RequestScope, typer runtime.ObjectTyper, admit admission.Interface) restful.RouteFunction {
|
func restfulCreateResource(r rest.Creater, scope handlers.RequestScope, admit admission.Interface) restful.RouteFunction {
|
||||||
return func(req *restful.Request, res *restful.Response) {
|
return func(req *restful.Request, res *restful.Response) {
|
||||||
handlers.CreateResource(r, scope, typer, admit)(res.ResponseWriter, req.Request)
|
handlers.CreateResource(r, scope, admit)(res.ResponseWriter, req.Request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1040,9 +1040,9 @@ func restfulDeleteCollection(r rest.CollectionDeleter, checkBody bool, scope han
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func restfulUpdateResource(r rest.Updater, scope handlers.RequestScope, typer runtime.ObjectTyper, admit admission.Interface) restful.RouteFunction {
|
func restfulUpdateResource(r rest.Updater, scope handlers.RequestScope, admit admission.Interface) restful.RouteFunction {
|
||||||
return func(req *restful.Request, res *restful.Response) {
|
return func(req *restful.Request, res *restful.Response) {
|
||||||
handlers.UpdateResource(r, scope, typer, admit)(res.ResponseWriter, req.Request)
|
handlers.UpdateResource(r, scope, admit)(res.ResponseWriter, req.Request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user