summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/runtime/scheme.go')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/runtime/scheme.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go b/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go
index 4b739ec38..3b254961d 100644
--- a/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go
+++ b/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go
@@ -211,6 +211,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.