Skip to content

Commit

Permalink
fix: error local router. (#2388)
Browse files Browse the repository at this point in the history
Signed-off-by: joyceliu <[email protected]>
Co-authored-by: joyceliu <[email protected]>
  • Loading branch information
redscholar and joyceliu authored Sep 4, 2024
1 parent 1504786 commit 658023c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
6 changes: 4 additions & 2 deletions OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ approvers:
- pixiake
- 24sama
- rayzhou2017
- ImitationImmortal
- liangzai006
- redscholar

reviewers:
- pixiake
Expand All @@ -15,4 +16,5 @@ reviewers:
- wansir
- LinuxSuRen
- 24sama
- ImitationImmortal
- liangzai006
- redscholar
20 changes: 16 additions & 4 deletions pkg/proxy/api_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
Expand Down
57 changes: 24 additions & 33 deletions pkg/proxy/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 658023c

Please sign in to comment.