Skip to content

Commit 7ab3e43

Browse files
committed
Cleanup old-style conversions
1 parent ab6cbd2 commit 7ab3e43

File tree

4 files changed

+257
-291
lines changed

4 files changed

+257
-291
lines changed

staging/src/k8s.io/apimachinery/pkg/conversion/converter.go

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ func NewConverter(nameFn NameFunc) *Converter {
9393
inputFieldMappingFuncs: make(map[reflect.Type]FieldMappingFunc),
9494
inputDefaultFlags: make(map[reflect.Type]FieldMatchingFlags),
9595
}
96-
c.RegisterConversionFunc(Convert_Slice_byte_To_Slice_byte)
96+
c.RegisterUntypedConversionFunc(
97+
(*[]byte)(nil), (*[]byte)(nil),
98+
func(a, b interface{}, s Scope) error {
99+
return Convert_Slice_byte_To_Slice_byte(a.(*[]byte), b.(*[]byte), s)
100+
},
101+
)
97102
return c
98103
}
99104

@@ -159,25 +164,11 @@ func NewConversionFuncs() ConversionFuncs {
159164
}
160165

161166
type ConversionFuncs struct {
167+
// FIXME: Remove.
162168
fns map[typePair]reflect.Value
163169
untyped map[typePair]ConversionFunc
164170
}
165171

166-
// Add adds the provided conversion functions to the lookup table - they must have the signature
167-
// `func(type1, type2, Scope) error`. Functions are added in the order passed and will override
168-
// previously registered pairs.
169-
func (c ConversionFuncs) Add(fns ...interface{}) error {
170-
for _, fn := range fns {
171-
fv := reflect.ValueOf(fn)
172-
ft := fv.Type()
173-
if err := verifyConversionFunctionSignature(ft); err != nil {
174-
return err
175-
}
176-
c.fns[typePair{ft.In(0).Elem(), ft.In(1).Elem()}] = fv
177-
}
178-
return nil
179-
}
180-
181172
// AddUntyped adds the provided conversion function to the lookup table for the types that are
182173
// supplied as a and b. a and b must be pointers or an error is returned. This method overwrites
183174
// previously defined functions.
@@ -360,29 +351,6 @@ func verifyConversionFunctionSignature(ft reflect.Type) error {
360351
return nil
361352
}
362353

363-
// RegisterConversionFunc registers a conversion func with the
364-
// Converter. conversionFunc must take three parameters: a pointer to the input
365-
// type, a pointer to the output type, and a conversion.Scope (which should be
366-
// used if recursive conversion calls are desired). It must return an error.
367-
//
368-
// Example:
369-
// c.RegisterConversionFunc(
370-
// func(in *Pod, out *v1.Pod, s Scope) error {
371-
// // conversion logic...
372-
// return nil
373-
// })
374-
// DEPRECATED: Will be removed in favor of RegisterUntypedConversionFunc
375-
func (c *Converter) RegisterConversionFunc(conversionFunc interface{}) error {
376-
return c.conversionFuncs.Add(conversionFunc)
377-
}
378-
379-
// Similar to RegisterConversionFunc, but registers conversion function that were
380-
// automatically generated.
381-
// DEPRECATED: Will be removed in favor of RegisterGeneratedUntypedConversionFunc
382-
func (c *Converter) RegisterGeneratedConversionFunc(conversionFunc interface{}) error {
383-
return c.generatedConversionFuncs.Add(conversionFunc)
384-
}
385-
386354
// RegisterUntypedConversionFunc registers a function that converts between a and b by passing objects of those
387355
// types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce
388356
// any other guarantee.

0 commit comments

Comments
 (0)