Merge pull request #27242 from smarterclayton/discovery_prefix

Automatic merge from submit-queue

Make discovery client parameterizable to legacy prefix
This commit is contained in:
k8s-merge-robot 2016-06-25 17:26:05 -07:00 committed by GitHub
commit cbab337b99

View File

@ -81,6 +81,8 @@ type SwaggerSchemaInterface interface {
// versions and resources. // versions and resources.
type DiscoveryClient struct { type DiscoveryClient struct {
*restclient.RESTClient *restclient.RESTClient
LegacyPrefix string
} }
// Convert unversioned.APIVersions to unversioned.APIGroup. APIVersions is used by legacy v1, so // Convert unversioned.APIVersions to unversioned.APIGroup. APIVersions is used by legacy v1, so
@ -105,7 +107,7 @@ func apiVersionsToAPIGroup(apiVersions *unversioned.APIVersions) (apiGroup unver
func (d *DiscoveryClient) ServerGroups() (apiGroupList *unversioned.APIGroupList, err error) { func (d *DiscoveryClient) ServerGroups() (apiGroupList *unversioned.APIGroupList, err error) {
// Get the groupVersions exposed at /api // Get the groupVersions exposed at /api
v := &unversioned.APIVersions{} v := &unversioned.APIVersions{}
err = d.Get().AbsPath("/api").Do().Into(v) err = d.Get().AbsPath(d.LegacyPrefix).Do().Into(v)
apiGroup := unversioned.APIGroup{} apiGroup := unversioned.APIGroup{}
if err == nil { if err == nil {
apiGroup = apiVersionsToAPIGroup(v) apiGroup = apiVersionsToAPIGroup(v)
@ -135,8 +137,9 @@ func (d *DiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (r
url := url.URL{} url := url.URL{}
if len(groupVersion) == 0 { if len(groupVersion) == 0 {
return nil, fmt.Errorf("groupVersion shouldn't be empty") return nil, fmt.Errorf("groupVersion shouldn't be empty")
} else if groupVersion == "v1" { }
url.Path = "/api/" + groupVersion if len(d.LegacyPrefix) > 0 && groupVersion == "v1" {
url.Path = d.LegacyPrefix + "/" + groupVersion
} else { } else {
url.Path = "/apis/" + groupVersion url.Path = "/apis/" + groupVersion
} }
@ -245,8 +248,8 @@ func (d *DiscoveryClient) SwaggerSchema(version unversioned.GroupVersion) (*swag
return nil, fmt.Errorf("API version: %v is not supported by the server. Use one of: %v", version, groupVersions) return nil, fmt.Errorf("API version: %v is not supported by the server. Use one of: %v", version, groupVersions)
} }
var path string var path string
if version == v1.SchemeGroupVersion { if len(d.LegacyPrefix) > 0 && version == v1.SchemeGroupVersion {
path = "/swaggerapi/api/" + version.Version path = "/swaggerapi" + d.LegacyPrefix + "/" + version.Version
} else { } else {
path = "/swaggerapi/apis/" + version.Group + "/" + version.Version path = "/swaggerapi/apis/" + version.Group + "/" + version.Version
} }
@ -285,7 +288,7 @@ func NewDiscoveryClientForConfig(c *restclient.Config) (*DiscoveryClient, error)
return nil, err return nil, err
} }
client, err := restclient.UnversionedRESTClientFor(&config) client, err := restclient.UnversionedRESTClientFor(&config)
return &DiscoveryClient{client}, err return &DiscoveryClient{RESTClient: client, LegacyPrefix: "/api"}, err
} }
// NewDiscoveryClientForConfig creates a new DiscoveryClient for the given config. If // NewDiscoveryClientForConfig creates a new DiscoveryClient for the given config. If
@ -301,7 +304,7 @@ func NewDiscoveryClientForConfigOrDie(c *restclient.Config) *DiscoveryClient {
// New creates a new DiscoveryClient for the given RESTClient. // New creates a new DiscoveryClient for the given RESTClient.
func NewDiscoveryClient(c *restclient.RESTClient) *DiscoveryClient { func NewDiscoveryClient(c *restclient.RESTClient) *DiscoveryClient {
return &DiscoveryClient{c} return &DiscoveryClient{RESTClient: c, LegacyPrefix: "/api"}
} }
func stringDoesntExistIn(str string, slice []string) bool { func stringDoesntExistIn(str string, slice []string) bool {