mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
client-go/rest: check if url is nil to prevent nil pointer dereference
Signed-off-by: André Martins <aanm90@gmail.com>
This commit is contained in:
parent
f8f190cdd2
commit
94e7b2b8fd
@ -519,14 +519,17 @@ func (r Request) finalURLTemplate() url.URL {
|
|||||||
newParams[k] = v
|
newParams[k] = v
|
||||||
}
|
}
|
||||||
r.params = newParams
|
r.params = newParams
|
||||||
url := r.URL()
|
u := r.URL()
|
||||||
|
if u == nil {
|
||||||
|
return url.URL{}
|
||||||
|
}
|
||||||
|
|
||||||
segments := strings.Split(url.Path, "/")
|
segments := strings.Split(u.Path, "/")
|
||||||
groupIndex := 0
|
groupIndex := 0
|
||||||
index := 0
|
index := 0
|
||||||
trimmedBasePath := ""
|
trimmedBasePath := ""
|
||||||
if url != nil && r.c.base != nil && strings.Contains(url.Path, r.c.base.Path) {
|
if r.c.base != nil && strings.Contains(u.Path, r.c.base.Path) {
|
||||||
p := strings.TrimPrefix(url.Path, r.c.base.Path)
|
p := strings.TrimPrefix(u.Path, r.c.base.Path)
|
||||||
if !strings.HasPrefix(p, "/") {
|
if !strings.HasPrefix(p, "/") {
|
||||||
p = "/" + p
|
p = "/" + p
|
||||||
}
|
}
|
||||||
@ -537,7 +540,7 @@ func (r Request) finalURLTemplate() url.URL {
|
|||||||
groupIndex = 1
|
groupIndex = 1
|
||||||
}
|
}
|
||||||
if len(segments) <= 2 {
|
if len(segments) <= 2 {
|
||||||
return *url
|
return *u
|
||||||
}
|
}
|
||||||
|
|
||||||
const CoreGroupPrefix = "api"
|
const CoreGroupPrefix = "api"
|
||||||
@ -555,11 +558,11 @@ func (r Request) finalURLTemplate() url.URL {
|
|||||||
// outlet here in case more API groups are added in future if ever possible:
|
// outlet here in case more API groups are added in future if ever possible:
|
||||||
// https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-groups
|
// https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-groups
|
||||||
// if a wrong API groups name is encountered, return the {prefix} for url.Path
|
// if a wrong API groups name is encountered, return the {prefix} for url.Path
|
||||||
url.Path = "/{prefix}"
|
u.Path = "/{prefix}"
|
||||||
url.RawQuery = ""
|
u.RawQuery = ""
|
||||||
return *url
|
return *u
|
||||||
}
|
}
|
||||||
//switch segLength := len(segments) - index; segLength {
|
// switch segLength := len(segments) - index; segLength {
|
||||||
switch {
|
switch {
|
||||||
// case len(segments) - index == 1:
|
// case len(segments) - index == 1:
|
||||||
// resource (with no name) do nothing
|
// resource (with no name) do nothing
|
||||||
@ -582,8 +585,8 @@ func (r Request) finalURLTemplate() url.URL {
|
|||||||
segments[index+3] = "{name}"
|
segments[index+3] = "{name}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
url.Path = path.Join(trimmedBasePath, path.Join(segments...))
|
u.Path = path.Join(trimmedBasePath, path.Join(segments...))
|
||||||
return *url
|
return *u
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Request) tryThrottleWithInfo(ctx context.Context, retryInfo string) error {
|
func (r *Request) tryThrottleWithInfo(ctx context.Context, retryInfo string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user