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
6970dda5
Commit
6970dda5
authored
Jun 17, 2015
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use runtime.Copier instead of hardcoding api.Scheme
Allow other schemes to be supported by etcd_helper.go runtime.Scheme.Copy() should be using the built in DeepCopy()
parent
8ebd8963
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
scheme.go
pkg/runtime/scheme.go
+3
-6
etcd_helper.go
pkg/tools/etcd_helper.go
+5
-2
No files found.
pkg/runtime/scheme.go
View file @
6970dda5
...
@@ -459,15 +459,12 @@ func (s *Scheme) DecodeInto(data []byte, obj Object) error {
...
@@ -459,15 +459,12 @@ func (s *Scheme) DecodeInto(data []byte, obj Object) error {
}
}
// Copy does a deep copy of an API object. Useful mostly for tests.
// Copy does a deep copy of an API object. Useful mostly for tests.
// TODO(dbsmith): implement directly instead of via Encode/Decode
func
(
s
*
Scheme
)
Copy
(
src
Object
)
(
Object
,
error
)
{
// TODO(claytonc): Copy cannot be used for objects which do not encode type information, such
dst
,
err
:=
s
.
raw
.
DeepCopy
(
src
)
// as lists of runtime.Objects
func
(
s
*
Scheme
)
Copy
(
obj
Object
)
(
Object
,
error
)
{
data
,
err
:=
s
.
EncodeToVersion
(
obj
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
s
.
Decode
(
data
)
return
dst
.
(
Object
),
nil
}
}
func
(
s
*
Scheme
)
CopyOrDie
(
obj
Object
)
Object
{
func
(
s
*
Scheme
)
CopyOrDie
(
obj
Object
)
Object
{
...
...
pkg/tools/etcd_helper.go
View file @
6970dda5
...
@@ -102,6 +102,7 @@ func recordEtcdRequestLatency(verb, resource string, startTime time.Time) {
...
@@ -102,6 +102,7 @@ func recordEtcdRequestLatency(verb, resource string, startTime time.Time) {
type
EtcdHelper
struct
{
type
EtcdHelper
struct
{
Client
EtcdGetSet
Client
EtcdGetSet
Codec
runtime
.
Codec
Codec
runtime
.
Codec
Copier
runtime
.
ObjectCopier
// optional, no atomic operations can be performed without this interface
// optional, no atomic operations can be performed without this interface
Versioner
EtcdVersioner
Versioner
EtcdVersioner
// prefix for all etcd keys
// prefix for all etcd keys
...
@@ -119,11 +120,13 @@ type EtcdHelper struct {
...
@@ -119,11 +120,13 @@ type EtcdHelper struct {
// NewEtcdHelper creates a helper that works against objects that use the internal
// NewEtcdHelper creates a helper that works against objects that use the internal
// Kubernetes API objects.
// Kubernetes API objects.
// TODO: Refactor to take a runtiem.ObjectCopier
func
NewEtcdHelper
(
client
EtcdGetSet
,
codec
runtime
.
Codec
,
prefix
string
)
EtcdHelper
{
func
NewEtcdHelper
(
client
EtcdGetSet
,
codec
runtime
.
Codec
,
prefix
string
)
EtcdHelper
{
return
EtcdHelper
{
return
EtcdHelper
{
Client
:
client
,
Client
:
client
,
Codec
:
codec
,
Codec
:
codec
,
Versioner
:
APIObjectVersioner
{},
Versioner
:
APIObjectVersioner
{},
Copier
:
api
.
Scheme
,
PathPrefix
:
prefix
,
PathPrefix
:
prefix
,
cache
:
util
.
NewCache
(
maxEtcdCacheEntries
),
cache
:
util
.
NewCache
(
maxEtcdCacheEntries
),
}
}
...
@@ -237,7 +240,7 @@ func (h *EtcdHelper) getFromCache(index uint64) (runtime.Object, bool) {
...
@@ -237,7 +240,7 @@ func (h *EtcdHelper) getFromCache(index uint64) (runtime.Object, bool) {
if
found
{
if
found
{
// We should not return the object itself to avoid poluting the cache if someone
// We should not return the object itself to avoid poluting the cache if someone
// modifies returned values.
// modifies returned values.
objCopy
,
err
:=
api
.
Scheme
.
DeepCopy
(
obj
)
objCopy
,
err
:=
h
.
Copier
.
Copy
(
obj
.
(
runtime
.
Object
)
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error during DeepCopy of cached object: %q"
,
err
)
glog
.
Errorf
(
"Error during DeepCopy of cached object: %q"
,
err
)
return
nil
,
false
return
nil
,
false
...
@@ -254,7 +257,7 @@ func (h *EtcdHelper) addToCache(index uint64, obj runtime.Object) {
...
@@ -254,7 +257,7 @@ func (h *EtcdHelper) addToCache(index uint64, obj runtime.Object) {
defer
func
()
{
defer
func
()
{
cacheAddLatency
.
Observe
(
float64
(
time
.
Since
(
startTime
)
/
time
.
Microsecond
))
cacheAddLatency
.
Observe
(
float64
(
time
.
Since
(
startTime
)
/
time
.
Microsecond
))
}()
}()
objCopy
,
err
:=
api
.
Scheme
.
Deep
Copy
(
obj
)
objCopy
,
err
:=
h
.
Copier
.
Copy
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error during DeepCopy of cached object: %q"
,
err
)
glog
.
Errorf
(
"Error during DeepCopy of cached object: %q"
,
err
)
return
return
...
...
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