75
vendor/k8s.io/apimachinery/pkg/runtime/scheme.go
generated
vendored
75
vendor/k8s.io/apimachinery/pkg/runtime/scheme.go
generated
vendored
@@ -18,7 +18,6 @@ package runtime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@@ -105,9 +104,6 @@ func NewScheme() *Scheme {
|
||||
// Enable couple default conversions by default.
|
||||
utilruntime.Must(RegisterEmbeddedConversions(s))
|
||||
utilruntime.Must(RegisterStringConversions(s))
|
||||
|
||||
utilruntime.Must(s.RegisterInputDefaults(&map[string][]string{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields))
|
||||
utilruntime.Must(s.RegisterInputDefaults(&url.Values{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields))
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -133,12 +129,6 @@ func (s *Scheme) nameFunc(t reflect.Type) string {
|
||||
return gvks[0].Kind
|
||||
}
|
||||
|
||||
// fromScope gets the input version, desired output version, and desired Scheme
|
||||
// from a conversion.Scope.
|
||||
func (s *Scheme) fromScope(scope conversion.Scope) *Scheme {
|
||||
return s
|
||||
}
|
||||
|
||||
// Converter allows access to the converter for the scheme
|
||||
func (s *Scheme) Converter() *conversion.Converter {
|
||||
return s.converter
|
||||
@@ -211,6 +201,19 @@ func (s *Scheme) AddKnownTypeWithName(gvk schema.GroupVersionKind, obj Object) {
|
||||
}
|
||||
}
|
||||
s.typeToGVK[t] = append(s.typeToGVK[t], gvk)
|
||||
|
||||
// if the type implements DeepCopyInto(<obj>), register a self-conversion
|
||||
if m := reflect.ValueOf(obj).MethodByName("DeepCopyInto"); m.IsValid() && m.Type().NumIn() == 1 && m.Type().NumOut() == 0 && m.Type().In(0) == reflect.TypeOf(obj) {
|
||||
if err := s.AddGeneratedConversionFunc(obj, obj, func(a, b interface{}, scope conversion.Scope) error {
|
||||
// copy a to b
|
||||
reflect.ValueOf(a).MethodByName("DeepCopyInto").Call([]reflect.Value{reflect.ValueOf(b)})
|
||||
// clear TypeMeta to match legacy reflective conversion
|
||||
b.(Object).GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{})
|
||||
return nil
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// KnownTypes returns the types known for the given version.
|
||||
@@ -226,6 +229,32 @@ func (s *Scheme) KnownTypes(gv schema.GroupVersion) map[string]reflect.Type {
|
||||
return types
|
||||
}
|
||||
|
||||
// VersionsForGroupKind returns the versions that a particular GroupKind can be converted to within the given group.
|
||||
// A GroupKind might be converted to a different group. That information is available in EquivalentResourceMapper.
|
||||
func (s *Scheme) VersionsForGroupKind(gk schema.GroupKind) []schema.GroupVersion {
|
||||
availableVersions := []schema.GroupVersion{}
|
||||
for gvk := range s.gvkToType {
|
||||
if gk != gvk.GroupKind() {
|
||||
continue
|
||||
}
|
||||
|
||||
availableVersions = append(availableVersions, gvk.GroupVersion())
|
||||
}
|
||||
|
||||
// order the return for stability
|
||||
ret := []schema.GroupVersion{}
|
||||
for _, version := range s.PrioritizedVersionsForGroup(gk.Group) {
|
||||
for _, availableVersion := range availableVersions {
|
||||
if version != availableVersion {
|
||||
continue
|
||||
}
|
||||
ret = append(ret, availableVersion)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// AllKnownTypes returns the all known types.
|
||||
func (s *Scheme) AllKnownTypes() map[schema.GroupVersionKind]reflect.Type {
|
||||
return s.gvkToType
|
||||
@@ -296,11 +325,6 @@ func (s *Scheme) New(kind schema.GroupVersionKind) (Object, error) {
|
||||
return nil, NewNotRegisteredErrForKind(s.schemeName, kind)
|
||||
}
|
||||
|
||||
// Log sets a logger on the scheme. For test purposes only
|
||||
func (s *Scheme) Log(l conversion.DebugLogger) {
|
||||
s.converter.Debug = l
|
||||
}
|
||||
|
||||
// AddIgnoredConversionType identifies a pair of types that should be skipped by
|
||||
// conversion (because the data inside them is explicitly dropped during
|
||||
// conversion).
|
||||
@@ -329,14 +353,6 @@ func (s *Scheme) AddFieldLabelConversionFunc(gvk schema.GroupVersionKind, conver
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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
|
||||
// a specific input type in conversion, such as a map[string]string to structs.
|
||||
func (s *Scheme) RegisterInputDefaults(in interface{}, fn conversion.FieldMappingFunc, defaultFlags conversion.FieldMatchingFlags) error {
|
||||
return s.converter.RegisterInputDefaults(in, fn, defaultFlags)
|
||||
}
|
||||
|
||||
// AddTypeDefaultingFunc registers a function that is passed a pointer to an
|
||||
// object and can default fields on the object. These functions will be invoked
|
||||
// when Default() is called. The function will never be called unless the
|
||||
@@ -420,12 +436,9 @@ func (s *Scheme) Convert(in, out interface{}, context interface{}) error {
|
||||
in = typed
|
||||
}
|
||||
|
||||
flags, meta := s.generateConvertMeta(in)
|
||||
meta := s.generateConvertMeta(in)
|
||||
meta.Context = context
|
||||
if flags == 0 {
|
||||
flags = conversion.AllowDifferentFieldTypeNames
|
||||
}
|
||||
return s.converter.Convert(in, out, flags, meta)
|
||||
return s.converter.Convert(in, out, meta)
|
||||
}
|
||||
|
||||
// ConvertFieldLabel alters the given field label and value for an kind field selector from
|
||||
@@ -522,9 +535,9 @@ func (s *Scheme) convertToVersion(copy bool, in Object, target GroupVersioner) (
|
||||
in = in.DeepCopyObject()
|
||||
}
|
||||
|
||||
flags, meta := s.generateConvertMeta(in)
|
||||
meta := s.generateConvertMeta(in)
|
||||
meta.Context = target
|
||||
if err := s.converter.Convert(in, out, flags, meta); err != nil {
|
||||
if err := s.converter.Convert(in, out, meta); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -552,7 +565,7 @@ func (s *Scheme) unstructuredToTyped(in Unstructured) (Object, error) {
|
||||
}
|
||||
|
||||
// generateConvertMeta constructs the meta value we pass to Convert.
|
||||
func (s *Scheme) generateConvertMeta(in interface{}) (conversion.FieldMatchingFlags, *conversion.Meta) {
|
||||
func (s *Scheme) generateConvertMeta(in interface{}) *conversion.Meta {
|
||||
return s.converter.DefaultMeta(reflect.TypeOf(in))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user