Add GetterWithOptions and allow stream flushing

In addition to Getter interface, API Installer now supports a
GetterWithOptions interface that takes an additional options object when
getting a resource. A flag is now returned from rest.ResourceStreamer
that indicates whether the streamed response should be
flushed when written back to the client. This is to support log
streaming.
This commit is contained in:
Cesar Wong
2015-04-06 12:58:00 -04:00
parent 6dba6aa178
commit efc7f86baf
5 changed files with 176 additions and 16 deletions

View File

@@ -130,6 +130,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
creater, isCreater := storage.(rest.Creater)
lister, isLister := storage.(rest.Lister)
getter, isGetter := storage.(rest.Getter)
getterWithOptions, isGetterWithOptions := storage.(rest.GetterWithOptions)
deleter, isDeleter := storage.(rest.Deleter)
gracefulDeleter, isGracefulDeleter := storage.(rest.GracefulDeleter)
updater, isUpdater := storage.(rest.Updater)
@@ -170,6 +171,17 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
gracefulDeleter = rest.GracefulDeleteAdapter{deleter}
}
var getOptions runtime.Object
var getOptionsKind string
if isGetterWithOptions {
getOptions = getterWithOptions.NewGetOptions()
_, getOptionsKind, err = a.group.Typer.ObjectVersionAndKind(getOptions)
if err != nil {
return err
}
isGetter = true
}
var ctxFn ContextFunc
ctxFn = func(req *restful.Request) api.Context {
if ctx, ok := context.Get(req.Request); ok {
@@ -316,12 +328,23 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
m := monitorFilter(action.Verb, resource)
switch action.Verb {
case "GET": // Get a resource.
route := ws.GET(action.Path).To(GetResource(getter, reqScope)).
var handler restful.RouteFunction
if isGetterWithOptions {
handler = GetResourceWithOptions(getterWithOptions, reqScope, getOptionsKind)
} else {
handler = GetResource(getter, reqScope)
}
route := ws.GET(action.Path).To(handler).
Filter(m).
Doc("read the specified " + kind).
Operation("read" + kind).
Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...).
Writes(versionedObject)
if isGetterWithOptions {
if err := addObjectParams(ws, route, getOptions); err != nil {
return err
}
}
addParams(route, action.Params)
ws.Route(route)
case "LIST": // List all resources of a kind.