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
362439db
Commit
362439db
authored
Aug 15, 2017
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkg/api: simplify deepcopy calls
parent
ce559394
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
35 deletions
+7
-35
copy_test.go
pkg/api/copy_test.go
+1
-6
deep_copy_test.go
pkg/api/deep_copy_test.go
+3
-15
defaulting_test.go
pkg/api/defaulting_test.go
+2
-5
helpers.go
pkg/api/v1/resource/helpers.go
+1
-9
No files found.
pkg/api/copy_test.go
View file @
362439db
...
...
@@ -50,12 +50,7 @@ func doDeepCopyTest(t *testing.T, kind schema.GroupVersionKind, f *fuzz.Fuzzer)
t
.
Fatalf
(
"Could not create a %v: %s"
,
kind
,
err
)
}
f
.
Fuzz
(
item
)
itemCopy
,
err
:=
api
.
Scheme
.
DeepCopy
(
item
)
if
err
!=
nil
{
t
.
Errorf
(
"Could not deep copy a %v: %s"
,
kind
,
err
)
return
}
itemCopy
:=
item
.
DeepCopyObject
()
if
!
reflect
.
DeepEqual
(
item
,
itemCopy
)
{
t
.
Errorf
(
"
\n
expected: %#v
\n\n
got: %#v
\n\n
diff: %v"
,
item
,
itemCopy
,
diff
.
ObjectReflectDiff
(
item
,
itemCopy
))
}
...
...
pkg/api/deep_copy_test.go
View file @
362439db
...
...
@@ -131,11 +131,7 @@ var benchmarkPod api.Pod = api.Pod{
func
BenchmarkPodCopy
(
b
*
testing
.
B
)
{
var
result
*
api
.
Pod
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
obj
,
err
:=
api
.
Scheme
.
DeepCopy
(
&
benchmarkPod
)
if
err
!=
nil
{
b
.
Fatalf
(
"Unexpected error copying pod: %v"
,
err
)
}
result
=
obj
.
(
*
api
.
Pod
)
result
=
benchmarkPod
.
DeepCopy
()
}
if
!
apiequality
.
Semantic
.
DeepEqual
(
benchmarkPod
,
*
result
)
{
b
.
Fatalf
(
"Incorrect copy: expected %v, got %v"
,
benchmarkPod
,
*
result
)
...
...
@@ -154,11 +150,7 @@ func BenchmarkNodeCopy(b *testing.B) {
var
result
*
api
.
Node
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
obj
,
err
:=
api
.
Scheme
.
DeepCopy
(
&
node
)
if
err
!=
nil
{
b
.
Fatalf
(
"Unexpected error copying node: %v"
,
err
)
}
result
=
obj
.
(
*
api
.
Node
)
result
=
node
.
DeepCopy
()
}
if
!
apiequality
.
Semantic
.
DeepEqual
(
node
,
*
result
)
{
b
.
Fatalf
(
"Incorrect copy: expected %v, got %v"
,
node
,
*
result
)
...
...
@@ -177,11 +169,7 @@ func BenchmarkReplicationControllerCopy(b *testing.B) {
var
result
*
api
.
ReplicationController
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
obj
,
err
:=
api
.
Scheme
.
DeepCopy
(
&
replicationController
)
if
err
!=
nil
{
b
.
Fatalf
(
"Unexpected error copying replication controller: %v"
,
err
)
}
result
=
obj
.
(
*
api
.
ReplicationController
)
result
=
replicationController
.
DeepCopy
()
}
if
!
apiequality
.
Semantic
.
DeepEqual
(
replicationController
,
*
result
)
{
b
.
Fatalf
(
"Incorrect copy: expected %v, got %v"
,
replicationController
,
*
result
)
...
...
pkg/api/defaulting_test.go
View file @
362439db
...
...
@@ -187,13 +187,10 @@ func TestDefaulting(t *testing.T) {
src
.
GetObjectKind
()
.
SetGroupVersionKind
(
schema
.
GroupVersionKind
{})
original
,
err
:=
scheme
.
DeepCopy
(
src
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
original
:=
src
.
DeepCopyObject
()
// get internal
withDefaults
,
_
:=
scheme
.
DeepCopy
(
src
)
withDefaults
:=
src
.
DeepCopyObject
(
)
scheme
.
Default
(
withDefaults
.
(
runtime
.
Object
))
if
!
reflect
.
DeepEqual
(
original
,
withDefaults
)
{
...
...
pkg/api/v1/resource/helpers.go
View file @
362439db
...
...
@@ -123,15 +123,7 @@ func ExtractResourceValueByContainerNameAndNodeAllocatable(copier deepCopier, fs
return
""
,
err
}
containerCopy
,
err
:=
copier
.
DeepCopy
(
realContainer
)
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to perform a deep copy of container object: %v"
,
err
)
}
container
,
ok
:=
containerCopy
.
(
*
v1
.
Container
)
if
!
ok
{
return
""
,
fmt
.
Errorf
(
"unexpected type returned from deep copy of container object"
)
}
container
:=
realContainer
.
DeepCopy
()
MergeContainerResourceLimits
(
container
,
nodeAllocatable
)
...
...
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