Skip to content

Commit

Permalink
enable batch/v2alpha1 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soltysh committed May 10, 2016
1 parent df11a51 commit a31ca0d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 52 deletions.
2 changes: 1 addition & 1 deletion hack/test-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
# Lists of API Versions of each groups that should be tested, groups are
# separated by comma, lists are separated by semicolon. e.g.,
# "v1,compute/v1alpha1,experimental/v1alpha2;v1,compute/v2,experimental/v1alpha3"
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1,metrics/v1alpha1,federation/v1alpha1;v1,autoscaling/v1,batch/v1,extensions/v1beta1,apps/v1alpha1,metrics/v1alpha1,federation/v1alpha1,policy/v1alpha1"}
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1,metrics/v1alpha1,federation/v1alpha1;v1,autoscaling/v1,batch/v1,batch/v2alpha1,extensions/v1beta1,apps/v1alpha1,metrics/v1alpha1,federation/v1alpha1,policy/v1alpha1"}
# once we have multiple group supports
# Run tests with the standard (registry) and a custom etcd prefix
# (kubernetes.io/registry).
Expand Down
106 changes: 62 additions & 44 deletions pkg/api/testapi/testapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ var (
)

type TestGroup struct {
externalGroupVersion unversioned.GroupVersion
internalGroupVersion unversioned.GroupVersion
internalTypes map[string]reflect.Type
// the first element in the group is meant to be the preferred version
externalGroupVersions []unversioned.GroupVersion
internalGroupVersion unversioned.GroupVersion
internalTypes map[string]reflect.Type
}

func init() {
Expand Down Expand Up @@ -100,26 +101,31 @@ func init() {
}

internalGroupVersion := unversioned.GroupVersion{Group: groupVersion.Group, Version: runtime.APIVersionInternal}
Groups[groupVersion.Group] = TestGroup{
externalGroupVersion: groupVersion,
internalGroupVersion: internalGroupVersion,
internalTypes: api.Scheme.KnownTypes(internalGroupVersion),
if group, ok := Groups[groupVersion.Group]; !ok {
Groups[groupVersion.Group] = TestGroup{
externalGroupVersions: []unversioned.GroupVersion{groupVersion},
internalGroupVersion: internalGroupVersion,
internalTypes: api.Scheme.KnownTypes(internalGroupVersion),
}
} else {
group.externalGroupVersions = append(group.externalGroupVersions, groupVersion)
Groups[groupVersion.Group] = group
}
}
}

if _, ok := Groups[api.GroupName]; !ok {
Groups[api.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: api.GroupName, Version: registered.GroupOrDie(api.GroupName).GroupVersion.Version},
internalGroupVersion: api.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(api.SchemeGroupVersion),
externalGroupVersions: []unversioned.GroupVersion{{Group: api.GroupName, Version: registered.GroupOrDie(api.GroupName).GroupVersion.Version}},
internalGroupVersion: api.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(api.SchemeGroupVersion),
}
}
if _, ok := Groups[extensions.GroupName]; !ok {
Groups[extensions.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: extensions.GroupName, Version: registered.GroupOrDie(extensions.GroupName).GroupVersion.Version},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(extensions.SchemeGroupVersion),
externalGroupVersions: []unversioned.GroupVersion{{Group: extensions.GroupName, Version: registered.GroupOrDie(extensions.GroupName).GroupVersion.Version}},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(extensions.SchemeGroupVersion),
}
}
if _, ok := Groups[autoscaling.GroupName]; !ok {
Expand All @@ -131,9 +137,9 @@ func init() {
internalTypes[k] = t
}
Groups[autoscaling.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: autoscaling.GroupName, Version: registered.GroupOrDie(autoscaling.GroupName).GroupVersion.Version},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: internalTypes,
externalGroupVersions: []unversioned.GroupVersion{{Group: autoscaling.GroupName, Version: registered.GroupOrDie(autoscaling.GroupName).GroupVersion.Version}},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: internalTypes,
}
}
if _, ok := Groups[autoscaling.GroupName+"IntraGroup"]; !ok {
Expand All @@ -145,30 +151,34 @@ func init() {
}
}
Groups[autoscaling.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: autoscaling.GroupName, Version: registered.GroupOrDie(autoscaling.GroupName).GroupVersion.Version},
internalGroupVersion: autoscaling.SchemeGroupVersion,
internalTypes: internalTypes,
externalGroupVersions: []unversioned.GroupVersion{{Group: autoscaling.GroupName, Version: registered.GroupOrDie(autoscaling.GroupName).GroupVersion.Version}},
internalGroupVersion: autoscaling.SchemeGroupVersion,
internalTypes: internalTypes,
}
}
if _, ok := Groups[batch.GroupName]; !ok {
var gvs []unversioned.GroupVersion
for _, gv := range registered.GroupOrDie(batch.GroupName).GroupVersions {
gvs = append(gvs, gv)
}
Groups[batch.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: batch.GroupName, Version: registered.GroupOrDie(batch.GroupName).GroupVersion.Version},
internalGroupVersion: batch.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(batch.SchemeGroupVersion),
externalGroupVersions: gvs,
internalGroupVersion: batch.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(batch.SchemeGroupVersion),
}
}
if _, ok := Groups[apps.GroupName]; !ok {
Groups[apps.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: apps.GroupName, Version: registered.GroupOrDie(apps.GroupName).GroupVersion.Version},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(extensions.SchemeGroupVersion),
externalGroupVersions: []unversioned.GroupVersion{{Group: apps.GroupName, Version: registered.GroupOrDie(apps.GroupName).GroupVersion.Version}},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(extensions.SchemeGroupVersion),
}
}
if _, ok := Groups[federation.GroupName]; !ok {
Groups[federation.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: federation.GroupName, Version: registered.GroupOrDie(federation.GroupName).GroupVersion.Version},
internalGroupVersion: federation.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(federation.SchemeGroupVersion),
externalGroupVersions: []unversioned.GroupVersion{{Group: federation.GroupName, Version: registered.GroupOrDie(federation.GroupName).GroupVersion.Version}},
internalGroupVersion: federation.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(federation.SchemeGroupVersion),
}
}

