Slide 13
Slide 13 text
google_l Open Source
Request Handling
CreateResource handles
the HTTP request…
…including
deserialization,
conversion, and
defaulting…
…and writing out to
storage
// apiserver/pkg/endpoints/handlers/create.go
func createHandler(r rest.NamedCreater, scope *RequestScope, admit admission.Interface, includeName bool)
http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
… // deal with tracing, dry-run, namespace, timouts
decoder := scope.Serializer.DecoderToVersion(s.Serializer, scope.HubGroupVersion)
body, err := limitedReadBody(req, scope.MaxRequestBodyBytes)
… // retrieve query params and validate create options
obj, gvk, err := decoder.Decode(body, &defaultGVK, original)
admissionAttributes := admission.NewAttributesRecord(obj, nil, scope.Kind, namespace, name,
scope.Resource, scope.Subresource, admission.Create, options, dryrun.IsDryRun(options.DryRun), userInfo)
requestFunc := func() (runtime.Object, error) {
return r.Create(ctx, name, obj,
rest.AdmissionToValidateObjectFunc(admit, admissionAttributes, scope),
options,
)
}
result, err := finishRequest(timeout, func() (runtime.Object, error) {
if mutatingAdmission, ok := admit.(admission.MutationInterface); ok &&
mutatingAdmission.Handles(admission.Create) {
if err := mutatingAdmission.Admit(ctx, admissionAttributes, scope); err !=
nil {
return nil, err
}
}
result, err := requestFunc()
return result, err
})
code := http.StatusCreated
transformResponseObject(ctx, scope, trace, req, w, code, outputMediaType, result)
}
}