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
99248b8f
Commit
99248b8f
authored
Sep 14, 2018
by
Wenjia Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite finalURLTemplate used only for metrics because of dynamic client change
parent
7bfd0d35
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
10 deletions
+55
-10
request.go
staging/src/k8s.io/client-go/rest/request.go
+55
-10
request_test.go
staging/src/k8s.io/client-go/rest/request_test.go
+0
-0
No files found.
staging/src/k8s.io/client-go/rest/request.go
View file @
99248b8f
...
@@ -455,17 +455,9 @@ func (r *Request) URL() *url.URL {
...
@@ -455,17 +455,9 @@ func (r *Request) URL() *url.URL {
// finalURLTemplate is similar to URL(), but will make all specific parameter values equal
// finalURLTemplate is similar to URL(), but will make all specific parameter values equal
// - instead of name or namespace, "{name}" and "{namespace}" will be used, and all query
// - instead of name or namespace, "{name}" and "{namespace}" will be used, and all query
// parameters will be reset. This creates a copy of the request so as not to change the
// parameters will be reset. This creates a copy of the url so as not to change the
// underlying object. This means some useful request info (like the types of field
// underlying object.
// selectors in use) will be lost.
// TODO: preserve field selector keys
func
(
r
Request
)
finalURLTemplate
()
url
.
URL
{
func
(
r
Request
)
finalURLTemplate
()
url
.
URL
{
if
len
(
r
.
resourceName
)
!=
0
{
r
.
resourceName
=
"{name}"
}
if
r
.
namespaceSet
&&
len
(
r
.
namespace
)
!=
0
{
r
.
namespace
=
"{namespace}"
}
newParams
:=
url
.
Values
{}
newParams
:=
url
.
Values
{}
v
:=
[]
string
{
"{value}"
}
v
:=
[]
string
{
"{value}"
}
for
k
:=
range
r
.
params
{
for
k
:=
range
r
.
params
{
...
@@ -473,6 +465,59 @@ func (r Request) finalURLTemplate() url.URL {
...
@@ -473,6 +465,59 @@ func (r Request) finalURLTemplate() url.URL {
}
}
r
.
params
=
newParams
r
.
params
=
newParams
url
:=
r
.
URL
()
url
:=
r
.
URL
()
segments
:=
strings
.
Split
(
r
.
URL
()
.
Path
,
"/"
)
groupIndex
:=
0
index
:=
0
if
r
.
URL
()
!=
nil
&&
r
.
baseURL
!=
nil
&&
strings
.
Contains
(
r
.
URL
()
.
Path
,
r
.
baseURL
.
Path
)
{
groupIndex
+=
len
(
strings
.
Split
(
r
.
baseURL
.
Path
,
"/"
))
}
if
groupIndex
>=
len
(
segments
)
{
return
*
url
}
const
CoreGroupPrefix
=
"api"
const
NamedGroupPrefix
=
"apis"
isCoreGroup
:=
segments
[
groupIndex
]
==
CoreGroupPrefix
isNamedGroup
:=
segments
[
groupIndex
]
==
NamedGroupPrefix
if
isCoreGroup
{
// checking the case of core group with /api/v1/... format
index
=
groupIndex
+
2
}
else
if
isNamedGroup
{
// checking the case of named group with /apis/apps/v1/... format
index
=
groupIndex
+
3
}
else
{
// this should not happen that the only two possibilities are /api... and /apis..., just want to put an
// outlet here in case more API groups are added in future if ever possible:
// https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-groups
// if a wrong API groups name is encountered, return the {prefix} for url.Path
url
.
Path
=
"/{prefix}"
url
.
RawQuery
=
""
return
*
url
}
//switch segLength := len(segments) - index; segLength {
switch
{
// case len(segments) - index == 1:
// resource (with no name) do nothing
case
len
(
segments
)
-
index
==
2
:
// /$RESOURCE/$NAME: replace $NAME with {name}
segments
[
index
+
1
]
=
"{name}"
case
len
(
segments
)
-
index
==
3
:
if
segments
[
index
+
2
]
==
"finalize"
||
segments
[
index
+
2
]
==
"status"
{
// /$RESOURCE/$NAME/$SUBRESOURCE: replace $NAME with {name}
segments
[
index
+
1
]
=
"{name}"
}
else
{
// /namespace/$NAMESPACE/$RESOURCE: replace $NAMESPACE with {namespace}
segments
[
index
+
1
]
=
"{namespace}"
}
case
len
(
segments
)
-
index
>=
4
:
segments
[
index
+
1
]
=
"{namespace}"
// /namespace/$NAMESPACE/$RESOURCE/$NAME: replace $NAMESPACE with {namespace}, $NAME with {name}
if
segments
[
index
+
3
]
!=
"finalize"
&&
segments
[
index
+
3
]
!=
"status"
{
// /$RESOURCE/$NAME/$SUBRESOURCE: replace $NAME with {name}
segments
[
index
+
3
]
=
"{name}"
}
}
url
.
Path
=
path
.
Join
(
segments
...
)
return
*
url
return
*
url
}
}
...
...
staging/src/k8s.io/client-go/rest/request_test.go
View file @
99248b8f
This diff is collapsed.
Click to expand it.
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