Skip to content

Commit a285a4f

Browse files
committed
improvements: cache now considers disable protobuf flag for lookup
1 parent 45ba50e commit a285a4f

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

pkg/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ func newClient(config *rest.Config, options Options) (*client, error) {
151151
mapper: options.Mapper,
152152
codecs: serializer.NewCodecFactory(options.Scheme),
153153

154-
structuredResourceByType: make(map[schema.GroupVersionKind]*resourceMeta),
155-
unstructuredResourceByType: make(map[schema.GroupVersionKind]*resourceMeta),
154+
structuredResourceByType: make(map[cacheKey]*resourceMeta),
155+
unstructuredResourceByType: make(map[cacheKey]*resourceMeta),
156156
}
157157

158158
rawMetaClient, err := metadata.NewForConfigAndClient(metadata.ConfigFor(config), options.HTTPClient)

pkg/client/client_rest_resources.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ type clientRestResources struct {
4949
codecs serializer.CodecFactory
5050

5151
// structuredResourceByType stores structured type metadata
52-
structuredResourceByType map[schema.GroupVersionKind]*resourceMeta
52+
structuredResourceByType map[cacheKey]*resourceMeta
53+
5354
// unstructuredResourceByType stores unstructured type metadata
54-
unstructuredResourceByType map[schema.GroupVersionKind]*resourceMeta
55-
mu sync.RWMutex
55+
unstructuredResourceByType map[cacheKey]*resourceMeta
56+
57+
mu sync.RWMutex
58+
}
59+
60+
type cacheKey struct {
61+
gvk schema.GroupVersionKind
62+
forceDisableProtoBuf bool
5663
}
5764

5865
// newResource maps obj to a Kubernetes Resource and constructs a client for that Resource.
@@ -117,14 +124,19 @@ func (c *clientRestResources) getResource(obj any) (*resourceMeta, error) {
117124
// It's better to do creation work twice than to not let multiple
118125
// people make requests at once
119126
c.mu.RLock()
127+
128+
cacheKey := cacheKey{gvk: gvk, forceDisableProtoBuf: forceDisableProtoBuf}
129+
120130
resourceByType := c.structuredResourceByType
121131
if isUnstructured {
122132
resourceByType = c.unstructuredResourceByType
123133
}
124-
r, known := resourceByType[gvk]
134+
135+
r, known := resourceByType[cacheKey]
136+
125137
c.mu.RUnlock()
126138

127-
if known && !forceDisableProtoBuf {
139+
if known {
128140
return r, nil
129141
}
130142

@@ -140,7 +152,7 @@ func (c *clientRestResources) getResource(obj any) (*resourceMeta, error) {
140152
if err != nil {
141153
return nil, err
142154
}
143-
resourceByType[gvk] = r
155+
resourceByType[cacheKey] = r
144156
return r, err
145157
}
146158

0 commit comments

Comments
 (0)