mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-05 17:10:27 +00:00
Use absolute path instead requestURI in openapiv3 discovery (#117495)
Currently, openapiv3 discovery uses requestURI to discover resources. However, that does not work when the rest endpoint contains prefixes (e.g. `http://localhost/test-endpoint/`). Because requestURI overwrites prefixes also in rest endpoint (e.g. `http://localhost/openapiv3/apis/apps/v1`). Since `absPath` keeps the prefixes in the rest endpoint, this PR changes to absPath instead requestURI. Kubernetes-commit: d94c733ee2bfaedd9a1c45d58fbd56c99403c94d
This commit is contained in:
committed by
Kubernetes Publisher
parent
f775857c5d
commit
fc96cec338
@@ -19,6 +19,7 @@ package openapi
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/kube-openapi/pkg/handler3"
|
||||
@@ -58,7 +59,11 @@ func (c *client) Paths() (map[string]GroupVersion, error) {
|
||||
// Create GroupVersions for each element of the result
|
||||
result := map[string]GroupVersion{}
|
||||
for k, v := range discoMap.Paths {
|
||||
result[k] = newGroupVersion(c, v)
|
||||
// If the server returned a URL rooted at /openapi/v3, preserve any additional client-side prefix.
|
||||
// If the server returned a URL not rooted at /openapi/v3, treat it as an actual server-relative URL.
|
||||
// See https://github.com/kubernetes/kubernetes/issues/117463 for details
|
||||
useClientPrefix := strings.HasPrefix(v.ServerRelativeURL, "/openapi/v3")
|
||||
result[k] = newGroupVersion(c, v, useClientPrefix)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user