mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #5605 from yujuhong/kubelet_locks
Kubelet: simplify the lock acquring pattern
This commit is contained in:
		@@ -254,6 +254,14 @@ type Kubelet struct {
 | 
				
			|||||||
	// out beforehand.
 | 
						// out beforehand.
 | 
				
			||||||
	mirrorPods util.StringSet
 | 
						mirrorPods util.StringSet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// A pod status cache stores statuses for pods (both rejected and synced).
 | 
				
			||||||
 | 
						// Note that currently no thread attempts to acquire podStatusesLock while
 | 
				
			||||||
 | 
						// holding podLock, and vice versa. If you intend to change this usage
 | 
				
			||||||
 | 
						// pattern, please explicitly impose an acquiring order to avoid deadlocks
 | 
				
			||||||
 | 
						// and document such an order in the comment.
 | 
				
			||||||
 | 
						podStatusesLock sync.RWMutex
 | 
				
			||||||
 | 
						podStatuses     map[string]api.PodStatus
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Needed to report events for containers belonging to deleted/modified pods.
 | 
						// Needed to report events for containers belonging to deleted/modified pods.
 | 
				
			||||||
	// Tracks references for reporting events
 | 
						// Tracks references for reporting events
 | 
				
			||||||
	dockerIDToRef map[dockertools.DockerID]*api.ObjectReference
 | 
						dockerIDToRef map[dockertools.DockerID]*api.ObjectReference
 | 
				
			||||||
@@ -299,10 +307,6 @@ type Kubelet struct {
 | 
				
			|||||||
	// the EventRecorder to use
 | 
						// the EventRecorder to use
 | 
				
			||||||
	recorder record.EventRecorder
 | 
						recorder record.EventRecorder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// A pod status cache stores statuses for pods (both rejected and synced).
 | 
					 | 
				
			||||||
	podStatusesLock sync.RWMutex
 | 
					 | 
				
			||||||
	podStatuses     map[string]api.PodStatus
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// A mirror pod manager which provides helper functions.
 | 
						// A mirror pod manager which provides helper functions.
 | 
				
			||||||
	mirrorManager mirrorManager
 | 
						mirrorManager mirrorManager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1462,7 +1466,8 @@ func (kl *Kubelet) SyncPods(allPods []api.Pod, podSyncTypes map[types.UID]metric
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	kl.removeOrphanedStatuses(podFullNames)
 | 
						kl.removeOrphanedStatuses(podFullNames)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Filtered out the rejected pod. They don't have running containers.
 | 
						// Filter out the rejected pod. They don't have running containers.
 | 
				
			||||||
 | 
						kl.handleHostPortConflicts(allPods)
 | 
				
			||||||
	var pods []api.Pod
 | 
						var pods []api.Pod
 | 
				
			||||||
	for _, pod := range allPods {
 | 
						for _, pod := range allPods {
 | 
				
			||||||
		status, ok := kl.getPodStatusFromCache(GetPodFullName(&pod))
 | 
							status, ok := kl.getPodStatusFromCache(GetPodFullName(&pod))
 | 
				
			||||||
@@ -1712,8 +1717,6 @@ func (kl *Kubelet) updatePods(u PodUpdate, podSyncTypes map[types.UID]metrics.Sy
 | 
				
			|||||||
		// Actually update the pods.
 | 
							// Actually update the pods.
 | 
				
			||||||
		kl.pods = newPods
 | 
							kl.pods = newPods
 | 
				
			||||||
		kl.mirrorPods = newMirrorPods
 | 
							kl.mirrorPods = newMirrorPods
 | 
				
			||||||
 | 
					 | 
				
			||||||
		kl.handleHostPortConflicts(kl.pods)
 | 
					 | 
				
			||||||
	case UPDATE:
 | 
						case UPDATE:
 | 
				
			||||||
		glog.V(3).Infof("Update: Containers changed")
 | 
							glog.V(3).Infof("Update: Containers changed")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1724,7 +1727,6 @@ func (kl *Kubelet) updatePods(u PodUpdate, podSyncTypes map[types.UID]metrics.Sy
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		allPods := updatePods(u.Pods, kl.pods)
 | 
							allPods := updatePods(u.Pods, kl.pods)
 | 
				
			||||||
		kl.pods, kl.mirrorPods = filterAndCategorizePods(allPods)
 | 
							kl.pods, kl.mirrorPods = filterAndCategorizePods(allPods)
 | 
				
			||||||
		kl.handleHostPortConflicts(kl.pods)
 | 
					 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		panic("syncLoop does not support incremental changes")
 | 
							panic("syncLoop does not support incremental changes")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user