Skip to content

Commit

Permalink
[Provider/Azure] optimize mutex locks
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav1086 committed Apr 29, 2020
1 parent 36eee3c commit 862c30a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions staging/src/k8s.io/legacy-cloud-providers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ type Cloud struct {
// ipv6DualStack allows overriding for unit testing. It's normally initialized from featuregates
ipv6DualStackEnabled bool
// Lock for access to node caches, includes nodeZones, nodeResourceGroups, and unmanagedNodes.
nodeCachesLock sync.Mutex
nodeCachesLock sync.RWMutex
// nodeZones is a mapping from Zone to a sets.String of Node's names in the Zone
// it is updated by the nodeInformer
nodeZones map[string]sets.String
Expand Down Expand Up @@ -801,8 +801,8 @@ func (az *Cloud) GetActiveZones() (sets.String, error) {
return nil, fmt.Errorf("Azure cloud provider doesn't have informers set")
}

az.nodeCachesLock.Lock()
defer az.nodeCachesLock.Unlock()
az.nodeCachesLock.RLock()
defer az.nodeCachesLock.RUnlock()
if !az.nodeInformerSynced() {
return nil, fmt.Errorf("node informer is not synced when trying to GetActiveZones")
}
Expand All @@ -828,8 +828,8 @@ func (az *Cloud) GetNodeResourceGroup(nodeName string) (string, error) {
return az.ResourceGroup, nil
}

az.nodeCachesLock.Lock()
defer az.nodeCachesLock.Unlock()
az.nodeCachesLock.RLock()
defer az.nodeCachesLock.RUnlock()
if !az.nodeInformerSynced() {
return "", fmt.Errorf("node informer is not synced when trying to GetNodeResourceGroup")
}
Expand All @@ -850,8 +850,8 @@ func (az *Cloud) GetResourceGroups() (sets.String, error) {
return sets.NewString(az.ResourceGroup), nil
}

az.nodeCachesLock.Lock()
defer az.nodeCachesLock.Unlock()
az.nodeCachesLock.RLock()
defer az.nodeCachesLock.RUnlock()
if !az.nodeInformerSynced() {
return nil, fmt.Errorf("node informer is not synced when trying to GetResourceGroups")
}
Expand All @@ -871,8 +871,8 @@ func (az *Cloud) GetUnmanagedNodes() (sets.String, error) {
return nil, nil
}

az.nodeCachesLock.Lock()
defer az.nodeCachesLock.Unlock()
az.nodeCachesLock.RLock()
defer az.nodeCachesLock.RUnlock()
if !az.nodeInformerSynced() {
return nil, fmt.Errorf("node informer is not synced when trying to GetUnmanagedNodes")
}
Expand Down

0 comments on commit 862c30a

Please sign in to comment.