Merge pull request #15808 from caesarxuchao/fix-kubectl-explain

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot
2015-10-21 07:04:32 -07:00
3 changed files with 49 additions and 17 deletions

View File

@@ -26,7 +26,6 @@ import (
"github.com/emicklei/go-restful/swagger"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/version"
)
@@ -184,26 +183,32 @@ func (c *Client) ValidateComponents() (*api.ComponentStatusList, error) {
// SwaggerSchemaInterface has a method to retrieve the swagger schema. Used in
// client.Interface
type SwaggerSchemaInterface interface {
SwaggerSchema(version string) (*swagger.ApiDeclaration, error)
SwaggerSchema(groupVersion string) (*swagger.ApiDeclaration, error)
}
// SwaggerSchema retrieves and parses the swagger API schema the server supports.
func (c *Client) SwaggerSchema(version string) (*swagger.ApiDeclaration, error) {
if version == "" {
version = latest.GroupOrDie("").Version
func (c *Client) SwaggerSchema(groupVersion string) (*swagger.ApiDeclaration, error) {
if groupVersion == "" {
return nil, fmt.Errorf("groupVersion cannot be empty")
}
vers, err := c.ServerAPIVersions()
groupList, err := c.Discovery().ServerGroups()
if err != nil {
return nil, err
}
groupVersions := extractGroupVersions(groupList)
// This check also takes care the case that kubectl is newer than the running endpoint
if stringDoesntExistIn(version, vers.Versions) {
return nil, fmt.Errorf("API version: %s is not supported by the server. Use one of: %v", version, vers.Versions)
if stringDoesntExistIn(groupVersion, groupVersions) {
return nil, fmt.Errorf("API version: %s is not supported by the server. Use one of: %v", groupVersion, groupVersions)
}
var path string
if groupVersion == "v1" {
path = "/swaggerapi/api/" + groupVersion
} else {
path = "/swaggerapi/apis/" + groupVersion
}
body, err := c.Get().AbsPath("/swaggerapi/api/" + version).Do().Raw()
body, err := c.Get().AbsPath(path).Do().Raw()
if err != nil {
return nil, err
}