Skip to content

Commit 07b9138

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

File tree

2 files changed

+11
-32
lines changed

2 files changed

+11
-32
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: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,34 +194,30 @@ 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+
// Kubernetes APIs work against Resources, not GroupVersionKinds. Map the
198+
// groupVersionKind to the Resource API we will use.
199+
mapping, err := ip.mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
200+
if err != nil {
201+
return nil, err
202+
}
203+
197204
// Construct a RESTClient for the groupVersionKind that we will use to
198205
// talk to the apiserver.
199206
var client rest.Interface
200-
var err error
207+
var listObj runtime.Object
201208
if isUnstructured {
202209
client, err = apiutil.RESTUnstructuredClientForGVK(gvk, ip.config)
210+
listObj = &unstructured.UnstructuredList{}
203211
} else {
204212
client, err = apiutil.RESTClientForGVK(gvk, ip.config, ip.codecs)
213+
listGVK := gvk.GroupVersion().WithKind(gvk.Kind + "List")
214+
listObj, err = ip.Scheme.New(listGVK)
205215

206216
}
207217
if err != nil {
208218
return nil, err
209219
}
210220

211-
// Kubernetes APIs work against Resources, not GroupVersionKinds. Map the
212-
// groupVersionKind to the Resource API we will use.
213-
mapping, err := ip.mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
214-
if err != nil {
215-
return nil, err
216-
}
217-
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
223-
}
224-
225221
// Create a new ListWatch for the obj
226222
return &cache.ListWatch{
227223
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {

0 commit comments

Comments
 (0)