mirror of https://github.com/k3s-io/k3s
Merge pull request #33267 from sttts/sttts-lock-apiGroupsForDiscovery
Automatic merge from submit-queue Add locking around apiGroupsForDiscovery <!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, read our contributor guidelines https://github.com/kubernetes/kubernetes/blob/master/CONTRIBUTING.md and developer guide https://github.com/kubernetes/kubernetes/blob/master/docs/devel/development.md 2. If you want *faster* PR reviews, read how: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/faster_reviews.md 3. Follow the instructions for writing a release note: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/pull-requests.md#release-notes --> **What this PR does / why we need it**: **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: <!-- Steps to write your release note: 1. Use the release-note-* labels to set the release note state (if you have access) 2. Enter your extended release note in the below block; leaving it blank means using the PR title as the release note. If no release note is required, just write `NONE`. --> ```release-note ```pull/6/head
commit
0e01bc8f3f
|
@ -152,7 +152,8 @@ type GenericAPIServer struct {
|
||||||
|
|
||||||
// Map storing information about all groups to be exposed in discovery response.
|
// Map storing information about all groups to be exposed in discovery response.
|
||||||
// The map is from name to the group.
|
// The map is from name to the group.
|
||||||
apiGroupsForDiscovery map[string]unversioned.APIGroup
|
apiGroupsForDiscoveryLock sync.RWMutex
|
||||||
|
apiGroupsForDiscovery map[string]unversioned.APIGroup
|
||||||
|
|
||||||
// See Config.$name for documentation of these flags
|
// See Config.$name for documentation of these flags
|
||||||
|
|
||||||
|
@ -228,6 +229,9 @@ func (s *GenericAPIServer) InstallAPIGroups(groupsInfo []APIGroupInfo) error {
|
||||||
// Installs handler at /apis to list all group versions for discovery
|
// Installs handler at /apis to list all group versions for discovery
|
||||||
func (s *GenericAPIServer) installGroupsDiscoveryHandler() {
|
func (s *GenericAPIServer) installGroupsDiscoveryHandler() {
|
||||||
apiserver.AddApisWebService(s.Serializer, s.HandlerContainer, s.apiPrefix, func(req *restful.Request) []unversioned.APIGroup {
|
apiserver.AddApisWebService(s.Serializer, s.HandlerContainer, s.apiPrefix, func(req *restful.Request) []unversioned.APIGroup {
|
||||||
|
s.apiGroupsForDiscoveryLock.RLock()
|
||||||
|
defer s.apiGroupsForDiscoveryLock.RUnlock()
|
||||||
|
|
||||||
// Return the list of supported groups in sorted order (to have a deterministic order).
|
// Return the list of supported groups in sorted order (to have a deterministic order).
|
||||||
groups := []unversioned.APIGroup{}
|
groups := []unversioned.APIGroup{}
|
||||||
groupNames := make([]string, len(s.apiGroupsForDiscovery))
|
groupNames := make([]string, len(s.apiGroupsForDiscovery))
|
||||||
|
@ -454,10 +458,16 @@ func (s *GenericAPIServer) InstallAPIGroup(apiGroupInfo *APIGroupInfo) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GenericAPIServer) AddAPIGroupForDiscovery(apiGroup unversioned.APIGroup) {
|
func (s *GenericAPIServer) AddAPIGroupForDiscovery(apiGroup unversioned.APIGroup) {
|
||||||
|
s.apiGroupsForDiscoveryLock.Lock()
|
||||||
|
defer s.apiGroupsForDiscoveryLock.Unlock()
|
||||||
|
|
||||||
s.apiGroupsForDiscovery[apiGroup.Name] = apiGroup
|
s.apiGroupsForDiscovery[apiGroup.Name] = apiGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GenericAPIServer) RemoveAPIGroupForDiscovery(groupName string) {
|
func (s *GenericAPIServer) RemoveAPIGroupForDiscovery(groupName string) {
|
||||||
|
s.apiGroupsForDiscoveryLock.Lock()
|
||||||
|
defer s.apiGroupsForDiscoveryLock.Unlock()
|
||||||
|
|
||||||
delete(s.apiGroupsForDiscovery, groupName)
|
delete(s.apiGroupsForDiscovery, groupName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue