Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2cdddd8

Browse files
committed
discovery: speedup cache miss by a two digit factor
1 parent 618050e commit 2cdddd8

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

staging/src/k8s.io/client-go/restmapper/discovery.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,27 +145,26 @@ func NewDiscoveryRESTMapper(groupResources []*APIGroupResources) meta.RESTMapper
145145
// GetAPIGroupResources uses the provided discovery client to gather
146146
// discovery information and populate a slice of APIGroupResources.
147147
func GetAPIGroupResources(cl discovery.DiscoveryInterface) ([]*APIGroupResources, error) {
148-
apiGroups, err := cl.ServerGroups()
149-
if err != nil {
150-
if apiGroups == nil || len(apiGroups.Groups) == 0 {
151-
return nil, err
152-
}
148+
gs, rs, err := cl.ServerGroupsAndResources()
149+
if rs == nil || gs == nil {
150+
return nil, err
153151
// TODO track the errors and update callers to handle partial errors.
154152
}
153+
rsm := map[string]*metav1.APIResourceList{}
154+
for _, r := range rs {
155+
rsm[r.GroupVersion] = r
156+
}
157+
155158
var result []*APIGroupResources
156-
for _, group := range apiGroups.Groups {
159+
for _, group := range gs {
157160
groupResources := &APIGroupResources{
158-
Group: group,
161+
Group: *group,
159162
VersionedResources: make(map[string][]metav1.APIResource),
160163
}
161164
for _, version := range group.Versions {
162-
resources, err := cl.ServerResourcesForGroupVersion(version.GroupVersion)
163-
if err != nil {
164-
// continue as best we can
165-
// TODO track the errors and update callers to handle partial errors.
166-
if resources == nil || len(resources.APIResources) == 0 {
167-
continue
168-
}
165+
resources, ok := rsm[version.GroupVersion]
166+
if !ok {
167+
continue
169168
}
170169
groupResources.VersionedResources[version.Version] = resources.APIResources
171170
}

0 commit comments

Comments
 (0)