mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	Make discovery summarizer call servers in parallel
This commit is contained in:
		@@ -102,20 +102,39 @@ func (ds *discoverySummarizerServer) indexHandler(w http.ResponseWriter, r *http
 | 
				
			|||||||
func (ds *discoverySummarizerServer) summarizeGroupVersionsHandler(path string) func(http.ResponseWriter, *http.Request) {
 | 
					func (ds *discoverySummarizerServer) summarizeGroupVersionsHandler(path string) func(http.ResponseWriter, *http.Request) {
 | 
				
			||||||
	return func(w http.ResponseWriter, r *http.Request) {
 | 
						return func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
		var apiGroupList *unversioned.APIGroupList
 | 
							var apiGroupList *unversioned.APIGroupList
 | 
				
			||||||
		// TODO: We can cache and parallelize the calls to all servers.
 | 
							// TODO: We can cache calls to all servers.
 | 
				
			||||||
 | 
							groups := make(chan *unversioned.APIGroupList)
 | 
				
			||||||
 | 
							errorChannel := make(chan error)
 | 
				
			||||||
		for _, serverAddress := range ds.groupVersionPaths[path] {
 | 
							for _, serverAddress := range ds.groupVersionPaths[path] {
 | 
				
			||||||
			groupList, err := ds.getAPIGroupList(serverAddress + path)
 | 
								addr := serverAddress
 | 
				
			||||||
 | 
								go func(groups chan *unversioned.APIGroupList, error_channel chan error) {
 | 
				
			||||||
 | 
									groupList, err := ds.getAPIGroupList(addr + path)
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
				ds.writeErr(http.StatusBadGateway, err, w)
 | 
										errorChannel <- err
 | 
				
			||||||
					return
 | 
										return
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									groups <- groupList
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}(groups, errorChannel)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var groupList *unversioned.APIGroupList
 | 
				
			||||||
 | 
							var err error
 | 
				
			||||||
 | 
							for range ds.groupVersionPaths[path] {
 | 
				
			||||||
 | 
								select {
 | 
				
			||||||
 | 
								case groupList = <-groups:
 | 
				
			||||||
				if apiGroupList == nil {
 | 
									if apiGroupList == nil {
 | 
				
			||||||
					apiGroupList = &unversioned.APIGroupList{}
 | 
										apiGroupList = &unversioned.APIGroupList{}
 | 
				
			||||||
					*apiGroupList = *groupList
 | 
										*apiGroupList = *groupList
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					apiGroupList.Groups = append(apiGroupList.Groups, groupList.Groups...)
 | 
										apiGroupList.Groups = append(apiGroupList.Groups, groupList.Groups...)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
								case err = <-errorChannel:
 | 
				
			||||||
 | 
									ds.writeErr(http.StatusBadGateway, err, w)
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ds.writeRawJSON(http.StatusOK, *apiGroupList, w)
 | 
							ds.writeRawJSON(http.StatusOK, *apiGroupList, w)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user