Merge pull request #63075 from deads2k/api-05-eliminate-indirection
Automatic merge from submit-queue (batch tested with PRs 62982, 63075, 63067, 62877, 63141). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. eliminate indirection from type registration Some years back there was a partial attempt to revamp api type registration, but the effort was never completed and this was before we started splitting schemes. With separate schemes, the idea of partial registration no longer makes sense. This pull starts removing cruft from the registration process and pulls out a layer of indirection that isn't needed. @kubernetes/sig-api-machinery-pr-reviews @lavalamp @cheftako @sttts @smarterclayton Rebase cost is fairly high, so I'd like to avoid this lingering. /assign @sttts /assign @cheftako ```release-note NONE ``` Kubernetes-commit: 97287177ee2b603f13f1028ef7f053f4795351f7
This commit is contained in:
commit
b2357e53fc
File diff suppressed because it is too large
Load Diff
|
@ -27,7 +27,7 @@ import (
|
|||
)
|
||||
|
||||
// Install registers the API group and adds types to a scheme
|
||||
func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
|
||||
func Install(registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
|
||||
if err := announced.NewGroupMetaFactory(
|
||||
&announced.GroupMetaFactoryArgs{
|
||||
GroupName: webhookadmission.GroupName,
|
||||
|
@ -37,7 +37,7 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
|
|||
announced.VersionToSchemeFunc{
|
||||
v1alpha1.SchemeGroupVersion.Version: v1alpha1.AddToScheme,
|
||||
},
|
||||
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
|
||||
).Register(registry, scheme); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
)
|
||||
|
||||
// Install registers the API group and adds types to a scheme
|
||||
func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
|
||||
func Install(registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
|
||||
if err := announced.NewGroupMetaFactory(
|
||||
&announced.GroupMetaFactoryArgs{
|
||||
GroupName: apiserver.GroupName,
|
||||
|
@ -37,7 +37,7 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
|
|||
announced.VersionToSchemeFunc{
|
||||
v1alpha1.SchemeGroupVersion.Version: v1alpha1.AddToScheme,
|
||||
},
|
||||
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
|
||||
).Register(registry, scheme); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
)
|
||||
|
||||
// Install registers the API group and adds types to a scheme
|
||||
func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
|
||||
func Install(registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
|
||||
if err := announced.NewGroupMetaFactory(
|
||||
&announced.GroupMetaFactoryArgs{
|
||||
GroupName: audit.GroupName,
|
||||
|
@ -42,7 +42,7 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
|
|||
v1beta1.SchemeGroupVersion.Version: v1beta1.AddToScheme,
|
||||
v1alpha1.SchemeGroupVersion.Version: v1alpha1.AddToScheme,
|
||||
},
|
||||
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
|
||||
).Register(registry, scheme); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
)
|
||||
|
||||
// Install registers the API group and adds types to a scheme
|
||||
func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
|
||||
func Install(registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
|
||||
if err := announced.NewGroupMetaFactory(
|
||||
&announced.GroupMetaFactoryArgs{
|
||||
GroupName: example.GroupName,
|
||||
|
@ -37,7 +37,7 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
|
|||
announced.VersionToSchemeFunc{
|
||||
examplev1.SchemeGroupVersion.Version: examplev1.AddToScheme,
|
||||
},
|
||||
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
|
||||
).Register(registry, scheme); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import (
|
|||
)
|
||||
|
||||
// Install registers the API group and adds types to a scheme
|
||||
func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
|
||||
func Install(registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
|
||||
if err := announced.NewGroupMetaFactory(
|
||||
&announced.GroupMetaFactoryArgs{
|
||||
GroupName: example2.GroupName,
|
||||
|
@ -38,7 +38,7 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
|
|||
announced.VersionToSchemeFunc{
|
||||
example2v1.SchemeGroupVersion.Version: example2v1.AddToScheme,
|
||||
},
|
||||
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
|
||||
).Register(registry, scheme); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apimachinery/announced"
|
||||
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -38,10 +37,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
groupFactoryRegistry = make(announced.APIGroupFactoryRegistry)
|
||||
registry = registered.NewOrDie("")
|
||||
scheme = runtime.NewScheme()
|
||||
codecs = serializer.NewCodecFactory(scheme)
|
||||
registry = registered.NewOrDie("")
|
||||
scheme = runtime.NewScheme()
|
||||
codecs = serializer.NewCodecFactory(scheme)
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -78,9 +78,9 @@ func MergeAPIResourceConfigs(
|
|||
if ok {
|
||||
if allAPIFlagValue == "false" {
|
||||
// Disable all group versions.
|
||||
resourceConfig.DisableVersions(registry.RegisteredGroupVersions()...)
|
||||
resourceConfig.DisableAll()
|
||||
} else if allAPIFlagValue == "true" {
|
||||
resourceConfig.EnableVersions(registry.RegisteredGroupVersions()...)
|
||||
resourceConfig.EnableAll()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ func TestParseRuntimeConfig(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for index, test := range testCases {
|
||||
t.Log(registry.RegisteredGroupVersions())
|
||||
actualDisablers, err := MergeAPIResourceConfigs(test.defaultResourceConfig(), test.runtimeConfig, registry)
|
||||
if err == nil && test.err {
|
||||
t.Fatalf("expected error for test case: %v", index)
|
||||
|
@ -168,10 +169,12 @@ func newFakeRegistry() *registered.APIRegistrationManager {
|
|||
registry := registered.NewOrDie("")
|
||||
|
||||
registry.RegisterGroup(apimachinery.GroupMeta{
|
||||
GroupVersion: apiv1.SchemeGroupVersion,
|
||||
GroupVersion: apiv1.SchemeGroupVersion,
|
||||
GroupVersions: []schema.GroupVersion{apiv1.SchemeGroupVersion},
|
||||
})
|
||||
registry.RegisterGroup(apimachinery.GroupMeta{
|
||||
GroupVersion: extensionsapiv1beta1.SchemeGroupVersion,
|
||||
GroupVersion: extensionsapiv1beta1.SchemeGroupVersion,
|
||||
GroupVersions: []schema.GroupVersion{extensionsapiv1beta1.SchemeGroupVersion},
|
||||
})
|
||||
registry.RegisterVersions([]schema.GroupVersion{apiv1.SchemeGroupVersion, extensionsapiv1beta1.SchemeGroupVersion})
|
||||
return registry
|
||||
|
|
|
@ -36,6 +36,18 @@ func NewResourceConfig() *ResourceConfig {
|
|||
return &ResourceConfig{GroupVersionConfigs: map[schema.GroupVersion]bool{}}
|
||||
}
|
||||
|
||||
func (o *ResourceConfig) DisableAll() {
|
||||
for k := range o.GroupVersionConfigs {
|
||||
o.GroupVersionConfigs[k] = false
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ResourceConfig) EnableAll() {
|
||||
for k := range o.GroupVersionConfigs {
|
||||
o.GroupVersionConfigs[k] = true
|
||||
}
|
||||
}
|
||||
|
||||
// DisableVersions disables the versions entirely.
|
||||
func (o *ResourceConfig) DisableVersions(versions ...schema.GroupVersion) {
|
||||
for _, version := range versions {
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apimachinery/announced"
|
||||
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -37,7 +36,6 @@ var (
|
|||
v1GroupVersion = schema.GroupVersion{Group: "", Version: "v1"}
|
||||
|
||||
registry = registered.NewOrDie(os.Getenv("KUBE_API_VERSIONS"))
|
||||
announce = make(announced.APIGroupFactoryRegistry)
|
||||
scheme = runtime.NewScheme()
|
||||
codecs = serializer.NewCodecFactory(scheme)
|
||||
parameterCodec = runtime.NewParameterCodec(scheme)
|
||||
|
@ -53,7 +51,7 @@ func init() {
|
|||
&metav1.APIResourceList{},
|
||||
)
|
||||
|
||||
exampleinstall.Install(announce, registry, scheme)
|
||||
exampleinstall.Install(registry, scheme)
|
||||
}
|
||||
|
||||
type fakeNegotiater struct {
|
||||
|
@ -119,8 +117,7 @@ func TestConfigurableStorageFactory(t *testing.T) {
|
|||
|
||||
func TestUpdateEtcdOverrides(t *testing.T) {
|
||||
registry := registered.NewOrDie(os.Getenv("KUBE_API_VERSIONS"))
|
||||
announced := make(announced.APIGroupFactoryRegistry)
|
||||
exampleinstall.Install(announced, registry, scheme)
|
||||
exampleinstall.Install(registry, scheme)
|
||||
|
||||
testCases := []struct {
|
||||
resource schema.GroupResource
|
||||
|
|
|
@ -48,7 +48,7 @@ func NewGenericWebhook(registry *registered.APIRegistrationManager, codecFactory
|
|||
|
||||
func newGenericWebhook(registry *registered.APIRegistrationManager, codecFactory serializer.CodecFactory, kubeConfigFile string, groupVersions []schema.GroupVersion, initialBackoff, requestTimeout time.Duration) (*GenericWebhook, error) {
|
||||
for _, groupVersion := range groupVersions {
|
||||
if !registry.IsEnabledVersion(groupVersion) {
|
||||
if !registry.IsRegisteredVersion(groupVersion) {
|
||||
return nil, fmt.Errorf("webhook plugin requires enabling extension resource: %s", groupVersion)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package log
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
@ -26,7 +25,6 @@ import (
|
|||
|
||||
"github.com/pborman/uuid"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apimachinery/announced"
|
||||
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -40,17 +38,13 @@ import (
|
|||
|
||||
// NOTE: Copied from webhook backend to register auditv1beta1 to scheme
|
||||
var (
|
||||
groupFactoryRegistry = make(announced.APIGroupFactoryRegistry)
|
||||
registry = registered.NewOrDie("")
|
||||
registry = registered.NewOrDie("")
|
||||
)
|
||||
|
||||
func init() {
|
||||
allGVs := []schema.GroupVersion{auditv1beta1.SchemeGroupVersion}
|
||||
registry.RegisterVersions(allGVs)
|
||||
if err := registry.EnableVersions(allGVs...); err != nil {
|
||||
panic(fmt.Sprintf("failed to enable version %v", allGVs))
|
||||
}
|
||||
install.Install(groupFactoryRegistry, registry, audit.Scheme)
|
||||
install.Install(registry, audit.Scheme)
|
||||
}
|
||||
|
||||
func TestLogEventsLegacy(t *testing.T) {
|
||||
|
|
|
@ -18,10 +18,8 @@ limitations under the License.
|
|||
package webhook
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apimachinery/announced"
|
||||
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
auditinternal "k8s.io/apiserver/pkg/apis/audit"
|
||||
|
@ -46,7 +44,6 @@ var (
|
|||
// NOTE: Copied from other webhook implementations
|
||||
//
|
||||
// Can we make these passable to NewGenericWebhook?
|
||||
groupFactoryRegistry = make(announced.APIGroupFactoryRegistry)
|
||||
// TODO(audit): figure out a general way to let the client choose their preferred version
|
||||
registry = registered.NewOrDie("")
|
||||
)
|
||||
|
@ -54,10 +51,7 @@ var (
|
|||
func init() {
|
||||
allGVs := []schema.GroupVersion{auditv1alpha1.SchemeGroupVersion, auditv1beta1.SchemeGroupVersion}
|
||||
registry.RegisterVersions(allGVs)
|
||||
if err := registry.EnableVersions(allGVs...); err != nil {
|
||||
panic(fmt.Sprintf("failed to enable version %v", allGVs))
|
||||
}
|
||||
install.Install(groupFactoryRegistry, registry, audit.Scheme)
|
||||
install.Install(registry, audit.Scheme)
|
||||
}
|
||||
|
||||
func loadWebhook(configFile string, groupVersion schema.GroupVersion, initialBackoff time.Duration) (*webhook.GenericWebhook, error) {
|
||||
|
|
|
@ -18,7 +18,6 @@ limitations under the License.
|
|||
package webhook
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@ -121,9 +120,6 @@ var registry = registered.NewOrDie("")
|
|||
|
||||
func init() {
|
||||
registry.RegisterVersions(groupVersions)
|
||||
if err := registry.EnableVersions(groupVersions...); err != nil {
|
||||
panic(fmt.Sprintf("failed to enable version %v", groupVersions))
|
||||
}
|
||||
}
|
||||
|
||||
// tokenReviewInterfaceFromKubeconfig builds a client from the specified kubeconfig file,
|
||||
|
|
|
@ -242,9 +242,6 @@ var registry = registered.NewOrDie("")
|
|||
|
||||
func init() {
|
||||
registry.RegisterVersions(groupVersions)
|
||||
if err := registry.EnableVersions(groupVersions...); err != nil {
|
||||
panic(fmt.Sprintf("failed to enable version %v", groupVersions))
|
||||
}
|
||||
}
|
||||
|
||||
// subjectAccessReviewInterfaceFromKubeconfig builds a client from the specified kubeconfig file,
|
||||
|
|
Loading…
Reference in New Issue