mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #14722 from mqliang/pod-sort
Auto commit by PR queue bot
This commit is contained in:
		@@ -366,7 +366,8 @@ func (dsc *DaemonSetsController) manage(ds *experimental.DaemonSet) {
 | 
			
		||||
			nodesNeedingDaemonPods = append(nodesNeedingDaemonPods, nodeName)
 | 
			
		||||
		} else if shouldRun && len(daemonPods) > 1 {
 | 
			
		||||
			// If daemon pod is supposed to be running on node, but more than 1 daemon pod is running, delete the excess daemon pods.
 | 
			
		||||
			// TODO: sort the daemon pods by creation time, so the the oldest is preserved.
 | 
			
		||||
			// Sort the daemon pods by creation time, so the the oldest is preserved.
 | 
			
		||||
			sort.Sort(podByCreationTimestamp(daemonPods))
 | 
			
		||||
			for i := 1; i < len(daemonPods); i++ {
 | 
			
		||||
				podsToDelete = append(podsToDelete, daemonPods[i].Name)
 | 
			
		||||
			}
 | 
			
		||||
@@ -524,3 +525,15 @@ func (o byCreationTimestamp) Less(i, j int) bool {
 | 
			
		||||
	}
 | 
			
		||||
	return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type podByCreationTimestamp []*api.Pod
 | 
			
		||||
 | 
			
		||||
func (o podByCreationTimestamp) Len() int      { return len(o) }
 | 
			
		||||
func (o podByCreationTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
 | 
			
		||||
 | 
			
		||||
func (o podByCreationTimestamp) Less(i, j int) bool {
 | 
			
		||||
	if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
 | 
			
		||||
		return o[i].Name < o[j].Name
 | 
			
		||||
	}
 | 
			
		||||
	return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user