Skip to content

Commit

Permalink
api support lising resources for all namespaces
Browse files Browse the repository at this point in the history
Signed-off-by: Vladik Romanovsky <[email protected]>
  • Loading branch information
vladikr authored and rmohr committed Jul 14, 2017
1 parent 74b99d3 commit 499ebff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/rest/endpoints/decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ func NoopDecoder(_ context.Context, _ *http.Request) (interface{}, error) {
return nil, nil
}

func NotNamespacedDecodeRequestFunc(ctx context.Context, r *http.Request) (interface{}, error) {
headers, err := queryExtractor(ctx, r)
if err != nil {
return nil, err
}
return &Metadata{Headers: *headers}, nil
}

func NamespaceDecodeRequestFunc(ctx context.Context, r *http.Request) (interface{}, error) {
namespace, err := namespaceDecodeRequestFunc(ctx, r)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions pkg/virt-api/rest/kubeproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func GenericResourceProxy(ws *restful.WebService, ctx context.Context, gvr schem
patch := endpoints.NewHandlerBuilder().Patch().Endpoint(NewGenericPatchEndpoint(cli, gvr, objResponseHandler)).Build(ctx)
post := endpoints.NewHandlerBuilder().Post(objPointer).Endpoint(NewGenericPostEndpoint(cli, gvr, objResponseHandler)).Build(ctx)
get := endpoints.NewHandlerBuilder().Get().Endpoint(NewGenericGetEndpoint(cli, gvr, objResponseHandler)).Build(ctx)
getListAllNamespaces := endpoints.NewHandlerBuilder().Get().Endpoint(NewGenericGetListEndpoint(cli, gvr, objListResponseHandler)).Decoder(endpoints.NotNamespacedDecodeRequestFunc).Build(ctx)
getList := endpoints.NewHandlerBuilder().Get().Endpoint(NewGenericGetListEndpoint(cli, gvr, objListResponseHandler)).Decoder(endpoints.NamespaceDecodeRequestFunc).Build(ctx)
deleteList := endpoints.NewHandlerBuilder().Delete().Endpoint(NewGenericDeleteListEndpoint(cli, gvr, objListResponseHandler)).Decoder(endpoints.NamespaceDecodeRequestFunc).Build(ctx)

Expand Down Expand Up @@ -109,6 +110,12 @@ func GenericResourceProxy(ws *restful.WebService, ctx context.Context, gvr schem
To(endpoints.MakeGoRestfulWrapper(get)).Writes(objExample).Doc("test4"), ws,
))

ws.Route(addGetAllNamespacesListParams(
ws.GET(gvr.Resource).
Produces(mime.MIME_JSON, mime.MIME_YAML).
To(endpoints.MakeGoRestfulWrapper(getListAllNamespaces)).Writes(listExample).Doc("test4"), ws,
))

ws.Route(
ws.PATCH(ResourcePath(gvr)).
Produces(mime.MIME_JSON_PATCH).
Expand Down Expand Up @@ -162,6 +169,12 @@ func addWatchGetListParams(builder *restful.RouteBuilder, ws *restful.WebService
Param(ws.QueryParameter("timeoutSeconds", "TimeoutSeconds for the list/watch call.").DataType("int"))
}

func addGetAllNamespacesListParams(builder *restful.RouteBuilder, ws *restful.WebService) *restful.RouteBuilder {
return builder.Param(fieldSelectorParam(ws)).Param(labelSelectorParam(ws)).
Param(ws.QueryParameter("resourceVersion", "When specified with a watch call, shows changes that occur after that particular version of a resource. Defaults to changes from the beginning of history.")).
Param(ws.QueryParameter("timeoutSeconds", "TimeoutSeconds for the list/watch call.").DataType("int"))
}

func addDeleteListParams(builder *restful.RouteBuilder, ws *restful.WebService) *restful.RouteBuilder {
return builder.Param(NameParam(ws)).Param(fieldSelectorParam(ws)).Param(labelSelectorParam(ws))
}
Expand Down

0 comments on commit 499ebff

Please sign in to comment.