mirror of
https://github.com/kubernetes/sample-controller.git
synced 2025-02-20 23:56:23 +08:00
Merge pull request #66218 from atlassian/handle-errors
Automatic merge from submit-queue (batch tested with PRs 66152, 66406, 66218, 66278, 65660). 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>. Handle errors **What this PR does / why we need it**: This is a followup PR for https://github.com/kubernetes/kubernetes/pull/64664 to handle errors returned from `.AddToScheme()` in places where they are not handled. **Release note**: ```release-note NONE ``` /kind cleanup /sig api-machinery /cc @sttts Kubernetes-commit: 6c500be0808cfe9aff1141ec83ad885d04dd25ae
This commit is contained in:
commit
342d9152cf
406
Godeps/Godeps.json
generated
406
Godeps/Godeps.json
generated
File diff suppressed because it is too large
Load Diff
@ -27,6 +27,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/runtime"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
appsinformers "k8s.io/client-go/informers/apps/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
@ -94,7 +95,7 @@ func NewController(
|
||||
// Create event broadcaster
|
||||
// Add sample-controller types to the default Kubernetes Scheme so Events can be
|
||||
// logged for sample-controller types.
|
||||
samplescheme.AddToScheme(scheme.Scheme)
|
||||
utilruntime.Must(samplescheme.AddToScheme(scheme.Scheme))
|
||||
glog.V(4).Info("Creating event broadcaster")
|
||||
eventBroadcaster := record.NewBroadcaster()
|
||||
eventBroadcaster.StartLogging(glog.Infof)
|
||||
|
4
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
generated
vendored
4
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
generated
vendored
@ -21,7 +21,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -137,9 +136,6 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
// splitRE is used to get the various parts of a number.
|
||||
splitRE = regexp.MustCompile(splitREString)
|
||||
|
||||
// Errors that could happen while parsing a string.
|
||||
ErrFormatWrong = errors.New("quantities must match the regular expression '" + splitREString + "'")
|
||||
ErrNumeric = errors.New("unable to parse numeric part of quantity")
|
||||
|
23
vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion/conversion.go
generated
vendored
23
vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion/conversion.go
generated
vendored
@ -17,11 +17,8 @@ limitations under the License.
|
||||
package internalversion
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
)
|
||||
|
||||
func Convert_internalversion_ListOptions_To_v1_ListOptions(in *ListOptions, out *metav1.ListOptions, s conversion.Scope) error {
|
||||
@ -55,23 +52,3 @@ func Convert_v1_ListOptions_To_internalversion_ListOptions(in *metav1.ListOption
|
||||
out.Continue = in.Continue
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_map_to_v1_LabelSelector(in *map[string]string, out *metav1.LabelSelector, s conversion.Scope) error {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out = new(metav1.LabelSelector)
|
||||
for labelKey, labelValue := range *in {
|
||||
metav1.AddLabelToSelector(out, labelKey, labelValue)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_v1_LabelSelector_to_map(in *metav1.LabelSelector, out *map[string]string, s conversion.Scope) error {
|
||||
var err error
|
||||
*out, err = metav1.LabelSelectorAsMap(in)
|
||||
if err != nil {
|
||||
err = field.Invalid(field.NewPath("labelSelector"), *in, fmt.Sprintf("cannot convert to old selector: %v", err))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
4
vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion/register.go
generated
vendored
4
vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion/register.go
generated
vendored
@ -64,8 +64,8 @@ func addToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion)
|
||||
metav1.Convert_string_To_fields_Selector,
|
||||
metav1.Convert_fields_Selector_To_string,
|
||||
|
||||
Convert_map_to_v1_LabelSelector,
|
||||
Convert_v1_LabelSelector_to_map,
|
||||
metav1.Convert_Map_string_To_string_To_v1_LabelSelector,
|
||||
metav1.Convert_v1_LabelSelector_To_Map_string_To_string,
|
||||
|
||||
Convert_internalversion_ListOptions_To_v1_ListOptions,
|
||||
Convert_v1_ListOptions_To_internalversion_ListOptions,
|
||||
|
39
vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion/zz_generated.conversion.go
generated
vendored
39
vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion/zz_generated.conversion.go
generated
vendored
@ -34,13 +34,38 @@ func init() {
|
||||
|
||||
// RegisterConversions adds conversion functions to the given scheme.
|
||||
// Public to allow building arbitrary schemes.
|
||||
func RegisterConversions(scheme *runtime.Scheme) error {
|
||||
return scheme.AddGeneratedConversionFuncs(
|
||||
Convert_internalversion_List_To_v1_List,
|
||||
Convert_v1_List_To_internalversion_List,
|
||||
Convert_internalversion_ListOptions_To_v1_ListOptions,
|
||||
Convert_v1_ListOptions_To_internalversion_ListOptions,
|
||||
)
|
||||
func RegisterConversions(s *runtime.Scheme) error {
|
||||
if err := s.AddGeneratedConversionFunc((*List)(nil), (*v1.List)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_internalversion_List_To_v1_List(a.(*List), b.(*v1.List), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*v1.List)(nil), (*List)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_List_To_internalversion_List(a.(*v1.List), b.(*List), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*ListOptions)(nil), (*v1.ListOptions)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_internalversion_ListOptions_To_v1_ListOptions(a.(*ListOptions), b.(*v1.ListOptions), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*v1.ListOptions)(nil), (*ListOptions)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_ListOptions_To_internalversion_ListOptions(a.(*v1.ListOptions), b.(*ListOptions), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*ListOptions)(nil), (*v1.ListOptions)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_internalversion_ListOptions_To_v1_ListOptions(a.(*ListOptions), b.(*v1.ListOptions), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*v1.ListOptions)(nil), (*ListOptions)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_ListOptions_To_internalversion_ListOptions(a.(*v1.ListOptions), b.(*ListOptions), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_internalversion_List_To_v1_List(in *List, out *v1.List, s conversion.Scope) error {
|
||||
|
39
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/conversion.go
generated
vendored
39
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/conversion.go
generated
vendored
@ -33,17 +33,17 @@ func AddConversionFuncs(scheme *runtime.Scheme) error {
|
||||
return scheme.AddConversionFuncs(
|
||||
Convert_v1_TypeMeta_To_v1_TypeMeta,
|
||||
|
||||
Convert_unversioned_ListMeta_To_unversioned_ListMeta,
|
||||
Convert_v1_ListMeta_To_v1_ListMeta,
|
||||
|
||||
Convert_intstr_IntOrString_To_intstr_IntOrString,
|
||||
|
||||
Convert_unversioned_Time_To_unversioned_Time,
|
||||
Convert_unversioned_MicroTime_To_unversioned_MicroTime,
|
||||
|
||||
Convert_Pointer_v1_Duration_To_v1_Duration,
|
||||
Convert_v1_Duration_To_Pointer_v1_Duration,
|
||||
|
||||
Convert_Slice_string_To_unversioned_Time,
|
||||
Convert_Slice_string_To_v1_Time,
|
||||
|
||||
Convert_v1_Time_To_v1_Time,
|
||||
Convert_v1_MicroTime_To_v1_MicroTime,
|
||||
|
||||
Convert_resource_Quantity_To_resource_Quantity,
|
||||
|
||||
@ -71,8 +71,8 @@ func AddConversionFuncs(scheme *runtime.Scheme) error {
|
||||
Convert_Pointer_float64_To_float64,
|
||||
Convert_float64_To_Pointer_float64,
|
||||
|
||||
Convert_map_to_unversioned_LabelSelector,
|
||||
Convert_unversioned_LabelSelector_to_map,
|
||||
Convert_Map_string_To_string_To_v1_LabelSelector,
|
||||
Convert_v1_LabelSelector_To_Map_string_To_string,
|
||||
|
||||
Convert_Slice_string_To_Slice_int32,
|
||||
|
||||
@ -187,7 +187,7 @@ func Convert_v1_TypeMeta_To_v1_TypeMeta(in, out *TypeMeta, s conversion.Scope) e
|
||||
}
|
||||
|
||||
// +k8s:conversion-fn=copy-only
|
||||
func Convert_unversioned_ListMeta_To_unversioned_ListMeta(in, out *ListMeta, s conversion.Scope) error {
|
||||
func Convert_v1_ListMeta_To_v1_ListMeta(in, out *ListMeta, s conversion.Scope) error {
|
||||
*out = *in
|
||||
return nil
|
||||
}
|
||||
@ -199,7 +199,14 @@ func Convert_intstr_IntOrString_To_intstr_IntOrString(in, out *intstr.IntOrStrin
|
||||
}
|
||||
|
||||
// +k8s:conversion-fn=copy-only
|
||||
func Convert_unversioned_Time_To_unversioned_Time(in *Time, out *Time, s conversion.Scope) error {
|
||||
func Convert_v1_Time_To_v1_Time(in *Time, out *Time, s conversion.Scope) error {
|
||||
// Cannot deep copy these, because time.Time has unexported fields.
|
||||
*out = *in
|
||||
return nil
|
||||
}
|
||||
|
||||
// +k8s:conversion-fn=copy-only
|
||||
func Convert_v1_MicroTime_To_v1_MicroTime(in *MicroTime, out *MicroTime, s conversion.Scope) error {
|
||||
// Cannot deep copy these, because time.Time has unexported fields.
|
||||
*out = *in
|
||||
return nil
|
||||
@ -220,14 +227,8 @@ func Convert_v1_Duration_To_Pointer_v1_Duration(in *Duration, out **Duration, s
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_unversioned_MicroTime_To_unversioned_MicroTime(in *MicroTime, out *MicroTime, s conversion.Scope) error {
|
||||
// Cannot deep copy these, because time.Time has unexported fields.
|
||||
*out = *in
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert_Slice_string_To_unversioned_Time allows converting a URL query parameter value
|
||||
func Convert_Slice_string_To_unversioned_Time(input *[]string, out *Time, s conversion.Scope) error {
|
||||
// Convert_Slice_string_To_v1_Time allows converting a URL query parameter value
|
||||
func Convert_Slice_string_To_v1_Time(input *[]string, out *Time, s conversion.Scope) error {
|
||||
str := ""
|
||||
if len(*input) > 0 {
|
||||
str = (*input)[0]
|
||||
@ -275,7 +276,7 @@ func Convert_resource_Quantity_To_resource_Quantity(in *resource.Quantity, out *
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_map_to_unversioned_LabelSelector(in *map[string]string, out *LabelSelector, s conversion.Scope) error {
|
||||
func Convert_Map_string_To_string_To_v1_LabelSelector(in *map[string]string, out *LabelSelector, s conversion.Scope) error {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
@ -285,7 +286,7 @@ func Convert_map_to_unversioned_LabelSelector(in *map[string]string, out *LabelS
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_unversioned_LabelSelector_to_map(in *LabelSelector, out *map[string]string, s conversion.Scope) error {
|
||||
func Convert_v1_LabelSelector_To_Map_string_To_string(in *LabelSelector, out *map[string]string, s conversion.Scope) error {
|
||||
var err error
|
||||
*out, err = LabelSelectorAsMap(in)
|
||||
return err
|
||||
|
8
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/register.go
generated
vendored
8
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/register.go
generated
vendored
@ -57,10 +57,10 @@ func AddToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion)
|
||||
&UpdateOptions{},
|
||||
)
|
||||
utilruntime.Must(scheme.AddConversionFuncs(
|
||||
Convert_versioned_Event_to_watch_Event,
|
||||
Convert_versioned_InternalEvent_to_versioned_Event,
|
||||
Convert_watch_Event_to_versioned_Event,
|
||||
Convert_versioned_Event_to_versioned_InternalEvent,
|
||||
Convert_v1_WatchEvent_To_watch_Event,
|
||||
Convert_v1_InternalEvent_To_v1_WatchEvent,
|
||||
Convert_watch_Event_To_v1_WatchEvent,
|
||||
Convert_v1_WatchEvent_To_v1_InternalEvent,
|
||||
))
|
||||
// Register Unversioned types under their own special group
|
||||
scheme.AddUnversionedTypes(Unversioned,
|
||||
|
12
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/watch.go
generated
vendored
12
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/watch.go
generated
vendored
@ -39,7 +39,7 @@ type WatchEvent struct {
|
||||
Object runtime.RawExtension `json:"object" protobuf:"bytes,2,opt,name=object"`
|
||||
}
|
||||
|
||||
func Convert_watch_Event_to_versioned_Event(in *watch.Event, out *WatchEvent, s conversion.Scope) error {
|
||||
func Convert_watch_Event_To_v1_WatchEvent(in *watch.Event, out *WatchEvent, s conversion.Scope) error {
|
||||
out.Type = string(in.Type)
|
||||
switch t := in.Object.(type) {
|
||||
case *runtime.Unknown:
|
||||
@ -52,11 +52,11 @@ func Convert_watch_Event_to_versioned_Event(in *watch.Event, out *WatchEvent, s
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_versioned_InternalEvent_to_versioned_Event(in *InternalEvent, out *WatchEvent, s conversion.Scope) error {
|
||||
return Convert_watch_Event_to_versioned_Event((*watch.Event)(in), out, s)
|
||||
func Convert_v1_InternalEvent_To_v1_WatchEvent(in *InternalEvent, out *WatchEvent, s conversion.Scope) error {
|
||||
return Convert_watch_Event_To_v1_WatchEvent((*watch.Event)(in), out, s)
|
||||
}
|
||||
|
||||
func Convert_versioned_Event_to_watch_Event(in *WatchEvent, out *watch.Event, s conversion.Scope) error {
|
||||
func Convert_v1_WatchEvent_To_watch_Event(in *WatchEvent, out *watch.Event, s conversion.Scope) error {
|
||||
out.Type = watch.EventType(in.Type)
|
||||
if in.Object.Object != nil {
|
||||
out.Object = in.Object.Object
|
||||
@ -70,8 +70,8 @@ func Convert_versioned_Event_to_watch_Event(in *WatchEvent, out *watch.Event, s
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_versioned_Event_to_versioned_InternalEvent(in *WatchEvent, out *InternalEvent, s conversion.Scope) error {
|
||||
return Convert_versioned_Event_to_watch_Event(in, (*watch.Event)(out), s)
|
||||
func Convert_v1_WatchEvent_To_v1_InternalEvent(in *WatchEvent, out *InternalEvent, s conversion.Scope) error {
|
||||
return Convert_v1_WatchEvent_To_watch_Event(in, (*watch.Event)(out), s)
|
||||
}
|
||||
|
||||
// InternalEvent makes watch.Event versioned
|
||||
|
132
vendor/k8s.io/apimachinery/pkg/conversion/converter.go
generated
vendored
132
vendor/k8s.io/apimachinery/pkg/conversion/converter.go
generated
vendored
@ -40,7 +40,11 @@ type NameFunc func(t reflect.Type) string
|
||||
|
||||
var DefaultNameFunc = func(t reflect.Type) string { return t.Name() }
|
||||
|
||||
type GenericConversionFunc func(a, b interface{}, scope Scope) (bool, error)
|
||||
// ConversionFunc converts the object a into the object b, reusing arrays or objects
|
||||
// or pointers if necessary. It should return an error if the object cannot be converted
|
||||
// or if some data is invalid. If you do not wish a and b to share fields or nested
|
||||
// objects, you must copy a before calling this function.
|
||||
type ConversionFunc func(a, b interface{}, scope Scope) error
|
||||
|
||||
// Converter knows how to convert one type to another.
|
||||
type Converter struct {
|
||||
@ -49,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{}
|
||||
|
||||
@ -98,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 {
|
||||
@ -161,11 +152,15 @@ type Scope interface {
|
||||
type FieldMappingFunc func(key string, sourceTag, destTag reflect.StructTag) (source string, dest string)
|
||||
|
||||
func NewConversionFuncs() ConversionFuncs {
|
||||
return ConversionFuncs{fns: make(map[typePair]reflect.Value)}
|
||||
return ConversionFuncs{
|
||||
fns: make(map[typePair]reflect.Value),
|
||||
untyped: make(map[typePair]ConversionFunc),
|
||||
}
|
||||
}
|
||||
|
||||
type ConversionFuncs struct {
|
||||
fns map[typePair]reflect.Value
|
||||
fns map[typePair]reflect.Value
|
||||
untyped map[typePair]ConversionFunc
|
||||
}
|
||||
|
||||
// Add adds the provided conversion functions to the lookup table - they must have the signature
|
||||
@ -183,6 +178,21 @@ func (c ConversionFuncs) Add(fns ...interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddUntyped adds the provided conversion function to the lookup table for the types that are
|
||||
// supplied as a and b. a and b must be pointers or an error is returned. This method overwrites
|
||||
// previously defined functions.
|
||||
func (c ConversionFuncs) AddUntyped(a, b interface{}, fn ConversionFunc) error {
|
||||
tA, tB := reflect.TypeOf(a), reflect.TypeOf(b)
|
||||
if tA.Kind() != reflect.Ptr {
|
||||
return fmt.Errorf("the type %T must be a pointer to register as an untyped conversion", a)
|
||||
}
|
||||
if tB.Kind() != reflect.Ptr {
|
||||
return fmt.Errorf("the type %T must be a pointer to register as an untyped conversion", b)
|
||||
}
|
||||
c.untyped[typePair{tA, tB}] = fn
|
||||
return nil
|
||||
}
|
||||
|
||||
// Merge returns a new ConversionFuncs that contains all conversions from
|
||||
// both other and c, with other conversions taking precedence.
|
||||
func (c ConversionFuncs) Merge(other ConversionFuncs) ConversionFuncs {
|
||||
@ -193,6 +203,12 @@ func (c ConversionFuncs) Merge(other ConversionFuncs) ConversionFuncs {
|
||||
for k, v := range other.fns {
|
||||
merged.fns[k] = v
|
||||
}
|
||||
for k, v := range c.untyped {
|
||||
merged.untyped[k] = v
|
||||
}
|
||||
for k, v := range other.untyped {
|
||||
merged.untyped[k] = v
|
||||
}
|
||||
return merged
|
||||
}
|
||||
|
||||
@ -355,16 +371,32 @@ func verifyConversionFunctionSignature(ft reflect.Type) error {
|
||||
// // conversion logic...
|
||||
// return nil
|
||||
// })
|
||||
// DEPRECATED: Will be removed in favor of RegisterUntypedConversionFunc
|
||||
func (c *Converter) RegisterConversionFunc(conversionFunc interface{}) error {
|
||||
return c.conversionFuncs.Add(conversionFunc)
|
||||
}
|
||||
|
||||
// Similar to RegisterConversionFunc, but registers conversion function that were
|
||||
// automatically generated.
|
||||
// DEPRECATED: Will be removed in favor of RegisterGeneratedUntypedConversionFunc
|
||||
func (c *Converter) RegisterGeneratedConversionFunc(conversionFunc interface{}) error {
|
||||
return c.generatedConversionFuncs.Add(conversionFunc)
|
||||
}
|
||||
|
||||
// RegisterUntypedConversionFunc 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.
|
||||
func (c *Converter) RegisterUntypedConversionFunc(a, b interface{}, fn ConversionFunc) error {
|
||||
return c.conversionFuncs.AddUntyped(a, b, fn)
|
||||
}
|
||||
|
||||
// RegisterGeneratedUntypedConversionFunc 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.
|
||||
func (c *Converter) RegisterGeneratedUntypedConversionFunc(a, b interface{}, fn ConversionFunc) error {
|
||||
return c.generatedConversionFuncs.AddUntyped(a, b, fn)
|
||||
}
|
||||
|
||||
// RegisterIgnoredConversion registers a "no-op" for conversion, where any requested
|
||||
// conversion between from and to is ignored.
|
||||
func (c *Converter) RegisterIgnoredConversion(from, to interface{}) error {
|
||||
@ -380,39 +412,6 @@ func (c *Converter) RegisterIgnoredConversion(from, to interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsConversionIgnored returns true if the specified objects should be dropped during
|
||||
// conversion.
|
||||
func (c *Converter) IsConversionIgnored(inType, outType reflect.Type) bool {
|
||||
_, found := c.ignoredConversions[typePair{inType, outType}]
|
||||
return found
|
||||
}
|
||||
|
||||
func (c *Converter) HasConversionFunc(inType, outType reflect.Type) bool {
|
||||
_, found := c.conversionFuncs.fns[typePair{inType, outType}]
|
||||
return found
|
||||
}
|
||||
|
||||
func (c *Converter) ConversionFuncValue(inType, outType reflect.Type) (reflect.Value, bool) {
|
||||
value, found := c.conversionFuncs.fns[typePair{inType, outType}]
|
||||
return value, found
|
||||
}
|
||||
|
||||
// SetStructFieldCopy registers a correspondence. Whenever a struct field is encountered
|
||||
// which has a type and name matching srcFieldType and srcFieldName, it wil be copied
|
||||
// into the field in the destination struct matching destFieldType & Name, if such a
|
||||
// field exists.
|
||||
// May be called multiple times, even for the same source field & type--all applicable
|
||||
// copies will be performed.
|
||||
func (c *Converter) SetStructFieldCopy(srcFieldType interface{}, srcFieldName string, destFieldType interface{}, destFieldName string) error {
|
||||
st := reflect.TypeOf(srcFieldType)
|
||||
dt := reflect.TypeOf(destFieldType)
|
||||
srcKey := typeNamePair{st, srcFieldName}
|
||||
destKey := typeNamePair{dt, destFieldName}
|
||||
c.structFieldDests[srcKey] = append(c.structFieldDests[srcKey], destKey)
|
||||
c.structFieldSources[destKey] = append(c.structFieldSources[destKey], srcKey)
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterInputDefaults registers a field name mapping function, used when converting
|
||||
// from maps to structs. Inputs to the conversion methods are checked for this type and a mapping
|
||||
// applied automatically if the input matches in. A set of default flags for the input conversion
|
||||
@ -468,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 {
|
||||
if len(c.genericConversions) > 0 {
|
||||
// TODO: avoid scope allocation
|
||||
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)
|
||||
}
|
||||
|
||||
@ -495,6 +485,21 @@ func (c *Converter) DefaultConvert(src, dest interface{}, flags FieldMatchingFla
|
||||
type conversionFunc func(sv, dv reflect.Value, scope *scope) error
|
||||
|
||||
func (c *Converter) doConversion(src, dest interface{}, flags FieldMatchingFlags, meta *Meta, f conversionFunc) error {
|
||||
pair := typePair{reflect.TypeOf(src), reflect.TypeOf(dest)}
|
||||
scope := &scope{
|
||||
converter: c,
|
||||
flags: flags,
|
||||
meta: meta,
|
||||
}
|
||||
if fn, ok := c.conversionFuncs.untyped[pair]; ok {
|
||||
return fn(src, dest, scope)
|
||||
}
|
||||
if fn, ok := c.generatedConversionFuncs.untyped[pair]; ok {
|
||||
return fn(src, dest, scope)
|
||||
}
|
||||
// TODO: consider everything past this point deprecated - we want to support only point to point top level
|
||||
// conversions
|
||||
|
||||
dv, err := EnforcePtr(dest)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -506,15 +511,10 @@ func (c *Converter) doConversion(src, dest interface{}, flags FieldMatchingFlags
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s := &scope{
|
||||
converter: c,
|
||||
flags: flags,
|
||||
meta: meta,
|
||||
}
|
||||
// Leave something on the stack, so that calls to struct tag getters never fail.
|
||||
s.srcStack.push(scopeStackElem{})
|
||||
s.destStack.push(scopeStackElem{})
|
||||
return f(sv, dv, s)
|
||||
scope.srcStack.push(scopeStackElem{})
|
||||
scope.destStack.push(scopeStackElem{})
|
||||
return f(sv, dv, scope)
|
||||
}
|
||||
|
||||
// callCustom calls 'custom' with sv & dv. custom must be a conversion function.
|
||||
|
21
vendor/k8s.io/apimachinery/pkg/runtime/doc.go
generated
vendored
21
vendor/k8s.io/apimachinery/pkg/runtime/doc.go
generated
vendored
@ -18,20 +18,27 @@ limitations under the License.
|
||||
// that follow the kubernetes API object conventions, which are:
|
||||
//
|
||||
// 0. Your API objects have a common metadata struct member, TypeMeta.
|
||||
//
|
||||
// 1. Your code refers to an internal set of API objects.
|
||||
//
|
||||
// 2. In a separate package, you have an external set of API objects.
|
||||
//
|
||||
// 3. The external set is considered to be versioned, and no breaking
|
||||
// changes are ever made to it (fields may be added but not changed
|
||||
// or removed).
|
||||
// changes are ever made to it (fields may be added but not changed
|
||||
// or removed).
|
||||
//
|
||||
// 4. As your api evolves, you'll make an additional versioned package
|
||||
// with every major change.
|
||||
// with every major change.
|
||||
//
|
||||
// 5. Versioned packages have conversion functions which convert to
|
||||
// and from the internal version.
|
||||
// and from the internal version.
|
||||
//
|
||||
// 6. You'll continue to support older versions according to your
|
||||
// deprecation policy, and you can easily provide a program/library
|
||||
// to update old versions into new versions because of 5.
|
||||
// deprecation policy, and you can easily provide a program/library
|
||||
// to update old versions into new versions because of 5.
|
||||
//
|
||||
// 7. All of your serializations and deserializations are handled in a
|
||||
// centralized place.
|
||||
// centralized place.
|
||||
//
|
||||
// Package runtime provides a conversion helper to make 5 easy, and the
|
||||
// Encode/Decode/DecodeInto trio to accomplish 7. You can also register
|
||||
|
37
vendor/k8s.io/apimachinery/pkg/runtime/scheme.go
generated
vendored
37
vendor/k8s.io/apimachinery/pkg/runtime/scheme.go
generated
vendored
@ -296,14 +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.
|
||||
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
|
||||
@ -355,15 +347,18 @@ 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.
|
||||
func (s *Scheme) AddConversionFunc(a, b interface{}, fn conversion.ConversionFunc) error {
|
||||
return s.converter.RegisterUntypedConversionFunc(a, b, fn)
|
||||
}
|
||||
|
||||
// AddGeneratedConversionFunc 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.
|
||||
func (s *Scheme) AddGeneratedConversionFunc(a, b interface{}, fn conversion.ConversionFunc) error {
|
||||
return s.converter.RegisterGeneratedUntypedConversionFunc(a, b, fn)
|
||||
}
|
||||
|
||||
// AddFieldLabelConversionFunc adds a conversion function to convert field selectors
|
||||
@ -373,14 +368,6 @@ func (s *Scheme) AddFieldLabelConversionFunc(gvk schema.GroupVersionKind, conver
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddStructFieldConversion allows you to specify a mechanical copy for a moved
|
||||
// or renamed struct field without writing an entire conversion function. See
|
||||
// the comment in conversion.Converter.SetStructFieldCopy for parameter details.
|
||||
// Call as many times as needed, even on the same fields.
|
||||
func (s *Scheme) AddStructFieldConversion(srcFieldType interface{}, srcFieldName string, destFieldType interface{}, destFieldName string) error {
|
||||
return s.converter.SetStructFieldCopy(srcFieldType, srcFieldName, destFieldType, destFieldName)
|
||||
}
|
||||
|
||||
// RegisterInputDefaults sets the provided field mapping function and field matching
|
||||
// as the defaults for the provided input type. The fn may be nil, in which case no
|
||||
// mapping will happen by default. Use this method to register a mechanism for handling
|
||||
|
4
vendor/k8s.io/client-go/discovery/cached_discovery.go
generated
vendored
4
vendor/k8s.io/client-go/discovery/cached_discovery.go
generated
vendored
@ -83,7 +83,7 @@ func (d *CachedDiscoveryClient) ServerResourcesForGroupVersion(groupVersion stri
|
||||
}
|
||||
|
||||
if err := d.writeCachedFile(filename, liveResources); err != nil {
|
||||
glog.V(3).Infof("failed to write cache to %v due to %v", filename, err)
|
||||
glog.V(1).Infof("failed to write cache to %v due to %v", filename, err)
|
||||
}
|
||||
|
||||
return liveResources, nil
|
||||
@ -117,7 +117,7 @@ func (d *CachedDiscoveryClient) ServerGroups() (*metav1.APIGroupList, error) {
|
||||
}
|
||||
|
||||
if err := d.writeCachedFile(filename, liveGroups); err != nil {
|
||||
glog.V(3).Infof("failed to write cache to %v due to %v", filename, err)
|
||||
glog.V(1).Infof("failed to write cache to %v due to %v", filename, err)
|
||||
}
|
||||
|
||||
return liveGroups, nil
|
||||
|
@ -35,17 +35,48 @@ func init() {
|
||||
|
||||
// RegisterConversions adds conversion functions to the given scheme.
|
||||
// Public to allow building arbitrary schemes.
|
||||
func RegisterConversions(scheme *runtime.Scheme) error {
|
||||
return scheme.AddGeneratedConversionFuncs(
|
||||
Convert_v1alpha1_ExecCredential_To_clientauthentication_ExecCredential,
|
||||
Convert_clientauthentication_ExecCredential_To_v1alpha1_ExecCredential,
|
||||
Convert_v1alpha1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec,
|
||||
Convert_clientauthentication_ExecCredentialSpec_To_v1alpha1_ExecCredentialSpec,
|
||||
Convert_v1alpha1_ExecCredentialStatus_To_clientauthentication_ExecCredentialStatus,
|
||||
Convert_clientauthentication_ExecCredentialStatus_To_v1alpha1_ExecCredentialStatus,
|
||||
Convert_v1alpha1_Response_To_clientauthentication_Response,
|
||||
Convert_clientauthentication_Response_To_v1alpha1_Response,
|
||||
)
|
||||
func RegisterConversions(s *runtime.Scheme) error {
|
||||
if err := s.AddGeneratedConversionFunc((*ExecCredential)(nil), (*clientauthentication.ExecCredential)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_ExecCredential_To_clientauthentication_ExecCredential(a.(*ExecCredential), b.(*clientauthentication.ExecCredential), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*clientauthentication.ExecCredential)(nil), (*ExecCredential)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_clientauthentication_ExecCredential_To_v1alpha1_ExecCredential(a.(*clientauthentication.ExecCredential), b.(*ExecCredential), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*ExecCredentialSpec)(nil), (*clientauthentication.ExecCredentialSpec)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec(a.(*ExecCredentialSpec), b.(*clientauthentication.ExecCredentialSpec), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*clientauthentication.ExecCredentialSpec)(nil), (*ExecCredentialSpec)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_clientauthentication_ExecCredentialSpec_To_v1alpha1_ExecCredentialSpec(a.(*clientauthentication.ExecCredentialSpec), b.(*ExecCredentialSpec), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*ExecCredentialStatus)(nil), (*clientauthentication.ExecCredentialStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_ExecCredentialStatus_To_clientauthentication_ExecCredentialStatus(a.(*ExecCredentialStatus), b.(*clientauthentication.ExecCredentialStatus), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*clientauthentication.ExecCredentialStatus)(nil), (*ExecCredentialStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_clientauthentication_ExecCredentialStatus_To_v1alpha1_ExecCredentialStatus(a.(*clientauthentication.ExecCredentialStatus), b.(*ExecCredentialStatus), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*Response)(nil), (*clientauthentication.Response)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_Response_To_clientauthentication_Response(a.(*Response), b.(*clientauthentication.Response), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*clientauthentication.Response)(nil), (*Response)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_clientauthentication_Response_To_v1alpha1_Response(a.(*clientauthentication.Response), b.(*Response), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_v1alpha1_ExecCredential_To_clientauthentication_ExecCredential(in *ExecCredential, out *clientauthentication.ExecCredential, s conversion.Scope) error {
|
||||
|
46
vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1beta1/zz_generated.conversion.go
generated
vendored
46
vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1beta1/zz_generated.conversion.go
generated
vendored
@ -35,15 +35,43 @@ func init() {
|
||||
|
||||
// RegisterConversions adds conversion functions to the given scheme.
|
||||
// Public to allow building arbitrary schemes.
|
||||
func RegisterConversions(scheme *runtime.Scheme) error {
|
||||
return scheme.AddGeneratedConversionFuncs(
|
||||
Convert_v1beta1_ExecCredential_To_clientauthentication_ExecCredential,
|
||||
Convert_clientauthentication_ExecCredential_To_v1beta1_ExecCredential,
|
||||
Convert_v1beta1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec,
|
||||
Convert_clientauthentication_ExecCredentialSpec_To_v1beta1_ExecCredentialSpec,
|
||||
Convert_v1beta1_ExecCredentialStatus_To_clientauthentication_ExecCredentialStatus,
|
||||
Convert_clientauthentication_ExecCredentialStatus_To_v1beta1_ExecCredentialStatus,
|
||||
)
|
||||
func RegisterConversions(s *runtime.Scheme) error {
|
||||
if err := s.AddGeneratedConversionFunc((*ExecCredential)(nil), (*clientauthentication.ExecCredential)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1beta1_ExecCredential_To_clientauthentication_ExecCredential(a.(*ExecCredential), b.(*clientauthentication.ExecCredential), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*clientauthentication.ExecCredential)(nil), (*ExecCredential)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_clientauthentication_ExecCredential_To_v1beta1_ExecCredential(a.(*clientauthentication.ExecCredential), b.(*ExecCredential), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*ExecCredentialSpec)(nil), (*clientauthentication.ExecCredentialSpec)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1beta1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec(a.(*ExecCredentialSpec), b.(*clientauthentication.ExecCredentialSpec), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*clientauthentication.ExecCredentialSpec)(nil), (*ExecCredentialSpec)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_clientauthentication_ExecCredentialSpec_To_v1beta1_ExecCredentialSpec(a.(*clientauthentication.ExecCredentialSpec), b.(*ExecCredentialSpec), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*ExecCredentialStatus)(nil), (*clientauthentication.ExecCredentialStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1beta1_ExecCredentialStatus_To_clientauthentication_ExecCredentialStatus(a.(*ExecCredentialStatus), b.(*clientauthentication.ExecCredentialStatus), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*clientauthentication.ExecCredentialStatus)(nil), (*ExecCredentialStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_clientauthentication_ExecCredentialStatus_To_v1beta1_ExecCredentialStatus(a.(*clientauthentication.ExecCredentialStatus), b.(*ExecCredentialStatus), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*clientauthentication.ExecCredentialSpec)(nil), (*ExecCredentialSpec)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_clientauthentication_ExecCredentialSpec_To_v1beta1_ExecCredentialSpec(a.(*clientauthentication.ExecCredentialSpec), b.(*ExecCredentialSpec), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_v1beta1_ExecCredential_To_clientauthentication_ExecCredential(in *ExecCredential, out *clientauthentication.ExecCredential, s conversion.Scope) error {
|
||||
|
2
vendor/k8s.io/client-go/rest/config.go
generated
vendored
2
vendor/k8s.io/client-go/rest/config.go
generated
vendored
@ -220,7 +220,7 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
|
||||
// the config.Version to be empty.
|
||||
func UnversionedRESTClientFor(config *Config) (*RESTClient, error) {
|
||||
if config.NegotiatedSerializer == nil {
|
||||
return nil, fmt.Errorf("NeogitatedSerializer is required when initializing a RESTClient")
|
||||
return nil, fmt.Errorf("NegotiatedSerializer is required when initializing a RESTClient")
|
||||
}
|
||||
|
||||
baseURL, versionedAPIPath, err := defaultServerUrlFor(config)
|
||||
|
@ -34,15 +34,38 @@ func init() {
|
||||
|
||||
// RegisterConversions adds conversion functions to the given scheme.
|
||||
// Public to allow building arbitrary schemes.
|
||||
func RegisterConversions(scheme *runtime.Scheme) error {
|
||||
return scheme.AddGeneratedConversionFuncs(
|
||||
Convert_v1_TestType_To_example_TestType,
|
||||
Convert_example_TestType_To_v1_TestType,
|
||||
Convert_v1_TestTypeList_To_example_TestTypeList,
|
||||
Convert_example_TestTypeList_To_v1_TestTypeList,
|
||||
Convert_v1_TestTypeStatus_To_example_TestTypeStatus,
|
||||
Convert_example_TestTypeStatus_To_v1_TestTypeStatus,
|
||||
)
|
||||
func RegisterConversions(s *runtime.Scheme) error {
|
||||
if err := s.AddGeneratedConversionFunc((*TestType)(nil), (*example.TestType)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_TestType_To_example_TestType(a.(*TestType), b.(*example.TestType), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*example.TestType)(nil), (*TestType)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_example_TestType_To_v1_TestType(a.(*example.TestType), b.(*TestType), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*TestTypeList)(nil), (*example.TestTypeList)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_TestTypeList_To_example_TestTypeList(a.(*TestTypeList), b.(*example.TestTypeList), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*example.TestTypeList)(nil), (*TestTypeList)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_example_TestTypeList_To_v1_TestTypeList(a.(*example.TestTypeList), b.(*TestTypeList), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*TestTypeStatus)(nil), (*example.TestTypeStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_TestTypeStatus_To_example_TestTypeStatus(a.(*TestTypeStatus), b.(*example.TestTypeStatus), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*example.TestTypeStatus)(nil), (*TestTypeStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_example_TestTypeStatus_To_v1_TestTypeStatus(a.(*example.TestTypeStatus), b.(*TestTypeStatus), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_v1_TestType_To_example_TestType(in *TestType, out *example.TestType, s conversion.Scope) error {
|
||||
|
@ -34,15 +34,38 @@ func init() {
|
||||
|
||||
// RegisterConversions adds conversion functions to the given scheme.
|
||||
// Public to allow building arbitrary schemes.
|
||||
func RegisterConversions(scheme *runtime.Scheme) error {
|
||||
return scheme.AddGeneratedConversionFuncs(
|
||||
Convert_v1_TestType_To_example2_TestType,
|
||||
Convert_example2_TestType_To_v1_TestType,
|
||||
Convert_v1_TestTypeList_To_example2_TestTypeList,
|
||||
Convert_example2_TestTypeList_To_v1_TestTypeList,
|
||||
Convert_v1_TestTypeStatus_To_example2_TestTypeStatus,
|
||||
Convert_example2_TestTypeStatus_To_v1_TestTypeStatus,
|
||||
)
|
||||
func RegisterConversions(s *runtime.Scheme) error {
|
||||
if err := s.AddGeneratedConversionFunc((*TestType)(nil), (*example2.TestType)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_TestType_To_example2_TestType(a.(*TestType), b.(*example2.TestType), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*example2.TestType)(nil), (*TestType)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_example2_TestType_To_v1_TestType(a.(*example2.TestType), b.(*TestType), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*TestTypeList)(nil), (*example2.TestTypeList)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_TestTypeList_To_example2_TestTypeList(a.(*TestTypeList), b.(*example2.TestTypeList), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*example2.TestTypeList)(nil), (*TestTypeList)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_example2_TestTypeList_To_v1_TestTypeList(a.(*example2.TestTypeList), b.(*TestTypeList), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*TestTypeStatus)(nil), (*example2.TestTypeStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_TestTypeStatus_To_example2_TestTypeStatus(a.(*TestTypeStatus), b.(*example2.TestTypeStatus), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*example2.TestTypeStatus)(nil), (*TestTypeStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_example2_TestTypeStatus_To_v1_TestTypeStatus(a.(*example2.TestTypeStatus), b.(*TestTypeStatus), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_v1_TestType_To_example2_TestType(in *TestType, out *example2.TestType, s conversion.Scope) error {
|
||||
|
36
vendor/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go
generated
vendored
36
vendor/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go
generated
vendored
@ -175,10 +175,14 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
|
||||
key := conversionPair{inType.Elem, outType.Elem}
|
||||
// We might scan the same package twice, and that's OK.
|
||||
if v, ok := manualMap[key]; ok && v != nil && v.Name.Package != pkg.Path {
|
||||
panic(fmt.Sprintf("duplicate static conversion defined: %s -> %s", key.inType, key.outType))
|
||||
panic(fmt.Sprintf("duplicate static conversion defined: %s -> %s from:\n%s.%s\n%s.%s", key.inType, key.outType, v.Name.Package, v.Name.Name, f.Name.Package, f.Name.Name))
|
||||
}
|
||||
manualMap[key] = f
|
||||
} else {
|
||||
// prevent user error when they don't get the correct conversion signature
|
||||
if strings.HasPrefix(f.Name.Name, "Convert_") {
|
||||
glog.Errorf("Rename function %s %s -> %s to match expected conversion signature", f.Name.Package, f.Name.Name, buffer.String())
|
||||
}
|
||||
glog.V(8).Infof("%s has wrong name", f.Name)
|
||||
}
|
||||
buffer.Reset()
|
||||
@ -606,14 +610,34 @@ func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
|
||||
}
|
||||
sw.Do("// RegisterConversions adds conversion functions to the given scheme.\n", nil)
|
||||
sw.Do("// Public to allow building arbitrary schemes.\n", nil)
|
||||
sw.Do("func RegisterConversions(scheme $.|raw$) error {\n", schemePtr)
|
||||
sw.Do("return scheme.AddGeneratedConversionFuncs(\n", nil)
|
||||
sw.Do("func RegisterConversions(s $.|raw$) error {\n", schemePtr)
|
||||
for _, t := range g.types {
|
||||
peerType := getPeerTypeFor(c, t, g.peerPackages)
|
||||
sw.Do(nameTmpl+",\n", argsFromType(t, peerType))
|
||||
sw.Do(nameTmpl+",\n", argsFromType(peerType, t))
|
||||
args := argsFromType(t, peerType).With("Scope", types.Ref(conversionPackagePath, "Scope"))
|
||||
sw.Do("if err := s.AddGeneratedConversionFunc((*$.inType|raw$)(nil), (*$.outType|raw$)(nil), func(a, b interface{}, scope $.Scope|raw$) error { return "+nameTmpl+"(a.(*$.inType|raw$), b.(*$.outType|raw$), scope) }); err != nil { return err }\n", args)
|
||||
args = argsFromType(peerType, t).With("Scope", types.Ref(conversionPackagePath, "Scope"))
|
||||
sw.Do("if err := s.AddGeneratedConversionFunc((*$.inType|raw$)(nil), (*$.outType|raw$)(nil), func(a, b interface{}, scope $.Scope|raw$) error { return "+nameTmpl+"(a.(*$.inType|raw$), b.(*$.outType|raw$), scope) }); err != nil { return err }\n", args)
|
||||
}
|
||||
sw.Do(")\n", nil)
|
||||
var pairs []conversionPair
|
||||
for pair, t := range g.manualConversions {
|
||||
if t.Name.Package != g.outputPackage {
|
||||
continue
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
// sort by name of the conversion function
|
||||
sort.Slice(pairs, func(i, j int) bool {
|
||||
if g.manualConversions[pairs[i]].Name.Name < g.manualConversions[pairs[j]].Name.Name {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
for _, pair := range pairs {
|
||||
args := argsFromType(pair.inType, pair.outType).With("Scope", types.Ref(conversionPackagePath, "Scope")).With("fn", g.manualConversions[pair])
|
||||
sw.Do("if err := s.AddConversionFunc((*$.inType|raw$)(nil), (*$.outType|raw$)(nil), func(a, b interface{}, scope $.Scope|raw$) error { return $.fn|raw$(a.(*$.inType|raw$), b.(*$.outType|raw$), scope) }); err != nil { return err }\n", args)
|
||||
}
|
||||
|
||||
sw.Do("return nil\n", nil)
|
||||
sw.Do("}\n\n", nil)
|
||||
return sw.Error()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user