Skip to content

Commit 6d5cca3

Browse files
author
Shawn Hurley
committed
remove cache reader marshal/unmarshal
1 parent 3127304 commit 6d5cca3

File tree

2 files changed

+20
-36
lines changed

2 files changed

+20
-36
lines changed

pkg/cache/internal/cache_reader.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ package internal
1818

1919
import (
2020
"context"
21-
"encoding/json"
2221
"fmt"
2322
"reflect"
2423

2524
"k8s.io/apimachinery/pkg/api/errors"
2625
apimeta "k8s.io/apimachinery/pkg/api/meta"
27-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2826
"k8s.io/apimachinery/pkg/fields"
2927
"k8s.io/apimachinery/pkg/labels"
3028
"k8s.io/apimachinery/pkg/runtime"
@@ -75,21 +73,6 @@ func (c *CacheReader) Get(_ context.Context, key client.ObjectKey, out runtime.O
7573
// TODO(directxman12): revisit the decision to always deepcopy
7674
obj = obj.(runtime.Object).DeepCopyObject()
7775

78-
// If out is supposed to be unstructured handle correctly.
79-
if o, ok := out.(*unstructured.Unstructured); ok {
80-
//Encode the obj to a map[string]interface and et the out.Object
81-
b, err := json.Marshal(obj)
82-
if err != nil {
83-
return err
84-
}
85-
err = json.Unmarshal(b, o)
86-
if err != nil {
87-
return err
88-
}
89-
o.SetGroupVersionKind(c.groupVersionKind)
90-
return nil
91-
}
92-
9376
// Copy the value of the item in the cache to the returned value
9477
// TODO(directxman12): this is a terrible hack, pls fix (we should have deepcopyinto)
9578
outVal := reflect.ValueOf(out)

pkg/cache/internal/informers_map.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,32 +194,33 @@ func (ip *InformersMap) Get(gvk schema.GroupVersionKind, obj runtime.Object) (*M
194194

195195
// newListWatch returns a new ListWatch object that can be used to create a SharedIndexInformer.
196196
func (ip *InformersMap) newListWatch(gvk schema.GroupVersionKind, isUnstructured bool) (*cache.ListWatch, error) {
197-
// Construct a RESTClient for the groupVersionKind that we will use to
198-
// talk to the apiserver.
199-
var client rest.Interface
200-
var err error
201-
if isUnstructured {
202-
client, err = apiutil.RESTUnstructuredClientForGVK(gvk, ip.config)
203-
} else {
204-
client, err = apiutil.RESTClientForGVK(gvk, ip.config, ip.codecs)
205-
206-
}
207-
if err != nil {
208-
return nil, err
209-
}
210-
211197
// Kubernetes APIs work against Resources, not GroupVersionKinds. Map the
212198
// groupVersionKind to the Resource API we will use.
213199
mapping, err := ip.mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
214200
if err != nil {
215201
return nil, err
216202
}
217203

218-
// Get a listObject for listing that the ListWatch can DeepCopy
219-
listGVK := gvk.GroupVersion().WithKind(gvk.Kind + "List")
220-
listObj, err := ip.Scheme.New(listGVK)
221-
if err != nil {
222-
return nil, err
204+
// Construct a RESTClient for the groupVersionKind that we will use to
205+
// talk to the apiserver.
206+
var client rest.Interface
207+
var listObj runtime.Object
208+
if isUnstructured {
209+
listObj = &unstructured.UnstructuredList{}
210+
client, err = apiutil.RESTUnstructuredClientForGVK(gvk, ip.config)
211+
if err != nil {
212+
return nil, err
213+
}
214+
} else {
215+
client, err = apiutil.RESTClientForGVK(gvk, ip.config, ip.codecs)
216+
if err != nil {
217+
return nil, err
218+
}
219+
listGVK := gvk.GroupVersion().WithKind(gvk.Kind + "List")
220+
listObj, err = ip.Scheme.New(listGVK)
221+
if err != nil {
222+
return nil, err
223+
}
223224
}
224225

225226
// Create a new ListWatch for the obj

0 commit comments

Comments
 (0)