diff --git a/OWNERS b/OWNERS index d75890f90..ee1951992 100644 --- a/OWNERS +++ b/OWNERS @@ -2,7 +2,8 @@ approvers: - pixiake - 24sama - rayzhou2017 - - ImitationImmortal + - liangzai006 + - redscholar reviewers: - pixiake @@ -15,4 +16,5 @@ reviewers: - wansir - LinuxSuRen - 24sama - - ImitationImmortal + - liangzai006 + - redscholar diff --git a/pkg/proxy/api_resources.go b/pkg/proxy/api_resources.go index 626e29e24..5343114a4 100644 --- a/pkg/proxy/api_resources.go +++ b/pkg/proxy/api_resources.go @@ -63,16 +63,28 @@ type resourceOptions struct { } func (o *resourceOptions) init() error { + // prefix for resourcePath. + var prefix string + scoper, ok := o.storage.(apirest.Scoper) + if !ok { + return fmt.Errorf("%q must implement scoper", o.path) + } + if scoper.NamespaceScoped() { + prefix = "/namespaces/{namespace}/" + } else { + prefix = "/" + } + // checks if the given storage path is the path of a subresource switch parts := strings.Split(o.path, "/"); len(parts) { case 2: o.resource, o.subresource = parts[0], parts[1] - o.resourcePath = "/namespaces/{namespace}/" + o.resource - o.itemPath = "/namespaces/{namespace}/" + o.resource + "/{name}" + o.resourcePath = prefix + o.resource + "/{name}/" + o.subresource + o.itemPath = prefix + o.resource + "/{name}/" + o.subresource case 1: o.resource = parts[0] - o.resourcePath = "/namespaces/{namespace}/" + o.resource + "/{name}/" + o.subresource - o.itemPath = "/namespaces/{namespace}/" + o.resource + "/{name}/" + o.subresource + o.resourcePath = prefix + o.resource + o.itemPath = prefix + o.resource + "/{name}" default: return errors.New("api_installer allows only one or two segment paths (resource or resource/subresource)") } diff --git a/pkg/proxy/transport.go b/pkg/proxy/transport.go index e8f76a6a2..d94c1343d 100644 --- a/pkg/proxy/transport.go +++ b/pkg/proxy/transport.go @@ -276,41 +276,32 @@ func (l *transport) registerResources(resources *apiResources) error { return fmt.Errorf("%q must implement TableConvertor", o.path) } - scoper, ok := o.storage.(apirest.Scoper) - if !ok { - return fmt.Errorf("%q must implement scoper", o.path) - } - // Get the list of actions for the given scope. - switch { - case !scoper.NamespaceScoped(): // cluster - // do nothing. The current managed resources are all namespace scope. - default: // namespace - reqScope, err := newReqScope(resources, o, l.authz) - if err != nil { - return err - } - // LIST - l.registerList(resources, reqScope, o) - // POST - l.registerPost(resources, reqScope, o) - // DELETECOLLECTION - l.registerDeleteCollection(resources, reqScope, o) - // DEPRECATED in 1.11 WATCHLIST - l.registerWatchList(resources, reqScope, o) - // GET - l.registerGet(resources, reqScope, o) - // PUT - l.registerPut(resources, reqScope, o) - // PATCH - l.registerPatch(resources, reqScope, o) - // DELETE - l.registerDelete(resources, reqScope, o) - // DEPRECATED in 1.11 WATCH - l.registerWatch(resources, reqScope, o) - // CONNECT - l.registerConnect(resources, reqScope, o) + // namespace + reqScope, err := newReqScope(resources, o, l.authz) + if err != nil { + return err } + // LIST + l.registerList(resources, reqScope, o) + // POST + l.registerPost(resources, reqScope, o) + // DELETECOLLECTION + l.registerDeleteCollection(resources, reqScope, o) + // DEPRECATED in 1.11 WATCHLIST + l.registerWatchList(resources, reqScope, o) + // GET + l.registerGet(resources, reqScope, o) + // PUT + l.registerPut(resources, reqScope, o) + // PATCH + l.registerPatch(resources, reqScope, o) + // DELETE + l.registerDelete(resources, reqScope, o) + // DEPRECATED in 1.11 WATCH + l.registerWatch(resources, reqScope, o) + // CONNECT + l.registerConnect(resources, reqScope, o) } return nil