K8s: Add subresource to the example apiserver (#78030)

This commit is contained in:
Ryan McKinley
2023-11-13 19:51:58 -08:00
committed by GitHub
parent a2a6f9a6d8
commit 1be1432926
16 changed files with 844 additions and 168 deletions

View File

@@ -42,16 +42,12 @@ type APIRouteHandler struct {
Handler http.HandlerFunc // when Level = resource, the resource will be available in context
}
// APIRoutes define the
// APIRoutes define explicit HTTP handlers in an apiserver
// TBD: is this actually necessary -- there may be more k8s native options for this
type APIRoutes struct {
// Root handlers are registered directly after the apiVersion identifier
Root []APIRouteHandler
// Namespace handlers are mounted under the namespace
Namespace []APIRouteHandler
// Resource routes behave the same as pod/logs
// it looks like a sub-resource, however the response is backed directly by an http handler
// The current resource can be fetched through context
Resource map[string]APIRouteHandler
}

View File

@@ -71,22 +71,6 @@ func getAPIHandler(delegateHandler http.Handler, restConfig *restclient.Config,
sub.HandleFunc(route.Path, route.Handler).
Methods(methods...)
}
// getter := makeGetter(restConfig)
for resource, route := range routes.Resource {
err = validPath(route.Path)
if err != nil {
return nil, err
}
fmt.Printf("TODO: %s/%v\n", resource, route)
// get a client for that resource kind
//getter := makeGetter(restConfig)
useful = true
// sub.HandleFunc(v.Slug, SubresourceHandlerWrapper(v.Handler, getter)).
// Methods(methods...)
}
}
if !useful {
@@ -184,12 +168,6 @@ func getOpenAPIPostProcessor(builders []APIGroupBuilder) func(*spec3.OpenAPI) (*
}
}
for resource, route := range routes.Resource {
copy.Paths.Paths[prefix+"/namespaces/{namespace}/"+resource+"{name}"+route.Path] = &spec3.Path{
PathProps: *route.Spec,
}
}
return &copy, nil
}
}