mirror of https://github.com/k3s-io/k3s
Merge pull request #63031 from jennybuckley/dedup-update-typer
Automatic merge from submit-queue (batch tested with PRs 62937, 63105, 63031, 63174). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Remove unnecessary typer from create/update handlers **What this PR does / why we need it**: Refactoring to remove unnecessarily duplicated definition of an ObjectTyper for some of the handlers. The patch handler also has an extra ObjectConvertor, but it is defined differently in both places so removing one would possibly have side effects. ```release-note NONE ``` /sig api-machinerypull/8/head
commit
8d1b6fa917
|
@ -232,9 +232,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)
|
||||
return nil
|
||||
}
|
||||
return handlers.CreateResource(storage, requestScope, discovery.NewUnstructuredObjectTyper(nil), r.admission)
|
||||
return handlers.CreateResource(storage, requestScope, r.admission)
|
||||
case "update":
|
||||
return handlers.UpdateResource(storage, requestScope, discovery.NewUnstructuredObjectTyper(nil), r.admission)
|
||||
return handlers.UpdateResource(storage, requestScope, r.admission)
|
||||
case "patch":
|
||||
return handlers.PatchResource(storage, requestScope, r.admission, unstructured.UnstructuredObjectConverter{}, supportedTypes)
|
||||
case "delete":
|
||||
|
@ -257,7 +257,7 @@ func (r *crdHandler) serveStatus(w http.ResponseWriter, req *http.Request, reque
|
|||
case "get":
|
||||
return handlers.GetResource(storage, nil, requestScope)
|
||||
case "update":
|
||||
return handlers.UpdateResource(storage, requestScope, discovery.NewUnstructuredObjectTyper(nil), r.admission)
|
||||
return handlers.UpdateResource(storage, requestScope, r.admission)
|
||||
case "patch":
|
||||
return handlers.PatchResource(storage, requestScope, r.admission, unstructured.UnstructuredObjectConverter{}, supportedTypes)
|
||||
default:
|
||||
|
@ -274,7 +274,7 @@ func (r *crdHandler) serveScale(w http.ResponseWriter, req *http.Request, reques
|
|||
case "get":
|
||||
return handlers.GetResource(storage, nil, requestScope)
|
||||
case "update":
|
||||
return handlers.UpdateResource(storage, requestScope, discovery.NewUnstructuredObjectTyper(nil), r.admission)
|
||||
return handlers.UpdateResource(storage, requestScope, r.admission)
|
||||
case "patch":
|
||||
return handlers.PatchResource(storage, requestScope, r.admission, unstructured.UnstructuredObjectConverter{}, supportedTypes)
|
||||
default:
|
||||
|
|
|
@ -35,7 +35,7 @@ import (
|
|||
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) {
|
||||
// For performance tracking purposes.
|
||||
trace := utiltrace.New("Create " + req.URL.Path)
|
||||
|
@ -80,7 +80,7 @@ func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.Object
|
|||
trace.Step("About to convert to expected version")
|
||||
obj, gvk, err := decoder.Decode(body, &defaultGVK, original)
|
||||
if err != nil {
|
||||
err = transformDecodeError(typer, err, original, gvk, body)
|
||||
err = transformDecodeError(scope.Typer, err, original, gvk, body)
|
||||
scope.err(err, w, req)
|
||||
return
|
||||
}
|
||||
|
@ -151,13 +151,13 @@ func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.Object
|
|||
}
|
||||
|
||||
// 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 {
|
||||
return createHandler(r, scope, typer, admission, true)
|
||||
func CreateNamedResource(r rest.NamedCreater, scope RequestScope, admission admission.Interface) http.HandlerFunc {
|
||||
return createHandler(r, scope, admission, true)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return createHandler(&namedCreaterAdapter{r}, scope, typer, admission, false)
|
||||
func CreateResource(r rest.Creater, scope RequestScope, admission admission.Interface) http.HandlerFunc {
|
||||
return createHandler(&namedCreaterAdapter{r}, scope, admission, false)
|
||||
}
|
||||
|
||||
type namedCreaterAdapter struct {
|
||||
|
|
|
@ -34,7 +34,7 @@ import (
|
|||
)
|
||||
|
||||
// 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) {
|
||||
// For performance tracking purposes.
|
||||
trace := utiltrace.New("Update " + req.URL.Path)
|
||||
|
@ -68,7 +68,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})
|
||||
obj, gvk, err := decoder.Decode(body, &defaultGVK, original)
|
||||
if err != nil {
|
||||
err = transformDecodeError(typer, err, original, gvk, body)
|
||||
err = transformDecodeError(scope.Typer, err, original, gvk, body)
|
||||
scope.err(err, w, req)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -605,7 +605,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||
if hasSubresource {
|
||||
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).
|
||||
Doc(doc).
|
||||
Param(ws.QueryParameter("pretty", "If 'true', then the output is pretty printed.")).
|
||||
|
@ -644,9 +644,9 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||
case "POST": // Create a resource.
|
||||
var handler restful.RouteFunction
|
||||
if isNamedCreater {
|
||||
handler = restfulCreateNamedResource(namedCreater, reqScope, a.group.Typer, admit)
|
||||
handler = restfulCreateNamedResource(namedCreater, reqScope, admit)
|
||||
} else {
|
||||
handler = restfulCreateResource(creater, reqScope, a.group.Typer, admit)
|
||||
handler = restfulCreateResource(creater, reqScope, admit)
|
||||
}
|
||||
handler = metrics.InstrumentRouteFunc(action.Verb, resource, subresource, requestScope, handler)
|
||||
article := getArticleForNoun(kind, " ")
|
||||
|
@ -975,15 +975,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) {
|
||||
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) {
|
||||
handlers.CreateResource(r, scope, typer, admit)(res.ResponseWriter, req.Request)
|
||||
handlers.CreateResource(r, scope, admit)(res.ResponseWriter, req.Request)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -999,9 +999,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) {
|
||||
handlers.UpdateResource(r, scope, typer, admit)(res.ResponseWriter, req.Request)
|
||||
handlers.UpdateResource(r, scope, admit)(res.ResponseWriter, req.Request)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue