Merge pull request #9958 from smarterclayton/use_copier

Use runtime.Copier instead of hardcoding api.Scheme
pull/6/head
Robert Bailey 2015-06-26 17:11:48 -07:00
commit 8ee63307e4
2 changed files with 8 additions and 8 deletions

View File

@ -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.
// TODO(dbsmith): implement directly instead of via Encode/Decode
// TODO(claytonc): Copy cannot be used for objects which do not encode type information, such
// as lists of runtime.Objects
func (s *Scheme) Copy(obj Object) (Object, error) {
data, err := s.EncodeToVersion(obj, "")
func (s *Scheme) Copy(src Object) (Object, error) {
dst, err := s.raw.DeepCopy(src)
if err != nil {
return nil, err
}
return s.Decode(data)
return dst.(Object), nil
}
func (s *Scheme) CopyOrDie(obj Object) Object {

View File

@ -102,6 +102,7 @@ func recordEtcdRequestLatency(verb, resource string, startTime time.Time) {
type EtcdHelper struct {
Client EtcdGetSet
Codec runtime.Codec
Copier runtime.ObjectCopier
// optional, no atomic operations can be performed without this interface
Versioner EtcdVersioner
// prefix for all etcd keys
@ -119,11 +120,13 @@ type EtcdHelper struct {
// NewEtcdHelper creates a helper that works against objects that use the internal
// Kubernetes API objects.
// TODO: Refactor to take a runtiem.ObjectCopier
func NewEtcdHelper(client EtcdGetSet, codec runtime.Codec, prefix string) EtcdHelper {
return EtcdHelper{
Client: client,
Codec: codec,
Versioner: APIObjectVersioner{},
Copier: api.Scheme,
PathPrefix: prefix,
cache: util.NewCache(maxEtcdCacheEntries),
}
@ -237,7 +240,7 @@ func (h *EtcdHelper) getFromCache(index uint64) (runtime.Object, bool) {
if found {
// We should not return the object itself to avoid poluting the cache if someone
// modifies returned values.
objCopy, err := api.Scheme.DeepCopy(obj)
objCopy, err := h.Copier.Copy(obj.(runtime.Object))
if err != nil {
glog.Errorf("Error during DeepCopy of cached object: %q", err)
return nil, false
@ -254,7 +257,7 @@ func (h *EtcdHelper) addToCache(index uint64, obj runtime.Object) {
defer func() {
cacheAddLatency.Observe(float64(time.Since(startTime) / time.Microsecond))
}()
objCopy, err := api.Scheme.DeepCopy(obj)
objCopy, err := h.Copier.Copy(obj)
if err != nil {
glog.Errorf("Error during DeepCopy of cached object: %q", err)
return