@@ -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