mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #50682 from sttts/sttts-deepcopy-calls-apimachinery
Automatic merge from submit-queue (batch tested with PRs 50577, 50682) apimachinery: simplify deepcopy calls
This commit is contained in:
commit
28a5ecb91b
@ -19,7 +19,6 @@ package roundtrip
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"strings"
|
||||
@ -269,11 +268,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object
|
||||
original := object
|
||||
|
||||
// deep copy the original object
|
||||
copied, err := scheme.DeepCopy(object)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("unable to copy: %v", err))
|
||||
}
|
||||
object = copied.(runtime.Object)
|
||||
object = object.DeepCopyObject()
|
||||
name := reflect.TypeOf(object).Elem().Name()
|
||||
|
||||
// catch deepcopy errors early
|
||||
|
@ -243,12 +243,8 @@ func TestDeepCopyOfRuntimeObject(t *testing.T) {
|
||||
}
|
||||
t.Logf("originalRole = %v\n", string(originalData))
|
||||
|
||||
copyOfOriginal, err := s.DeepCopy(original)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
copiedData, err := runtime.Encode(codec, copyOfOriginal.(runtime.Object))
|
||||
copyOfOriginal := original.DeepCopy()
|
||||
copiedData, err := runtime.Encode(codec, copyOfOriginal)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -530,11 +530,7 @@ func (s *Scheme) convertToVersion(copy bool, in Object, target GroupVersioner) (
|
||||
}
|
||||
|
||||
if copy {
|
||||
copied, err := s.Copy(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
in = copied
|
||||
in = in.DeepCopyObject()
|
||||
}
|
||||
|
||||
flags, meta := s.generateConvertMeta(in)
|
||||
@ -555,11 +551,7 @@ func (s *Scheme) generateConvertMeta(in interface{}) (conversion.FieldMatchingFl
|
||||
// copyAndSetTargetKind performs a conditional copy before returning the object, or an error if copy was not successful.
|
||||
func copyAndSetTargetKind(copy bool, copier ObjectCopier, obj Object, kind schema.GroupVersionKind) (Object, error) {
|
||||
if copy {
|
||||
copied, err := copier.Copy(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
obj = copied
|
||||
obj = obj.DeepCopyObject()
|
||||
}
|
||||
setTargetKind(obj, kind)
|
||||
return obj, nil
|
||||
|
@ -711,7 +711,7 @@ func TestConvertToVersion(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for i, test := range testCases {
|
||||
original, _ := test.scheme.DeepCopy(test.in)
|
||||
original := test.in.DeepCopyObject()
|
||||
out, err := test.scheme.ConvertToVersion(test.in, test.gv)
|
||||
switch {
|
||||
case test.errFn != nil:
|
||||
|
Loading…
Reference in New Issue
Block a user