Skip to content

Commit 62b0bbc

Browse files
authored
Merge pull request kubernetes#88382 from jpbetz/parallel-mem-client-resource-discovery
Refresh discovery server resources for memCacheClient in parallel
2 parents 9a8e869 + 190a723 commit 62b0bbc

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

staging/src/k8s.io/client-go/discovery/cached/memory/memcache.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,29 @@ func (d *memCacheClient) refreshLocked() error {
190190
return err
191191
}
192192

193+
wg := &sync.WaitGroup{}
194+
resultLock := &sync.Mutex{}
193195
rl := map[string]*cacheEntry{}
194196
for _, g := range gl.Groups {
195197
for _, v := range g.Versions {
196-
r, err := d.serverResourcesForGroupVersion(v.GroupVersion)
197-
rl[v.GroupVersion] = &cacheEntry{r, err}
198-
if err != nil {
199-
utilruntime.HandleError(fmt.Errorf("couldn't get resource list for %v: %v", v.GroupVersion, err))
200-
}
198+
gv := v.GroupVersion
199+
wg.Add(1)
200+
go func() {
201+
defer wg.Done()
202+
defer utilruntime.HandleCrash()
203+
204+
r, err := d.serverResourcesForGroupVersion(gv)
205+
if err != nil {
206+
utilruntime.HandleError(fmt.Errorf("couldn't get resource list for %v: %v", gv, err))
207+
}
208+
209+
resultLock.Lock()
210+
defer resultLock.Unlock()
211+
rl[gv] = &cacheEntry{r, err}
212+
}()
201213
}
202214
}
215+
wg.Wait()
203216

204217
d.groupToServerResources, d.groupList = rl, gl
205218
d.cacheValid = true

staging/src/k8s.io/client-go/discovery/cached/memory/memcache_test.go

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,22 @@ func TestServerGroupsFails(t *testing.T) {
205205
func TestPartialPermanentFailure(t *testing.T) {
206206
fake := &fakeDiscovery{
207207
groupList: &metav1.APIGroupList{
208-
Groups: []metav1.APIGroup{{
209-
Name: "astronomy",
210-
Versions: []metav1.GroupVersionForDiscovery{{
211-
GroupVersion: "astronomy/v8beta1",
212-
Version: "v8beta1",
213-
}, {
214-
GroupVersion: "astronomy2/v8beta1",
215-
Version: "v8beta1",
216-
}},
217-
}},
208+
Groups: []metav1.APIGroup{
209+
{
210+
Name: "astronomy",
211+
Versions: []metav1.GroupVersionForDiscovery{{
212+
GroupVersion: "astronomy/v8beta1",
213+
Version: "v8beta1",
214+
}},
215+
},
216+
{
217+
Name: "astronomy2",
218+
Versions: []metav1.GroupVersionForDiscovery{{
219+
GroupVersion: "astronomy2/v8beta1",
220+
Version: "v8beta1",
221+
}},
222+
},
223+
},
218224
},
219225
resourceMap: map[string]*resourceMapEntry{
220226
"astronomy/v8beta1": {
@@ -286,16 +292,22 @@ func TestPartialPermanentFailure(t *testing.T) {
286292
func TestPartialRetryableFailure(t *testing.T) {
287293
fake := &fakeDiscovery{
288294
groupList: &metav1.APIGroupList{
289-
Groups: []metav1.APIGroup{{
290-
Name: "astronomy",
291-
Versions: []metav1.GroupVersionForDiscovery{{
292-
GroupVersion: "astronomy/v8beta1",
293-
Version: "v8beta1",
294-
}, {
295-
GroupVersion: "astronomy2/v8beta1",
296-
Version: "v8beta1",
297-
}},
298-
}},
295+
Groups: []metav1.APIGroup{
296+
{
297+
Name: "astronomy",
298+
Versions: []metav1.GroupVersionForDiscovery{{
299+
GroupVersion: "astronomy/v8beta1",
300+
Version: "v8beta1",
301+
}},
302+
},
303+
{
304+
Name: "astronomy2",
305+
Versions: []metav1.GroupVersionForDiscovery{{
306+
GroupVersion: "astronomy2/v8beta1",
307+
Version: "v8beta1",
308+
}},
309+
},
310+
},
299311
},
300312
resourceMap: map[string]*resourceMapEntry{
301313
"astronomy/v8beta1": {

0 commit comments

Comments
 (0)