Merge pull request #82356 from m3ngyang/opt-podgc

optimize gc_controller.gcTerminated
This commit is contained in:
Kubernetes Prow Robot 2019-09-16 09:58:38 -07:00 committed by GitHub
commit 2183a84feb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,7 @@ import (
"sync"
"time"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@ -113,8 +113,6 @@ func (gcc *PodGCController) gcTerminated(pods []*v1.Pod) {
}
terminatedPodCount := len(terminatedPods)
sort.Sort(byCreationTimestamp(terminatedPods))
deleteCount := terminatedPodCount - gcc.terminatedPodThreshold
if deleteCount > terminatedPodCount {
@ -122,8 +120,12 @@ func (gcc *PodGCController) gcTerminated(pods []*v1.Pod) {
}
if deleteCount > 0 {
klog.Infof("garbage collecting %v pods", deleteCount)
} else {
return
}
// sort only when necessary
sort.Sort(byCreationTimestamp(terminatedPods))
var wait sync.WaitGroup
for i := 0; i < deleteCount; i++ {
wait.Add(1)