mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #82356 from m3ngyang/opt-podgc
optimize gc_controller.gcTerminated
This commit is contained in:
		@@ -21,7 +21,7 @@ import (
 | 
				
			|||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/api/core/v1"
 | 
						v1 "k8s.io/api/core/v1"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/labels"
 | 
						"k8s.io/apimachinery/pkg/labels"
 | 
				
			||||||
	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 | 
						utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 | 
				
			||||||
@@ -113,8 +113,6 @@ func (gcc *PodGCController) gcTerminated(pods []*v1.Pod) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	terminatedPodCount := len(terminatedPods)
 | 
						terminatedPodCount := len(terminatedPods)
 | 
				
			||||||
	sort.Sort(byCreationTimestamp(terminatedPods))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	deleteCount := terminatedPodCount - gcc.terminatedPodThreshold
 | 
						deleteCount := terminatedPodCount - gcc.terminatedPodThreshold
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if deleteCount > terminatedPodCount {
 | 
						if deleteCount > terminatedPodCount {
 | 
				
			||||||
@@ -122,8 +120,12 @@ func (gcc *PodGCController) gcTerminated(pods []*v1.Pod) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	if deleteCount > 0 {
 | 
						if deleteCount > 0 {
 | 
				
			||||||
		klog.Infof("garbage collecting %v pods", deleteCount)
 | 
							klog.Infof("garbage collecting %v pods", deleteCount)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// sort only when necessary
 | 
				
			||||||
 | 
						sort.Sort(byCreationTimestamp(terminatedPods))
 | 
				
			||||||
	var wait sync.WaitGroup
 | 
						var wait sync.WaitGroup
 | 
				
			||||||
	for i := 0; i < deleteCount; i++ {
 | 
						for i := 0; i < deleteCount; i++ {
 | 
				
			||||||
		wait.Add(1)
 | 
							wait.Add(1)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user