Provide more helpful error when using unsupported api version

This commit is contained in:
feihujiang 2015-06-27 15:27:16 +08:00
parent 712f303350
commit 878a72228f
2 changed files with 8 additions and 0 deletions

View File

@ -29,6 +29,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/registered"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
@ -267,6 +268,9 @@ func (c *clientSwaggerSchema) ValidateBytes(data []byte) error {
if err != nil {
return err
}
if ok := registered.IsRegisteredAPIVersion(version); !ok {
return fmt.Errorf("API version %q isn't supported, only supports API versions %q", version, registered.RegisteredVersions)
}
schemaData, err := c.c.RESTClient.Get().
AbsPath("/swaggerapi/api", version).
Do().

View File

@ -21,6 +21,7 @@ import (
"reflect"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/registered"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/yaml"
)
@ -46,6 +47,9 @@ func (m *Mapper) InfoForData(data []byte, source string) (*Info, error) {
if err != nil {
return nil, fmt.Errorf("unable to get type info from %q: %v", source, err)
}
if ok := registered.IsRegisteredAPIVersion(version); !ok {
return nil, fmt.Errorf("API version %q in %q isn't supported, only supports API versions %q", version, source, registered.RegisteredVersions)
}
if kind == "" {
return nil, fmt.Errorf("kind not set in %q", source)
}