mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #50756 from sttts/sttts-deepcopy-calls-kubectl
Automatic merge from submit-queue (batch tested with PRs 41901, 50762, 50756) kubectl: simplify deepcopy calls
This commit is contained in:
commit
929f138319
@ -74,10 +74,9 @@ func TestMain(m *testing.M) {
|
||||
},
|
||||
Status: v1.NodeStatus{},
|
||||
}
|
||||
clone, _ := api.Scheme.DeepCopy(node)
|
||||
|
||||
// A copy of the same node, but cordoned.
|
||||
cordoned_node = clone.(*v1.Node)
|
||||
cordoned_node = node.DeepCopy()
|
||||
cordoned_node.Spec.Unschedulable = true
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
@ -130,8 +130,7 @@ func TestPatchNoop(t *testing.T) {
|
||||
|
||||
// Patched
|
||||
{
|
||||
copied, _ := api.Scheme.DeepCopy(patchObject)
|
||||
patchObject = copied.(*api.Service)
|
||||
patchObject = patchObject.DeepCopy()
|
||||
if patchObject.Annotations == nil {
|
||||
patchObject.Annotations = map[string]string{}
|
||||
}
|
||||
@ -150,11 +149,7 @@ func TestPatchNoop(t *testing.T) {
|
||||
func TestPatchObjectFromFileOutput(t *testing.T) {
|
||||
_, svc, _ := testData()
|
||||
|
||||
svcCopyObj, err := api.Scheme.DeepCopy(&svc.Items[0])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
svcCopy := svcCopyObj.(*api.Service)
|
||||
svcCopy := svc.Items[0].DeepCopy()
|
||||
if svcCopy.Labels == nil {
|
||||
svcCopy.Labels = map[string]string{}
|
||||
}
|
||||
|
@ -49,10 +49,9 @@ func generateNodeAndTaintedNode(oldTaints []v1.Taint, newTaints []v1.Taint) (*v1
|
||||
},
|
||||
Status: v1.NodeStatus{},
|
||||
}
|
||||
clone, _ := api.Scheme.DeepCopy(node)
|
||||
|
||||
// A copy of the same node, but tainted.
|
||||
taintedNode = clone.(*v1.Node)
|
||||
taintedNode = node.DeepCopy()
|
||||
taintedNode.Spec.Taints = newTaints
|
||||
|
||||
return node, taintedNode
|
||||
|
@ -445,10 +445,7 @@ func GetApplyPatch(obj runtime.Object, codec runtime.Encoder) ([]byte, []byte, t
|
||||
if err != nil {
|
||||
return nil, []byte(""), types.MergePatchType, err
|
||||
}
|
||||
objCopy, err := api.Scheme.Copy(obj)
|
||||
if err != nil {
|
||||
return nil, beforeJSON, types.MergePatchType, err
|
||||
}
|
||||
objCopy := obj.DeepCopyObject()
|
||||
accessor := meta.NewAccessor()
|
||||
annotations, err := accessor.Annotations(objCopy)
|
||||
if err != nil {
|
||||
|
@ -201,10 +201,7 @@ func TestReplicationControllerStop(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
copiedForWatch, err := api.Scheme.Copy(test.Objs[0])
|
||||
if err != nil {
|
||||
t.Fatalf("%s unexpected error: %v", test.Name, err)
|
||||
}
|
||||
copiedForWatch := test.Objs[0].DeepCopyObject()
|
||||
fake := fake.NewSimpleClientset(test.Objs...)
|
||||
fakeWatch := watch.NewFake()
|
||||
fake.PrependWatchReactor("replicationcontrollers", testcore.DefaultWatchReactor(fakeWatch, nil))
|
||||
@ -214,7 +211,7 @@ func TestReplicationControllerStop(t *testing.T) {
|
||||
}()
|
||||
|
||||
reaper := ReplicationControllerReaper{fake.Core(), time.Millisecond, time.Millisecond}
|
||||
err = reaper.Stop(ns, name, 0, nil)
|
||||
err := reaper.Stop(ns, name, 0, nil)
|
||||
if !reflect.DeepEqual(err, test.StopError) {
|
||||
t.Errorf("%s unexpected error: %v", test.Name, err)
|
||||
continue
|
||||
|
@ -772,12 +772,8 @@ type updateRcFunc func(controller *api.ReplicationController)
|
||||
// 3. Update the resource
|
||||
func updateRcWithRetries(rcClient coreclient.ReplicationControllersGetter, namespace string, rc *api.ReplicationController, applyUpdate updateRcFunc) (*api.ReplicationController, error) {
|
||||
// Deep copy the rc in case we failed on Get during retry loop
|
||||
obj, err := api.Scheme.Copy(rc)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to deep copy rc before updating it: %v", err)
|
||||
}
|
||||
oldRc := obj.(*api.ReplicationController)
|
||||
err = retry.RetryOnConflict(retry.DefaultBackoff, func() (e error) {
|
||||
oldRc := rc.DeepCopy()
|
||||
err := retry.RetryOnConflict(retry.DefaultBackoff, func() (e error) {
|
||||
// Apply the update, then attempt to push it to the apiserver.
|
||||
applyUpdate(rc)
|
||||
if rc, e = rcClient.ReplicationControllers(namespace).Update(rc); e == nil {
|
||||
@ -807,12 +803,8 @@ type updatePodFunc func(controller *api.Pod)
|
||||
// 3. Update the resource
|
||||
func updatePodWithRetries(podClient coreclient.PodsGetter, namespace string, pod *api.Pod, applyUpdate updatePodFunc) (*api.Pod, error) {
|
||||
// Deep copy the pod in case we failed on Get during retry loop
|
||||
obj, err := api.Scheme.Copy(pod)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to deep copy pod before updating it: %v", err)
|
||||
}
|
||||
oldPod := obj.(*api.Pod)
|
||||
err = retry.RetryOnConflict(retry.DefaultBackoff, func() (e error) {
|
||||
oldPod := pod.DeepCopy()
|
||||
err := retry.RetryOnConflict(retry.DefaultBackoff, func() (e error) {
|
||||
// Apply the update, then attempt to push it to the apiserver.
|
||||
applyUpdate(pod)
|
||||
if pod, e = podClient.Pods(namespace).Update(pod); e == nil {
|
||||
|
@ -6,6 +6,7 @@ load(
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"types.generated.go",
|
||||
"types.go",
|
||||
"zz_generated.deepcopy.go",
|
||||
|
19
pkg/kubectl/testing/doc.go
Normal file
19
pkg/kubectl/testing/doc.go
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// +k8s:deepcopy-gen=package
|
||||
|
||||
package testing
|
@ -26,7 +26,9 @@ import (
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// Deprecated: GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||
//
|
||||
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
|
||||
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
|
||||
return []conversion.GeneratedDeepCopyFunc{
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
@ -61,19 +63,19 @@ func (in *TestStruct) DeepCopyInto(out *TestStruct) {
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, creating a new TestStruct.
|
||||
func (x *TestStruct) DeepCopy() *TestStruct {
|
||||
if x == nil {
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestStruct.
|
||||
func (in *TestStruct) DeepCopy() *TestStruct {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(TestStruct)
|
||||
x.DeepCopyInto(out)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (x *TestStruct) DeepCopyObject() runtime.Object {
|
||||
if c := x.DeepCopy(); c != nil {
|
||||
func (in *TestStruct) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
} else {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user