Commit 27bb99d4 authored by k8s-merge-robot's avatar k8s-merge-robot Committed by GitHub

Merge pull request #27554 from deads2k/allow-new-groups

Automatic merge from submit-queue make addition group RESTStorage registration easier Starts factoring out `RESTStorage` creation to eventually allow for decoupled API group `RESTStorage` configuration. Right now you can't add additional groups without modifying the main API Group registration in master.go. Allows the `master.Config` to hold a function that can build a `RESTStorage` based on the `Master` struct. @lavalamp @caesarxuchao @kubernetes/sig-api-machinery @liggitt @smarterclayton
parents 5299e05b 6f7007af
...@@ -26,6 +26,14 @@ ...@@ -26,6 +26,14 @@
"description": "get information of a group" "description": "get information of a group"
}, },
{ {
"path": "/apis/apps/v1alpha1",
"description": "API at /apis/apps/v1alpha1"
},
{
"path": "/apis/apps",
"description": "get information of a group"
},
{
"path": "/apis/autoscaling/v1", "path": "/apis/autoscaling/v1",
"description": "API at /apis/autoscaling/v1" "description": "API at /apis/autoscaling/v1"
}, },
...@@ -46,27 +54,19 @@ ...@@ -46,27 +54,19 @@
"description": "get information of a group" "description": "get information of a group"
}, },
{ {
"path": "/apis/policy/v1alpha1", "path": "/apis/certificates/v1alpha1",
"description": "API at /apis/policy/v1alpha1" "description": "API at /apis/certificates/v1alpha1"
},
{
"path": "/apis/policy",
"description": "get information of a group"
},
{
"path": "/apis/apps/v1alpha1",
"description": "API at /apis/apps/v1alpha1"
}, },
{ {
"path": "/apis/apps", "path": "/apis/certificates",
"description": "get information of a group" "description": "get information of a group"
}, },
{ {
"path": "/apis/certificates/v1alpha1", "path": "/apis/policy/v1alpha1",
"description": "API at /apis/certificates/v1alpha1" "description": "API at /apis/policy/v1alpha1"
}, },
{ {
"path": "/apis/certificates", "path": "/apis/policy",
"description": "get information of a group" "description": "get information of a group"
}, },
{ {
......
...@@ -27,6 +27,7 @@ type APIResourceConfigSource interface { ...@@ -27,6 +27,7 @@ type APIResourceConfigSource interface {
ResourceEnabled(resource unversioned.GroupVersionResource) bool ResourceEnabled(resource unversioned.GroupVersionResource) bool
AllResourcesForVersionEnabled(version unversioned.GroupVersion) bool AllResourcesForVersionEnabled(version unversioned.GroupVersion) bool
AnyResourcesForVersionEnabled(version unversioned.GroupVersion) bool AnyResourcesForVersionEnabled(version unversioned.GroupVersion) bool
AnyResourcesForGroupEnabled(group string) bool
} }
// Specifies the overrides for various API group versions. // Specifies the overrides for various API group versions.
...@@ -170,3 +171,15 @@ func (o *ResourceConfig) AnyResourcesForVersionEnabled(version unversioned.Group ...@@ -170,3 +171,15 @@ func (o *ResourceConfig) AnyResourcesForVersionEnabled(version unversioned.Group
return versionOverride.Enable return versionOverride.Enable
} }
func (o *ResourceConfig) AnyResourcesForGroupEnabled(group string) bool {
for version := range o.GroupVersionResourceConfigs {
if version.Group == group {
if o.AnyResourcesForVersionEnabled(version) {
return true
}
}
}
return false
}
...@@ -97,3 +97,64 @@ func TestDisabledVersion(t *testing.T) { ...@@ -97,3 +97,64 @@ func TestDisabledVersion(t *testing.T) {
} }
} }
func TestAnyResourcesForGroupEnabled(t *testing.T) {
tests := []struct {
name string
creator func() APIResourceConfigSource
testGroup string
expectedResult bool
}{
{
name: "empty",
creator: func() APIResourceConfigSource {
return NewResourceConfig()
},
testGroup: "one",
expectedResult: false,
},
{
name: "present, but disabled",
creator: func() APIResourceConfigSource {
ret := NewResourceConfig()
ret.DisableVersions(unversioned.GroupVersion{Group: "one", Version: "version1"})
return ret
},
testGroup: "one",
expectedResult: false,
},
{
name: "present, and one version enabled",
creator: func() APIResourceConfigSource {
ret := NewResourceConfig()
ret.DisableVersions(unversioned.GroupVersion{Group: "one", Version: "version1"})
ret.EnableVersions(unversioned.GroupVersion{Group: "one", Version: "version2"})
return ret
},
testGroup: "one",
expectedResult: true,
},
{
name: "present, and one resource",
creator: func() APIResourceConfigSource {
ret := NewResourceConfig()
ret.DisableVersions(unversioned.GroupVersion{Group: "one", Version: "version1"})
ret.EnableResources(unversioned.GroupVersionResource{Group: "one", Version: "version2", Resource: "foo"})
return ret
},
testGroup: "one",
expectedResult: true,
},
}
for _, tc := range tests {
if e, a := tc.expectedResult, tc.creator().AnyResourcesForGroupEnabled(tc.testGroup); e != a {
t.Errorf("%s: expected %v, got %v", tc.name, e, a)
}
}
}
...@@ -136,9 +136,14 @@ func newMaster(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *ass ...@@ -136,9 +136,14 @@ 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. // limitedAPIResourceConfigSource only enables the core group, the extensions group, the batch group, and the autoscaling group.
func limitedAPIResourceConfigSource() *genericapiserver.ResourceConfig { func limitedAPIResourceConfigSource() *genericapiserver.ResourceConfig {
ret := genericapiserver.NewResourceConfig() ret := genericapiserver.NewResourceConfig()
ret.EnableVersions(apiv1.SchemeGroupVersion, extensionsapiv1beta1.SchemeGroupVersion, ret.EnableVersions(
batchapiv1.SchemeGroupVersion, batchapiv2alpha1.SchemeGroupVersion, apiv1.SchemeGroupVersion,
appsapi.SchemeGroupVersion, autoscalingapiv1.SchemeGroupVersion) extensionsapiv1beta1.SchemeGroupVersion,
batchapiv1.SchemeGroupVersion,
batchapiv2alpha1.SchemeGroupVersion,
appsapi.SchemeGroupVersion,
autoscalingapiv1.SchemeGroupVersion,
)
return ret return ret
} }
...@@ -493,7 +498,7 @@ func TestDiscoveryAtAPIS(t *testing.T) { ...@@ -493,7 +498,7 @@ func TestDiscoveryAtAPIS(t *testing.T) {
}, },
} }
assert.Equal(3, len(groupList.Groups)) assert.Equal(4, len(groupList.Groups))
for _, group := range groupList.Groups { for _, group := range groupList.Groups {
if !expectGroupNames.Has(group.Name) { if !expectGroupNames.Has(group.Name) {
t.Errorf("got unexpected group %s", group.Name) t.Errorf("got unexpected group %s", group.Name)
...@@ -520,7 +525,7 @@ func TestDiscoveryAtAPIS(t *testing.T) { ...@@ -520,7 +525,7 @@ func TestDiscoveryAtAPIS(t *testing.T) {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
assert.Equal(4, len(groupList.Groups)) assert.Equal(5, len(groupList.Groups))
expectGroupNames.Insert("company.com") expectGroupNames.Insert("company.com")
expectVersions["company.com"] = []unversioned.GroupVersionForDiscovery{thirdPartyGV} expectVersions["company.com"] = []unversioned.GroupVersionForDiscovery{thirdPartyGV}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment