Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c0dbe9a9
Commit
c0dbe9a9
authored
Aug 15, 2017
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubectl: simplify deepcopy calls
parent
1d633b7f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
40 additions
and
39 deletions
+40
-39
drain_test.go
pkg/kubectl/cmd/drain_test.go
+1
-2
patch_test.go
pkg/kubectl/cmd/patch_test.go
+2
-7
taint_test.go
pkg/kubectl/cmd/taint_test.go
+1
-2
editoptions.go
pkg/kubectl/cmd/util/editor/editoptions.go
+1
-4
delete_test.go
pkg/kubectl/delete_test.go
+2
-5
rolling_updater.go
pkg/kubectl/rolling_updater.go
+4
-12
BUILD
pkg/kubectl/testing/BUILD
+1
-0
doc.go
pkg/kubectl/testing/doc.go
+19
-0
zz_generated.deepcopy.go
pkg/kubectl/testing/zz_generated.deepcopy.go
+9
-7
No files found.
pkg/kubectl/cmd/drain_test.go
View file @
c0dbe9a9
...
...
@@ -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
())
}
...
...
pkg/kubectl/cmd/patch_test.go
View file @
c0dbe9a9
...
...
@@ -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
{}
}
...
...
pkg/kubectl/cmd/taint_test.go
View file @
c0dbe9a9
...
...
@@ -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
...
...
pkg/kubectl/cmd/util/editor/editoptions.go
View file @
c0dbe9a9
...
...
@@ -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
{
...
...
pkg/kubectl/delete_test.go
View file @
c0dbe9a9
...
...
@@ -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
...
...
pkg/kubectl/rolling_updater.go
View file @
c0dbe9a9
...
...
@@ -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
{
...
...
pkg/kubectl/testing/BUILD
View file @
c0dbe9a9
...
...
@@ -6,6 +6,7 @@ load(
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"types.generated.go",
"types.go",
"zz_generated.deepcopy.go",
...
...
pkg/kubectl/testing/doc.go
0 → 100644
View file @
c0dbe9a9
/*
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
pkg/kubectl/testing/zz_generated.deepcopy.go
View file @
c0dbe9a9
...
...
@@ -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
}
// DeepCopy
Into
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment