Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f670cc46
Unverified
Commit
f670cc46
authored
May 21, 2016
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid multiple allocations during selfLink generation
parent
25a2a7d2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
api_installer.go
pkg/apiserver/api_installer.go
+14
-7
api_installer_test.go
pkg/apiserver/api_installer_test.go
+3
-1
No files found.
pkg/apiserver/api_installer.go
View file @
f670cc46
...
@@ -390,18 +390,26 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -390,18 +390,26 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
resourcePath
:=
namespacedPath
resourcePath
:=
namespacedPath
resourceParams
:=
namespaceParams
resourceParams
:=
namespaceParams
itemPathPrefix
:=
gpath
.
Join
(
a
.
prefix
,
scope
.
ParamName
())
+
"/"
itemPath
:=
namespacedPath
+
"/{name}"
itemPath
:=
namespacedPath
+
"/{name}"
itemPathMiddle
:=
"/"
+
resource
+
"/"
nameParams
:=
append
(
namespaceParams
,
nameParam
)
nameParams
:=
append
(
namespaceParams
,
nameParam
)
proxyParams
:=
append
(
nameParams
,
pathParam
)
proxyParams
:=
append
(
nameParams
,
pathParam
)
itemPathSuffix
:=
""
if
hasSubresource
{
if
hasSubresource
{
itemPath
=
itemPath
+
"/"
+
subresource
itemPathSuffix
=
"/"
+
subresource
itemPath
=
itemPath
+
itemPathSuffix
resourcePath
=
itemPath
resourcePath
=
itemPath
resourceParams
=
nameParams
resourceParams
=
nameParams
}
}
apiResource
.
Name
=
path
apiResource
.
Name
=
path
apiResource
.
Namespaced
=
true
apiResource
.
Namespaced
=
true
apiResource
.
Kind
=
resourceKind
apiResource
.
Kind
=
resourceKind
namer
:=
scopeNaming
{
scope
,
a
.
group
.
Linker
,
gpath
.
Join
(
a
.
prefix
,
itemPath
),
false
}
itemPathFn
:=
func
(
name
,
namespace
string
)
string
{
return
itemPathPrefix
+
namespace
+
itemPathMiddle
+
name
+
itemPathSuffix
}
namer
:=
scopeNaming
{
scope
,
a
.
group
.
Linker
,
itemPathFn
,
false
}
actions
=
appendIf
(
actions
,
action
{
"LIST"
,
resourcePath
,
resourceParams
,
namer
},
isLister
)
actions
=
appendIf
(
actions
,
action
{
"LIST"
,
resourcePath
,
resourceParams
,
namer
},
isLister
)
actions
=
appendIf
(
actions
,
action
{
"POST"
,
resourcePath
,
resourceParams
,
namer
},
isCreater
)
actions
=
appendIf
(
actions
,
action
{
"POST"
,
resourcePath
,
resourceParams
,
namer
},
isCreater
)
...
@@ -430,7 +438,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -430,7 +438,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
// For ex: LIST all pods in all namespaces by sending a LIST request at /api/apiVersion/pods.
// For ex: LIST all pods in all namespaces by sending a LIST request at /api/apiVersion/pods.
// TODO: more strongly type whether a resource allows these actions on "all namespaces" (bulk delete)
// TODO: more strongly type whether a resource allows these actions on "all namespaces" (bulk delete)
if
!
hasSubresource
{
if
!
hasSubresource
{
namer
=
scopeNaming
{
scope
,
a
.
group
.
Linker
,
gpath
.
Join
(
a
.
prefix
,
itemPath
)
,
true
}
namer
=
scopeNaming
{
scope
,
a
.
group
.
Linker
,
itemPathFn
,
true
}
actions
=
appendIf
(
actions
,
action
{
"LIST"
,
resource
,
params
,
namer
},
isLister
)
actions
=
appendIf
(
actions
,
action
{
"LIST"
,
resource
,
params
,
namer
},
isLister
)
actions
=
appendIf
(
actions
,
action
{
"WATCHLIST"
,
"watch/"
+
resource
,
params
,
namer
},
allowWatchList
)
actions
=
appendIf
(
actions
,
action
{
"WATCHLIST"
,
"watch/"
+
resource
,
params
,
namer
},
allowWatchList
)
}
}
...
@@ -775,7 +783,7 @@ func (n rootScopeNaming) ObjectName(obj runtime.Object) (namespace, name string,
...
@@ -775,7 +783,7 @@ func (n rootScopeNaming) ObjectName(obj runtime.Object) (namespace, name string,
type
scopeNaming
struct
{
type
scopeNaming
struct
{
scope
meta
.
RESTScope
scope
meta
.
RESTScope
runtime
.
SelfLinker
runtime
.
SelfLinker
itemPath
string
itemPath
Fn
func
(
name
,
namespace
string
)
string
allNamespaces
bool
allNamespaces
bool
}
}
...
@@ -822,9 +830,8 @@ func (n scopeNaming) GenerateLink(req *restful.Request, obj runtime.Object) (pat
...
@@ -822,9 +830,8 @@ func (n scopeNaming) GenerateLink(req *restful.Request, obj runtime.Object) (pat
if
len
(
name
)
==
0
{
if
len
(
name
)
==
0
{
return
""
,
""
,
errEmptyName
return
""
,
""
,
errEmptyName
}
}
path
=
strings
.
Replace
(
n
.
itemPath
,
"{name}"
,
name
,
1
)
path
=
strings
.
Replace
(
path
,
"{"
+
n
.
scope
.
ArgumentName
()
+
"}"
,
namespace
,
1
)
return
n
.
itemPathFn
(
name
,
namespace
),
""
,
nil
return
path
,
""
,
nil
}
}
// GenerateListLink returns the appropriate path and query to locate a list by its canonical path.
// GenerateListLink returns the appropriate path and query to locate a list by its canonical path.
...
...
pkg/apiserver/api_installer_test.go
View file @
f670cc46
...
@@ -36,7 +36,9 @@ func TestScopeNamingGenerateLink(t *testing.T) {
...
@@ -36,7 +36,9 @@ func TestScopeNamingGenerateLink(t *testing.T) {
s
:=
scopeNaming
{
s
:=
scopeNaming
{
meta
.
RESTScopeNamespace
,
meta
.
RESTScopeNamespace
,
selfLinker
,
selfLinker
,
"/api/v1/namespaces/{namespace}/services/{name}"
,
func
(
name
,
namespace
string
)
string
{
return
"/api/v1/namespaces/"
+
namespace
+
"/services/"
+
name
},
true
,
true
,
}
}
service
:=
&
api
.
Service
{
service
:=
&
api
.
Service
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment