diff --git a/pkg/apis/core/v1/conversion.go b/pkg/apis/core/v1/conversion.go index fe690579c64..cceee153af2 100644 --- a/pkg/apis/core/v1/conversion.go +++ b/pkg/apis/core/v1/conversion.go @@ -30,105 +30,6 @@ import ( "k8s.io/kubernetes/pkg/apis/extensions" ) -// This is a "fast-path" that avoids reflection for common types. It focuses on the objects that are -// converted the most in the cluster. -// TODO: generate one of these for every external API group - this is to prove the impact -func addFastPathConversionFuncs(scheme *runtime.Scheme) error { - scheme.AddGenericConversionFunc(func(objA, objB interface{}, s conversion.Scope) (bool, error) { - switch a := objA.(type) { - case *v1.Pod: - switch b := objB.(type) { - case *core.Pod: - return true, Convert_v1_Pod_To_core_Pod(a, b, s) - } - case *core.Pod: - switch b := objB.(type) { - case *v1.Pod: - return true, Convert_core_Pod_To_v1_Pod(a, b, s) - } - - case *v1.Event: - switch b := objB.(type) { - case *core.Event: - return true, Convert_v1_Event_To_core_Event(a, b, s) - } - case *core.Event: - switch b := objB.(type) { - case *v1.Event: - return true, Convert_core_Event_To_v1_Event(a, b, s) - } - - case *v1.ReplicationController: - switch b := objB.(type) { - case *core.ReplicationController: - return true, Convert_v1_ReplicationController_To_core_ReplicationController(a, b, s) - } - case *core.ReplicationController: - switch b := objB.(type) { - case *v1.ReplicationController: - return true, Convert_core_ReplicationController_To_v1_ReplicationController(a, b, s) - } - - case *v1.Node: - switch b := objB.(type) { - case *core.Node: - return true, Convert_v1_Node_To_core_Node(a, b, s) - } - case *core.Node: - switch b := objB.(type) { - case *v1.Node: - return true, Convert_core_Node_To_v1_Node(a, b, s) - } - - case *v1.Namespace: - switch b := objB.(type) { - case *core.Namespace: - return true, Convert_v1_Namespace_To_core_Namespace(a, b, s) - } - case *core.Namespace: - switch b := objB.(type) { - case *v1.Namespace: - return true, Convert_core_Namespace_To_v1_Namespace(a, b, s) - } - - case *v1.Service: - switch b := objB.(type) { - case *core.Service: - return true, Convert_v1_Service_To_core_Service(a, b, s) - } - case *core.Service: - switch b := objB.(type) { - case *v1.Service: - return true, Convert_core_Service_To_v1_Service(a, b, s) - } - - case *v1.Endpoints: - switch b := objB.(type) { - case *core.Endpoints: - return true, Convert_v1_Endpoints_To_core_Endpoints(a, b, s) - } - case *core.Endpoints: - switch b := objB.(type) { - case *v1.Endpoints: - return true, Convert_core_Endpoints_To_v1_Endpoints(a, b, s) - } - - case *metav1.WatchEvent: - switch b := objB.(type) { - case *metav1.InternalEvent: - return true, metav1.Convert_versioned_Event_to_versioned_InternalEvent(a, b, s) - } - case *metav1.InternalEvent: - switch b := objB.(type) { - case *metav1.WatchEvent: - return true, metav1.Convert_versioned_InternalEvent_to_versioned_Event(a, b, s) - } - } - return false, nil - }) - return nil -} - func addConversionFuncs(scheme *runtime.Scheme) error { // Add non-generated conversion functions err := scheme.AddConversionFuncs( diff --git a/pkg/apis/core/v1/register.go b/pkg/apis/core/v1/register.go index 79611beabe6..b446b7ea507 100644 --- a/pkg/apis/core/v1/register.go +++ b/pkg/apis/core/v1/register.go @@ -30,7 +30,7 @@ func init() { // We only register manually written functions here. The registration of the // generated functions takes place in the generated files. The separation // makes the code compile even when the generated files are missing. - localSchemeBuilder.Register(addDefaultingFuncs, addConversionFuncs, addFastPathConversionFuncs) + localSchemeBuilder.Register(addDefaultingFuncs, addConversionFuncs) } // TODO: remove these global varialbes diff --git a/staging/src/k8s.io/apimachinery/pkg/conversion/converter.go b/staging/src/k8s.io/apimachinery/pkg/conversion/converter.go index 0c384de4847..bc615dc3ace 100644 --- a/staging/src/k8s.io/apimachinery/pkg/conversion/converter.go +++ b/staging/src/k8s.io/apimachinery/pkg/conversion/converter.go @@ -53,11 +53,6 @@ type Converter struct { conversionFuncs ConversionFuncs generatedConversionFuncs ConversionFuncs - // genericConversions are called during normal conversion to offer a "fast-path" - // that avoids all reflection. These methods are not called outside of the .Convert() - // method. - genericConversions []GenericConversionFunc - // Set of conversions that should be treated as a no-op ignoredConversions map[typePair]struct{} @@ -102,14 +97,6 @@ func NewConverter(nameFn NameFunc) *Converter { return c } -// AddGenericConversionFunc adds a function that accepts the ConversionFunc call pattern -// (for two conversion types) to the converter. These functions are checked first during -// a normal conversion, but are otherwise not called. Use AddConversionFuncs when registering -// typed conversions. -func (c *Converter) AddGenericConversionFunc(fn GenericConversionFunc) { - c.genericConversions = append(c.genericConversions, fn) -} - // WithConversions returns a Converter that is a copy of c but with the additional // fns merged on top. func (c *Converter) WithConversions(fns ConversionFuncs) *Converter { @@ -480,15 +467,6 @@ func (f FieldMatchingFlags) IsSet(flag FieldMatchingFlags) bool { // it is not used by Convert() other than storing it in the scope. // Not safe for objects with cyclic references! func (c *Converter) Convert(src, dest interface{}, flags FieldMatchingFlags, meta *Meta) error { - // TODO: deprecated, will be removed in favor of untyped conversion - if len(c.genericConversions) > 0 { - s := &scope{converter: c, flags: flags, meta: meta} - for _, fn := range c.genericConversions { - if ok, err := fn(src, dest, s); ok { - return err - } - } - } return c.doConversion(src, dest, flags, meta, c.convert) } diff --git a/staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go b/staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go index d188588163e..058ac5b4acc 100644 --- a/staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go +++ b/staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go @@ -296,15 +296,6 @@ func (s *Scheme) New(kind schema.GroupVersionKind) (Object, error) { return nil, NewNotRegisteredErrForKind(s.schemeName, kind) } -// AddGenericConversionFunc adds a function that accepts the ConversionFunc call pattern -// (for two conversion types) to the converter. These functions are checked first during -// a normal conversion, but are otherwise not called. Use AddConversionFuncs when registering -// typed conversions. -// DEPRECATED: Use AddConversionFunc -func (s *Scheme) AddGenericConversionFunc(fn conversion.GenericConversionFunc) { - s.converter.AddGenericConversionFunc(fn) -} - // Log sets a logger on the scheme. For test purposes only func (s *Scheme) Log(l conversion.DebugLogger) { s.converter.Debug = l @@ -356,17 +347,6 @@ func (s *Scheme) AddConversionFuncs(conversionFuncs ...interface{}) error { return nil } -// AddGeneratedConversionFuncs registers conversion functions that were -// automatically generated. -func (s *Scheme) AddGeneratedConversionFuncs(conversionFuncs ...interface{}) error { - for _, f := range conversionFuncs { - if err := s.converter.RegisterGeneratedConversionFunc(f); err != nil { - return err - } - } - return nil -} - // AddConversionFunc registers a function that converts between a and b by passing objects of those // types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce // any other guarantee.