mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Add synchronization around nodeMap
This commit is contained in:
parent
e967ffd522
commit
292d33e33c
@ -44,6 +44,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var ErrMetadataConflict = errors.New("Metadata already set at the same key")
|
var ErrMetadataConflict = errors.New("Metadata already set at the same key")
|
||||||
|
|
||||||
const podCIDRMetadataKey string = "node-ip-range"
|
const podCIDRMetadataKey string = "node-ip-range"
|
||||||
|
|
||||||
// GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine.
|
// GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine.
|
||||||
|
@ -304,9 +304,12 @@ func (nc *NodeController) syncCloudNodes() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nodeMap := make(map[string]*api.Node)
|
nodeMap := make(map[string]*api.Node)
|
||||||
|
nodeMapLock := sync.Mutex{}
|
||||||
for i := range nodes.Items {
|
for i := range nodes.Items {
|
||||||
node := nodes.Items[i]
|
node := nodes.Items[i]
|
||||||
|
nodeMapLock.Lock()
|
||||||
nodeMap[node.Name] = &node
|
nodeMap[node.Name] = &node
|
||||||
|
nodeMapLock.Unlock()
|
||||||
}
|
}
|
||||||
if nc.allocateNodeCIDRs {
|
if nc.allocateNodeCIDRs {
|
||||||
nc.reconcilePodCIDRs(matches, nodes)
|
nc.reconcilePodCIDRs(matches, nodes)
|
||||||
@ -318,7 +321,10 @@ func (nc *NodeController) syncCloudNodes() error {
|
|||||||
for i := range matches.Items {
|
for i := range matches.Items {
|
||||||
go func(node *api.Node) {
|
go func(node *api.Node) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if _, ok := nodeMap[node.Name]; !ok {
|
nodeMapLock.Lock()
|
||||||
|
_, ok := nodeMap[node.Name]
|
||||||
|
nodeMapLock.Unlock()
|
||||||
|
if !ok {
|
||||||
glog.V(3).Infof("Querying addresses for new node: %s", node.Name)
|
glog.V(3).Infof("Querying addresses for new node: %s", node.Name)
|
||||||
nodeList := &api.NodeList{}
|
nodeList := &api.NodeList{}
|
||||||
nodeList.Items = []api.Node{*node}
|
nodeList.Items = []api.Node{*node}
|
||||||
@ -337,7 +343,9 @@ func (nc *NodeController) syncCloudNodes() error {
|
|||||||
glog.Errorf("Create node %s error: %v", node.Name, err)
|
glog.Errorf("Create node %s error: %v", node.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
nodeMapLock.Lock()
|
||||||
delete(nodeMap, node.Name)
|
delete(nodeMap, node.Name)
|
||||||
|
nodeMapLock.Unlock()
|
||||||
}(&matches.Items[i])
|
}(&matches.Items[i])
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
Loading…
Reference in New Issue
Block a user