Expand All @@ -185,10 +195,14 @@ func (g TestGroup) ContentConfig() (string, *unversioned.GroupVersion, runtime.C
}

func (g TestGroup) GroupVersion() *unversioned.GroupVersion {
copyOfGroupVersion := g.externalGroupVersion
copyOfGroupVersion := g.externalGroupVersions[0]
return &copyOfGroupVersion
}

func (g TestGroup) GroupVersions() []unversioned.GroupVersion {
return append([]unversioned.GroupVersion{}, g.externalGroupVersions...)
}

// InternalGroupVersion returns the group,version used to identify the internal
// types for this API
func (g TestGroup) InternalGroupVersion() unversioned.GroupVersion {
Expand All @@ -204,9 +218,9 @@ func (g TestGroup) InternalTypes() map[string]reflect.Type {
// KUBE_TEST_API_TYPE env var.
func (g TestGroup) Codec() runtime.Codec {
if serializer.Serializer == nil {
return api.Codecs.LegacyCodec(g.externalGroupVersion)
return api.Codecs.LegacyCodec(g.externalGroupVersions[0])
}
return api.Codecs.CodecForVersions(serializer, api.Codecs.UniversalDeserializer(), []unversioned.GroupVersion{g.externalGroupVersion}, nil)
return api.Codecs.CodecForVersions(serializer, api.Codecs.UniversalDeserializer(), g.externalGroupVersions, nil)
}

// NegotiatedSerializer returns the negotiated serializer for the server.
Expand All @@ -224,7 +238,7 @@ func (g TestGroup) StorageCodec() runtime.Codec {
s := storageSerializer.Serializer

if s == nil {
return api.Codecs.LegacyCodec(g.externalGroupVersion)
return api.Codecs.LegacyCodec(g.externalGroupVersions[0])
}

// etcd2 only supports string data - we must wrap any result before returning
Expand All @@ -234,13 +248,13 @@ func (g TestGroup) StorageCodec() runtime.Codec {
}
ds := recognizer.NewDecoder(s, api.Codecs.UniversalDeserializer())

return api.Codecs.CodecForVersions(s, ds, []unversioned.GroupVersion{g.externalGroupVersion}, nil)
return api.Codecs.CodecForVersions(s, ds, g.externalGroupVersions, nil)
}

// Converter returns the api.Scheme for the API version to test against, as set by the
// KUBE_TEST_API env var.
func (g TestGroup) Converter() runtime.ObjectConvertor {
interfaces, err := registered.GroupOrDie(g.externalGroupVersion.Group).InterfacesFor(g.externalGroupVersion)
interfaces, err := registered.GroupOrDie(g.externalGroupVersions[0].Group).InterfacesFor(g.externalGroupVersions[0])
if err != nil {
panic(err)
}
Expand All @@ -250,7 +264,7 @@ func (g TestGroup) Converter() runtime.ObjectConvertor {
// MetadataAccessor returns the MetadataAccessor for the API version to test against,
// as set by the KUBE_TEST_API env var.
func (g TestGroup) MetadataAccessor() meta.MetadataAccessor {
interfaces, err := registered.GroupOrDie(g.externalGroupVersion.Group).InterfacesFor(g.externalGroupVersion)
interfaces, err := registered.GroupOrDie(g.externalGroupVersions[0].Group).InterfacesFor(g.externalGroupVersions[0])
if err != nil {
panic(err)
}
Expand All @@ -261,18 +275,18 @@ func (g TestGroup) MetadataAccessor() meta.MetadataAccessor {
// 'resource' should be the resource path, e.g. "pods" for the Pod type. 'name' should be
// empty for lists.
func (g TestGroup) SelfLink(resource, name string) string {
if g.externalGroupVersion.Group == api.GroupName {
if g.externalGroupVersions[0].Group == api.GroupName {
if name == "" {
return fmt.Sprintf("/api/%s/%s", g.externalGroupVersion.Version, resource)
return fmt.Sprintf("/api/%s/%s", g.externalGroupVersions[0].Version, resource)
}
return fmt.Sprintf("/api/%s/%s/%s", g.externalGroupVersion.Version, resource, name)
return fmt.Sprintf("/api/%s/%s/%s", g.externalGroupVersions[0].Version, resource, name)
} else {
// TODO: will need a /apis prefix once we have proper multi-group
// support
if name == "" {
return fmt.Sprintf("/apis/%s/%s/%s", g.externalGroupVersion.Group, g.externalGroupVersion.Version, resource)
return fmt.Sprintf("/apis/%s/%s/%s", g.externalGroupVersions[0].Group, g.externalGroupVersions[0].Version, resource)
}
return fmt.Sprintf("/apis/%s/%s/%s/%s", g.externalGroupVersion.Group, g.externalGroupVersion.Version, resource, name)
return fmt.Sprintf("/apis/%s/%s/%s/%s", g.externalGroupVersions[0].Group, g.externalGroupVersions[0].Version, resource, name)
}
}

Expand All @@ -281,12 +295,12 @@ func (g TestGroup) SelfLink(resource, name string) string {
// /api/v1/watch/namespaces/foo/pods/pod0 for v1.
func (g TestGroup) ResourcePathWithPrefix(prefix, resource, namespace, name string) string {
var path string
if g.externalGroupVersion.Group == api.GroupName {
path = "/api/" + g.externalGroupVersion.Version
if g.externalGroupVersions[0].Group == api.GroupName {
path = "/api/" + g.externalGroupVersions[0].Version
} else {
// TODO: switch back once we have proper multiple group support
// path = "/apis/" + g.Group + "/" + Version(group...)
path = "/apis/" + g.externalGroupVersion.Group + "/" + g.externalGroupVersion.Version
path = "/apis/" + g.externalGroupVersions[0].Group + "/" + g.externalGroupVersions[0].Version
}

if prefix != "" {
Expand Down Expand Up @@ -355,5 +369,9 @@ func GetCodecForObject(obj runtime.Object) (runtime.Codec, error) {
}

func NewTestGroup(external, internal unversioned.GroupVersion, internalTypes map[string]reflect.Type) TestGroup {
return TestGroup{external, internal, internalTypes}
return TestGroup{
externalGroupVersions: []unversioned.GroupVersion{external},
internalGroupVersion: internal,
internalTypes: internalTypes,
}
}
20 changes: 13 additions & 7 deletions pkg/master/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
autoscalingapiv1 "k8s.io/kubernetes/pkg/apis/autoscaling/v1"
"k8s.io/kubernetes/pkg/apis/batch"
batchapiv1 "k8s.io/kubernetes/pkg/apis/batch/v1"
batchapiv2alpha1 "k8s.io/kubernetes/pkg/apis/batch/v2alpha1"
"k8s.io/kubernetes/pkg/apis/extensions"
extensionsapiv1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
"k8s.io/kubernetes/pkg/apiserver"
Expand Down Expand Up @@ -128,7 +129,9 @@ func newMaster(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *ass
// limitedAPIResourceConfigSource only enables the core group, the extensions group, the batch group, and the autoscaling group.
func limitedAPIResourceConfigSource() *genericapiserver.ResourceConfig {
ret := genericapiserver.NewResourceConfig()
ret.EnableVersions(apiv1.SchemeGroupVersion, extensionsapiv1beta1.SchemeGroupVersion, batchapiv1.SchemeGroupVersion, appsapi.SchemeGroupVersion, autoscalingapiv1.SchemeGroupVersion)
ret.EnableVersions(apiv1.SchemeGroupVersion, extensionsapiv1beta1.SchemeGroupVersion,
batchapiv1.SchemeGroupVersion, batchapiv2alpha1.SchemeGroupVersion,
appsapi.SchemeGroupVersion, autoscalingapiv1.SchemeGroupVersion)
return ret
}

Expand Down Expand Up @@ -423,12 +426,6 @@ func TestDiscoveryAtAPIS(t *testing.T) {
Version: testapi.Autoscaling.GroupVersion().Version,
},
},
batch.GroupName: {
{
GroupVersion: testapi.Batch.GroupVersion().String(),
Version: testapi.Batch.GroupVersion().Version,
},
},
apps.GroupName: {
{
GroupVersion: testapi.Apps.GroupVersion().String(),
Expand All @@ -442,6 +439,15 @@ func TestDiscoveryAtAPIS(t *testing.T) {
},
},
}
var batchVersions []unversioned.GroupVersionForDiscovery
for _, gv := range testapi.Batch.GroupVersions() {
batchVersions = append(batchVersions, unversioned.GroupVersionForDiscovery{
GroupVersion: gv.String(),
Version: gv.Version,
})
}
expectVersions[batch.GroupName] = batchVersions

expectPreferredVersion := map[string]unversioned.GroupVersionForDiscovery{
autoscaling.GroupName: {
GroupVersion: registered.GroupOrDie(autoscaling.GroupName).GroupVersion.String(),
Expand Down

0 comments on commit a31ca0d

Please sign in to comment.