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
2d5624bb
Commit
2d5624bb
authored
Aug 15, 2017
by
Kubernetes Submit Queue
Committed by
GitHub
Aug 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #50681 from sttts/sttts-deepcopy-calls-apiserver
Automatic merge from submit-queue apiserver: simplify deepcopy calls
parents
28a5ecb9
b2442224
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
20 additions
and
79 deletions
+20
-79
apiserver_test.go
staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go
+3
-15
doc.go
staging/src/k8s.io/apiserver/pkg/endpoints/testing/doc.go
+1
-1
store.go
...c/k8s.io/apiserver/pkg/registry/generic/registry/store.go
+6
-13
resttest.go
...c/k8s.io/apiserver/pkg/registry/rest/resttest/resttest.go
+0
-0
update.go
staging/src/k8s.io/apiserver/pkg/registry/rest/update.go
+1
-4
cacher.go
staging/src/k8s.io/apiserver/pkg/storage/cacher.go
+5
-23
etcd_helper.go
staging/src/k8s.io/apiserver/pkg/storage/etcd/etcd_helper.go
+2
-11
etcd_watcher_test.go
...rc/k8s.io/apiserver/pkg/storage/etcd/etcd_watcher_test.go
+1
-6
cacher_test.go
...ing/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go
+1
-6
No files found.
staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go
View file @
2d5624bb
...
...
@@ -490,11 +490,7 @@ func (storage *SimpleRESTStorage) Get(ctx request.Context, id string, options *m
if
id
==
"binary"
{
return
storage
.
stream
,
storage
.
errors
[
"get"
]
}
copied
,
err
:=
scheme
.
Copy
(
&
storage
.
item
)
if
err
!=
nil
{
panic
(
err
)
}
return
copied
,
storage
.
errors
[
"get"
]
return
storage
.
item
.
DeepCopy
(),
storage
.
errors
[
"get"
]
}
func
(
storage
*
SimpleRESTStorage
)
checkContext
(
ctx
request
.
Context
)
{
...
...
@@ -748,11 +744,7 @@ func (storage *SimpleTypedStorage) New() runtime.Object {
func
(
storage
*
SimpleTypedStorage
)
Get
(
ctx
request
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
storage
.
checkContext
(
ctx
)
copied
,
err
:=
scheme
.
Copy
(
storage
.
item
)
if
err
!=
nil
{
panic
(
err
)
}
return
copied
,
storage
.
errors
[
"get"
]
return
storage
.
item
.
DeepCopyObject
(),
storage
.
errors
[
"get"
]
}
func
(
storage
*
SimpleTypedStorage
)
checkContext
(
ctx
request
.
Context
)
{
...
...
@@ -3876,11 +3868,7 @@ func (storage *SimpleXGSubresourceRESTStorage) New() runtime.Object {
}
func
(
storage
*
SimpleXGSubresourceRESTStorage
)
Get
(
ctx
request
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
copied
,
err
:=
scheme
.
Copy
(
&
storage
.
item
)
if
err
!=
nil
{
panic
(
err
)
}
return
copied
,
nil
return
storage
.
item
.
DeepCopyObject
(),
nil
}
func
TestXGSubresource
(
t
*
testing
.
T
)
{
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/testing/doc.go
View file @
2d5624bb
...
...
@@ -16,4 +16,4 @@ limitations under the License.
// +k8s:deepcopy-gen=package
package
testing
// import "k8s.io/apiserver/pkg/endpoints/testing"
package
testing
staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go
View file @
2d5624bb
...
...
@@ -1048,18 +1048,6 @@ func (e *Store) Delete(ctx genericapirequest.Context, name string, options *meta
return
out
,
true
,
err
}
// copyListOptions copies list options for mutation.
func
copyListOptions
(
options
*
metainternalversion
.
ListOptions
)
*
metainternalversion
.
ListOptions
{
if
options
==
nil
{
return
&
metainternalversion
.
ListOptions
{}
}
copied
,
err
:=
metainternalversion
.
Copier
.
Copy
(
options
)
if
err
!=
nil
{
panic
(
err
)
}
return
copied
.
(
*
metainternalversion
.
ListOptions
)
}
// DeleteCollection removes all items returned by List with a given ListOptions from storage.
//
// DeleteCollection is currently NOT atomic. It can happen that only subset of objects
...
...
@@ -1071,10 +1059,15 @@ func copyListOptions(options *metainternalversion.ListOptions) *metainternalvers
// possibly with storage API, but watch is not delivered correctly then).
// It will be possible to fix it with v3 etcd API.
func
(
e
*
Store
)
DeleteCollection
(
ctx
genericapirequest
.
Context
,
options
*
metav1
.
DeleteOptions
,
listOptions
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
if
listOptions
==
nil
{
listOptions
=
&
metainternalversion
.
ListOptions
{}
}
else
{
listOptions
=
listOptions
.
DeepCopy
()
}
// DeleteCollection must remain backwards compatible with old clients that expect it to
// remove all resources, initialized or not, within the type. It is also consistent with
// Delete which does not require IncludeUninitialized
listOptions
=
copyListOptions
(
listOptions
)
listOptions
.
IncludeUninitialized
=
true
listObj
,
err
:=
e
.
List
(
ctx
,
listOptions
)
...
...
staging/src/k8s.io/apiserver/pkg/registry/rest/resttest/resttest.go
View file @
2d5624bb
This diff is collapsed.
Click to expand it.
staging/src/k8s.io/apiserver/pkg/registry/rest/update.go
View file @
2d5624bb
...
...
@@ -172,10 +172,7 @@ func (i *defaultUpdatedObjectInfo) UpdatedObject(ctx genericapirequest.Context,
// so we don't return the original. BeforeUpdate can mutate the returned object, doing things like clearing ResourceVersion.
// If we're re-called, we need to be able to return the pristine version.
if
newObj
!=
nil
{
newObj
,
err
=
i
.
copier
.
Copy
(
newObj
)
if
err
!=
nil
{
return
nil
,
err
}
newObj
=
newObj
.
DeepCopyObject
()
}
// Allow any configured transformers to update the new object
...
...
staging/src/k8s.io/apiserver/pkg/storage/cacher.go
View file @
2d5624bb
...
...
@@ -543,11 +543,8 @@ func (c *Cacher) GuaranteedUpdate(
if
elem
,
exists
,
err
:=
c
.
watchCache
.
GetByKey
(
key
);
err
!=
nil
{
glog
.
Errorf
(
"GetByKey returned error: %v"
,
err
)
}
else
if
exists
{
currObj
,
copyErr
:=
c
.
copier
.
Copy
(
elem
.
(
*
storeElement
)
.
Object
)
if
copyErr
==
nil
{
return
c
.
storage
.
GuaranteedUpdate
(
ctx
,
key
,
ptrToType
,
ignoreNotFound
,
preconditions
,
tryUpdate
,
currObj
)
}
glog
.
Errorf
(
"couldn't copy object: %v"
,
copyErr
)
currObj
:=
elem
.
(
*
storeElement
)
.
Object
.
DeepCopyObject
()
return
c
.
storage
.
GuaranteedUpdate
(
ctx
,
key
,
ptrToType
,
ignoreNotFound
,
preconditions
,
tryUpdate
,
currObj
)
}
// If we couldn't get the object, fallback to no-suggestion.
return
c
.
storage
.
GuaranteedUpdate
(
ctx
,
key
,
ptrToType
,
ignoreNotFound
,
preconditions
,
tryUpdate
)
...
...
@@ -877,26 +874,11 @@ func (c *cacheWatcher) sendWatchCacheEvent(event *watchCacheEvent) {
var
watchEvent
watch
.
Event
switch
{
case
curObjPasses
&&
!
oldObjPasses
:
object
,
err
:=
c
.
copier
.
Copy
(
event
.
Object
)
if
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"unexpected copy error: %v"
,
err
))
return
}
watchEvent
=
watch
.
Event
{
Type
:
watch
.
Added
,
Object
:
object
}
watchEvent
=
watch
.
Event
{
Type
:
watch
.
Added
,
Object
:
event
.
Object
.
DeepCopyObject
()}
case
curObjPasses
&&
oldObjPasses
:
object
,
err
:=
c
.
copier
.
Copy
(
event
.
Object
)
if
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"unexpected copy error: %v"
,
err
))
return
}
watchEvent
=
watch
.
Event
{
Type
:
watch
.
Modified
,
Object
:
object
}
watchEvent
=
watch
.
Event
{
Type
:
watch
.
Modified
,
Object
:
event
.
Object
.
DeepCopyObject
()}
case
!
curObjPasses
&&
oldObjPasses
:
object
,
err
:=
c
.
copier
.
Copy
(
event
.
PrevObject
)
if
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"unexpected copy error: %v"
,
err
))
return
}
watchEvent
=
watch
.
Event
{
Type
:
watch
.
Deleted
,
Object
:
object
}
watchEvent
=
watch
.
Event
{
Type
:
watch
.
Deleted
,
Object
:
event
.
PrevObject
.
DeepCopyObject
()}
}
// We need to ensure that if we put event X to the c.result, all
...
...
staging/src/k8s.io/apiserver/pkg/storage/etcd/etcd_helper.go
View file @
2d5624bb
...
...
@@ -612,12 +612,7 @@ func (h *etcdHelper) getFromCache(index uint64, filter storage.FilterFunc) (runt
}
// We should not return the object itself to avoid polluting the cache if someone
// modifies returned values.
objCopy
,
err
:=
h
.
copier
.
Copy
(
obj
.
(
runtime
.
Object
))
if
err
!=
nil
{
glog
.
Errorf
(
"Error during DeepCopy of cached object: %q"
,
err
)
// We can't return a copy, thus we report the object as not found.
return
nil
,
false
}
objCopy
:=
obj
.
(
runtime
.
Object
)
.
DeepCopyObject
()
metrics
.
ObserveCacheHit
()
return
objCopy
.
(
runtime
.
Object
),
true
}
...
...
@@ -630,11 +625,7 @@ func (h *etcdHelper) addToCache(index uint64, obj runtime.Object) {
defer
func
()
{
metrics
.
ObserveAddCache
(
startTime
)
}()
objCopy
,
err
:=
h
.
copier
.
Copy
(
obj
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error during DeepCopy of cached object: %q"
,
err
)
return
}
objCopy
:=
obj
.
DeepCopyObject
()
isOverwrite
:=
h
.
cache
.
Add
(
index
,
objCopy
)
if
!
isOverwrite
{
metrics
.
ObserveNewEntry
()
...
...
staging/src/k8s.io/apiserver/pkg/storage/etcd/etcd_watcher_test.go
View file @
2d5624bb
...
...
@@ -373,12 +373,7 @@ func TestWatchEtcdState(t *testing.T) {
// CAS the previous value
updateFn
:=
func
(
input
runtime
.
Object
,
res
storage
.
ResponseMeta
)
(
runtime
.
Object
,
*
uint64
,
error
)
{
newObj
,
err
:=
scheme
.
DeepCopy
(
pod
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
return
nil
,
nil
,
err
}
return
newObj
.
(
*
example
.
Pod
),
nil
,
nil
return
pod
.
DeepCopyObject
(),
nil
,
nil
}
err
=
h
.
GuaranteedUpdate
(
context
.
TODO
(),
key
,
&
example
.
Pod
{},
false
,
nil
,
updateFn
)
if
err
!=
nil
{
...
...
staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go
View file @
2d5624bb
...
...
@@ -123,12 +123,7 @@ func makeTestPod(name string) *example.Pod {
func
updatePod
(
t
*
testing
.
T
,
s
storage
.
Interface
,
obj
,
old
*
example
.
Pod
)
*
example
.
Pod
{
updateFn
:=
func
(
input
runtime
.
Object
,
res
storage
.
ResponseMeta
)
(
runtime
.
Object
,
*
uint64
,
error
)
{
newObj
,
err
:=
scheme
.
DeepCopy
(
obj
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
return
nil
,
nil
,
err
}
return
newObj
.
(
*
example
.
Pod
),
nil
,
nil
return
obj
.
DeepCopyObject
(),
nil
,
nil
}
key
:=
"pods/"
+
obj
.
Namespace
+
"/"
+
obj
.
Name
if
err
:=
s
.
GuaranteedUpdate
(
context
.
TODO
(),
key
,
&
example
.
Pod
{},
old
==
nil
,
nil
,
updateFn
);
err
!=
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