mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-29 05:22:37 +00:00
remove support enable-disable api resources
This commit is contained in:
parent
da171196d9
commit
64a12258e8
@ -487,15 +487,5 @@ func DefaultAPIResourceConfigSource() *serverstorage.ResourceConfig {
|
|||||||
admissionregistrationv1beta1.SchemeGroupVersion,
|
admissionregistrationv1beta1.SchemeGroupVersion,
|
||||||
)
|
)
|
||||||
|
|
||||||
// all extensions resources except these are disabled by default
|
|
||||||
ret.EnableResources(
|
|
||||||
extensionsapiv1beta1.SchemeGroupVersion.WithResource("daemonsets"),
|
|
||||||
extensionsapiv1beta1.SchemeGroupVersion.WithResource("deployments"),
|
|
||||||
extensionsapiv1beta1.SchemeGroupVersion.WithResource("ingresses"),
|
|
||||||
extensionsapiv1beta1.SchemeGroupVersion.WithResource("networkpolicies"),
|
|
||||||
extensionsapiv1beta1.SchemeGroupVersion.WithResource("replicasets"),
|
|
||||||
extensionsapiv1beta1.SchemeGroupVersion.WithResource("podsecuritypolicies"),
|
|
||||||
)
|
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
type APIResourceConfigSource interface {
|
type APIResourceConfigSource interface {
|
||||||
AnyVersionOfResourceEnabled(resource schema.GroupResource) bool
|
AnyVersionOfResourceEnabled(resource schema.GroupResource) bool
|
||||||
ResourceEnabled(resource schema.GroupVersionResource) bool
|
ResourceEnabled(resource schema.GroupVersionResource) bool
|
||||||
AllResourcesForVersionEnabled(version schema.GroupVersion) bool
|
|
||||||
AnyResourcesForVersionEnabled(version schema.GroupVersion) bool
|
AnyResourcesForVersionEnabled(version schema.GroupVersion) bool
|
||||||
AnyResourcesForGroupEnabled(group string) bool
|
AnyResourcesForGroupEnabled(group string) bool
|
||||||
}
|
}
|
||||||
@ -85,31 +84,6 @@ func (o *ResourceConfig) EnableVersions(versions ...schema.GroupVersion) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ResourceConfig) DisableResources(resources ...schema.GroupVersionResource) {
|
|
||||||
for _, resource := range resources {
|
|
||||||
version := resource.GroupVersion()
|
|
||||||
_, versionExists := o.GroupVersionResourceConfigs[version]
|
|
||||||
if !versionExists {
|
|
||||||
o.GroupVersionResourceConfigs[version] = NewGroupVersionResourceConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
o.GroupVersionResourceConfigs[version].DisabledResources.Insert(resource.Resource)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *ResourceConfig) EnableResources(resources ...schema.GroupVersionResource) {
|
|
||||||
for _, resource := range resources {
|
|
||||||
version := resource.GroupVersion()
|
|
||||||
_, versionExists := o.GroupVersionResourceConfigs[version]
|
|
||||||
if !versionExists {
|
|
||||||
o.GroupVersionResourceConfigs[version] = NewGroupVersionResourceConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
o.GroupVersionResourceConfigs[version].EnabledResources.Insert(resource.Resource)
|
|
||||||
o.GroupVersionResourceConfigs[version].DisabledResources.Delete(resource.Resource)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AnyResourcesForVersionEnabled only considers matches based on exactly group/resource lexical matching. This means that
|
// AnyResourcesForVersionEnabled only considers matches based on exactly group/resource lexical matching. This means that
|
||||||
// resource renames across versions are NOT considered to be the same resource by this method. You'll need to manually check
|
// resource renames across versions are NOT considered to be the same resource by this method. You'll need to manually check
|
||||||
// using the ResourceEnabled function.
|
// using the ResourceEnabled function.
|
||||||
@ -147,22 +121,6 @@ func (o *ResourceConfig) ResourceEnabled(resource schema.GroupVersionResource) b
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ResourceConfig) AllResourcesForVersionEnabled(version schema.GroupVersion) bool {
|
|
||||||
versionOverride, versionExists := o.GroupVersionResourceConfigs[version]
|
|
||||||
if !versionExists {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if !versionOverride.Enable {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(versionOverride.EnabledResources) == 0 && len(versionOverride.DisabledResources) == 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *ResourceConfig) AnyResourcesForVersionEnabled(version schema.GroupVersion) bool {
|
func (o *ResourceConfig) AnyResourcesForVersionEnabled(version schema.GroupVersion) bool {
|
||||||
versionOverride, versionExists := o.GroupVersionResourceConfigs[version]
|
versionOverride, versionExists := o.GroupVersionResourceConfigs[version]
|
||||||
if !versionExists {
|
if !versionExists {
|
||||||
|
@ -26,76 +26,21 @@ func TestDisabledVersion(t *testing.T) {
|
|||||||
g1v1 := schema.GroupVersion{Group: "group1", Version: "version1"}
|
g1v1 := schema.GroupVersion{Group: "group1", Version: "version1"}
|
||||||
g1v2 := schema.GroupVersion{Group: "group1", Version: "version2"}
|
g1v2 := schema.GroupVersion{Group: "group1", Version: "version2"}
|
||||||
g2v1 := schema.GroupVersion{Group: "group2", Version: "version1"}
|
g2v1 := schema.GroupVersion{Group: "group2", Version: "version1"}
|
||||||
g3v1 := schema.GroupVersion{Group: "group3", Version: "version1"}
|
|
||||||
|
|
||||||
resourceType := "the-resource"
|
|
||||||
disabledResourceType := "the-disabled-resource"
|
|
||||||
|
|
||||||
config := NewResourceConfig()
|
config := NewResourceConfig()
|
||||||
|
|
||||||
config.DisableVersions(g1v1)
|
config.DisableVersions(g1v1)
|
||||||
config.EnableVersions(g1v2, g3v1)
|
config.EnableVersions(g1v2, g2v1)
|
||||||
config.EnableResources(g1v1.WithResource(resourceType), g2v1.WithResource(resourceType))
|
|
||||||
config.DisableResources(g1v2.WithResource(disabledResourceType))
|
|
||||||
|
|
||||||
expectedEnabledResources := []schema.GroupVersionResource{
|
if config.AnyResourcesForVersionEnabled(g1v1) {
|
||||||
g1v2.WithResource(resourceType),
|
t.Errorf("expected disabled for %v, from %v", g1v1, config)
|
||||||
g2v1.WithResource(resourceType),
|
|
||||||
}
|
}
|
||||||
expectedDisabledResources := []schema.GroupVersionResource{
|
if !config.AnyResourcesForVersionEnabled(g1v2) {
|
||||||
g1v1.WithResource(resourceType), g1v1.WithResource(disabledResourceType),
|
t.Errorf("expected enabled for %v, from %v", g1v1, config)
|
||||||
g1v2.WithResource(disabledResourceType),
|
|
||||||
g2v1.WithResource(disabledResourceType),
|
|
||||||
}
|
}
|
||||||
|
if !config.AnyResourcesForVersionEnabled(g2v1) {
|
||||||
for _, expectedResource := range expectedEnabledResources {
|
t.Errorf("expected enabled for %v, from %v", g1v1, config)
|
||||||
if !config.ResourceEnabled(expectedResource) {
|
|
||||||
t.Errorf("expected enabled for %v, from %v", expectedResource, config)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for _, expectedResource := range expectedDisabledResources {
|
|
||||||
if config.ResourceEnabled(expectedResource) {
|
|
||||||
t.Errorf("expected disabled for %v, from %v", expectedResource, config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if e, a := false, config.AnyResourcesForVersionEnabled(g1v1); e != a {
|
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
|
||||||
}
|
|
||||||
if e, a := false, config.AllResourcesForVersionEnabled(g1v1); e != a {
|
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
|
||||||
}
|
|
||||||
if e, a := true, config.AnyResourcesForVersionEnabled(g1v2); e != a {
|
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
|
||||||
}
|
|
||||||
if e, a := false, config.AllResourcesForVersionEnabled(g1v2); e != a {
|
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
|
||||||
}
|
|
||||||
if e, a := true, config.AnyResourcesForVersionEnabled(g3v1); e != a {
|
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
|
||||||
}
|
|
||||||
if e, a := true, config.AllResourcesForVersionEnabled(g3v1); e != a {
|
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedEnabledAnyVersionResources := []schema.GroupResource{
|
|
||||||
{Group: "group1", Resource: resourceType},
|
|
||||||
}
|
|
||||||
expectedDisabledAnyResources := []schema.GroupResource{
|
|
||||||
{Group: "group1", Resource: disabledResourceType},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, expectedResource := range expectedEnabledAnyVersionResources {
|
|
||||||
if !config.AnyVersionOfResourceEnabled(expectedResource) {
|
|
||||||
t.Errorf("expected enabled for %v, from %v", expectedResource, config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, expectedResource := range expectedDisabledAnyResources {
|
|
||||||
if config.AnyVersionOfResourceEnabled(expectedResource) {
|
|
||||||
t.Errorf("expected disabled for %v, from %v", expectedResource, config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAnyResourcesForGroupEnabled(t *testing.T) {
|
func TestAnyResourcesForGroupEnabled(t *testing.T) {
|
||||||
@ -136,18 +81,6 @@ func TestAnyResourcesForGroupEnabled(t *testing.T) {
|
|||||||
},
|
},
|
||||||
testGroup: "one",
|
testGroup: "one",
|
||||||
|
|
||||||
expectedResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "present, and one resource",
|
|
||||||
creator: func() APIResourceConfigSource {
|
|
||||||
ret := NewResourceConfig()
|
|
||||||
ret.DisableVersions(schema.GroupVersion{Group: "one", Version: "version1"})
|
|
||||||
ret.EnableResources(schema.GroupVersionResource{Group: "one", Version: "version2", Resource: "foo"})
|
|
||||||
return ret
|
|
||||||
},
|
|
||||||
testGroup: "one",
|
|
||||||
|
|
||||||
expectedResult: true,
|
expectedResult: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user