Skip to content

Commit

Permalink
fix aggregated discovery version sorting
Browse files Browse the repository at this point in the history
add test for level based priorities

Kubernetes-commit: 3c68fe6596922dc535b5af03f409611e57258f9d
  • Loading branch information
Alexander Zielenski authored and k8s-publishing-bot committed Nov 9, 2022
1 parent 8380ea7 commit b53a7e9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/apiserver/handler_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/helper"
)

var APIRegistrationGroup string = "apiregistration.k8s.io"
var APIRegistrationGroupVersion metav1.GroupVersion = metav1.GroupVersion{Group: "apiregistration.k8s.io", Version: "v1"}
var APIRegistrationGroupPriority int = 18000

// Given a list of APIServices and proxyHandlers for contacting them,
Expand Down Expand Up @@ -151,9 +151,12 @@ type groupVersionInfo struct {
// describes how to contact the server responsible for this GroupVersion.
service serviceKey

// groupPriority describes the priority of the APIService for sorting
// groupPriority describes the priority of the APIService's group for sorting
groupPriority int

// groupPriority describes the priority of the APIService version for sorting
versionPriority int

// Method for contacting the service
handler http.Handler
}
Expand Down Expand Up @@ -390,6 +393,7 @@ func (dm *discoveryManager) syncAPIService(apiServiceName string) error {
}

dm.mergedDiscoveryHandler.AddGroupVersion(gv.Group, entry)
dm.mergedDiscoveryHandler.SetGroupVersionPriority(metav1.GroupVersion(gv), info.groupPriority, info.versionPriority)
return nil
}

Expand Down Expand Up @@ -428,7 +432,7 @@ func (dm *discoveryManager) Run(stopCh <-chan struct{}) {
}

// Ensure that apiregistration.k8s.io is the first group in the discovery group.
dm.mergedDiscoveryHandler.SetGroupPriority(APIRegistrationGroup, APIRegistrationGroupPriority)
dm.mergedDiscoveryHandler.SetGroupVersionPriority(APIRegistrationGroupVersion, APIRegistrationGroupPriority, 0)

wait.PollUntil(1*time.Minute, func() (done bool, err error) {
dm.servicesLock.Lock()
Expand Down Expand Up @@ -458,6 +462,7 @@ func (dm *discoveryManager) AddAPIService(apiService *apiregistrationv1.APIServi
// Add or update APIService record and mark it as dirty
dm.setInfoForAPIService(apiService.Name, &groupVersionInfo{
groupPriority: int(apiService.Spec.GroupPriorityMinimum),
versionPriority: int(apiService.Spec.VersionPriority),
handler: handler,
lastMarkedDirty: time.Now(),
service: newServiceKey(*apiService.Spec.Service),
Expand Down

0 comments on commit b53a7e9

Please sign in to comment.