Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,16 @@ else
fi
echo "${reset}"

echo -ne "Checking for deep-copies that need updating... "
if ! hack/verify-generated-deep-copies.sh > /dev/null; then
echo "${red}ERROR!"
echo "Some deep-copy functions need regeneration."
echo "To regenerate deep-copies, run:"
echo " hack/update-generated-deep-copies.sh"
exit_code=1
else
echo "${green}OK"
fi
echo "${reset}"

exit $exit_code
3 changes: 1 addition & 2 deletions pkg/api/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
apitesting "github.com/GoogleCloudPlatform/kubernetes/pkg/api/testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
)

func TestDeepCopyApiObjects(t *testing.T) {
Expand All @@ -37,7 +36,7 @@ func TestDeepCopyApiObjects(t *testing.T) {
t.Fatalf("Could not create a %s: %s", kind, err)
}
f.Fuzz(item)
itemCopy, err := conversion.DeepCopy(item)
itemCopy, err := api.Scheme.DeepCopy(item)
if err != nil {
t.Errorf("Could not deep copy a %s: %s", kind, err)
continue
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/framework/fake_controller_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"sync"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
Expand Down Expand Up @@ -130,7 +129,7 @@ func (f *FakeControllerSource) List() (runtime.Object, error) {
// Otherwise, if they make a change and write it back, they
// will inadvertently change the our canonical copy (in
// addition to racing with other clients).
objCopy, err := conversion.DeepCopy(obj)
objCopy, err := api.Scheme.DeepCopy(obj)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -167,7 +166,7 @@ func (f *FakeControllerSource) Watch(resourceVersion string) (watch.Interface, e
// it back, they will inadvertently change the our
// canonical copy (in addition to racing with other
// clients).
objCopy, err := conversion.DeepCopy(c.Object)
objCopy, err := api.Scheme.DeepCopy(c.Object)
if err != nil {
return nil, err
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/conversion/cloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ func NewCloner() *Cloner {

// Prevent recursing into every byte...
func byteSliceDeepCopy(in []byte, out *[]byte, c *Cloner) error {
*out = make([]byte, len(in))
copy(*out, in)
if in != nil {
*out = make([]byte, len(in))
copy(*out, in)
} else {
*out = nil
}
return nil
}

Expand Down
114 changes: 0 additions & 114 deletions pkg/conversion/deep_copy.go

This file was deleted.

8 changes: 4 additions & 4 deletions pkg/conversion/deep_copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestDeepCopy(t *testing.T) {
}{},
}
for _, obj := range table {
obj2, err := DeepCopy(obj)
obj2, err := NewCloner().DeepCopy(obj)
if err != nil {
t.Errorf("Error: couldn't copy %#v", obj)
continue
Expand All @@ -51,7 +51,7 @@ func TestDeepCopy(t *testing.T) {

obj3 := reflect.New(reflect.TypeOf(obj)).Interface()
f.Fuzz(obj3)
obj4, err := DeepCopy(obj3)
obj4, err := NewCloner().DeepCopy(obj3)
if err != nil {
t.Errorf("Error: couldn't copy %#v", obj)
continue
Expand All @@ -64,7 +64,7 @@ func TestDeepCopy(t *testing.T) {
}

func copyOrDie(t *testing.T, in interface{}) interface{} {
out, err := DeepCopy(in)
out, err := NewCloner().DeepCopy(in)
if err != nil {
t.Fatalf("DeepCopy failed: %#q: %v", in, err)
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func BenchmarkDeepCopy(b *testing.B) {
var r interface{}
for i := 0; i < b.N; i++ {
for j := range table {
r, _ = DeepCopy(table[j])
r, _ = NewCloner().DeepCopy(table[j])
}
}
result = r
Expand Down
3 changes: 1 addition & 2 deletions pkg/registry/service/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest/resttest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
Expand Down Expand Up @@ -60,7 +59,7 @@ func makeIPNet(t *testing.T) *net.IPNet {
}

func deepCloneService(svc *api.Service) *api.Service {
value, err := conversion.DeepCopy(svc)
value, err := api.Scheme.DeepCopy(svc)
if err != nil {
panic("couldn't copy service")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/runtime/deep_copy_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)

// TODO(wojtek-t): As suggested in #8320, we should consider the strategy
// to first do the shallow copy and then recurse into things that need a
// deep copy (maps, pointers, slices). That sort of copy function would
// need one parameter - a pointer to the thing it's supposed to expand,
// and it would involve a lot less memory copying.
type DeepCopyGenerator interface {
// Adds a type to a generator.
// If the type is non-struct, it will return an error, otherwise deep-copy
Expand Down
4 changes: 2 additions & 2 deletions pkg/runtime/embedded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"reflect"
"testing"

"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestDeepCopyOfEmbeddedObject(t *testing.T) {
}
t.Logf("originalRole = %v\n", string(originalData))

copyOfOriginal, err := conversion.DeepCopy(original)
copyOfOriginal, err := api.Scheme.DeepCopy(original)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/tools/etcd_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strings"
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
Expand Down Expand Up @@ -238,7 +239,7 @@ func (h *EtcdHelper) getFromCache(index uint64) (runtime.Object, bool) {
if found {
// We should not return the object itself to avoid poluting the cache if someone
// modifies returned values.
objCopy, err := conversion.DeepCopy(obj)
objCopy, err := api.Scheme.DeepCopy(obj)
trace.Step("Deep copied")
if err != nil {
glog.Errorf("Error during DeepCopy of cached object: %q", err)
Expand All @@ -256,7 +257,7 @@ func (h *EtcdHelper) addToCache(index uint64, obj runtime.Object) {
defer func() {
cacheAddLatency.Observe(float64(time.Since(startTime) / time.Microsecond))
}()
objCopy, err := conversion.DeepCopy(obj)
objCopy, err := api.Scheme.DeepCopy(obj)
if err != nil {
glog.Errorf("Error during DeepCopy of cached object: %q", err)
return
Expand Down