mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Merge pull request #28570 from kevinjkj/kevinjkj-patch-3
Automatic merge from submit-queue Optimizing the processing flow of HandlePodAdditions and canAdmitPod … Optimizing the processing flow of HandlePodAdditions and canAdmitPod methods. If the following loop body in canAdmitPod method is removed, the detection speed can be improved, and the change is very small. ------ otherPods := []*api.Pod{} for _, p := range pods { if p != pod { otherPods = append(otherPods, p) } } ------
This commit is contained in:
commit
d6e84cc2e9
@ -2202,8 +2202,8 @@ func (kl *Kubelet) rejectPod(pod *api.Pod, reason, message string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// canAdmitPod determines if a pod can be admitted, and gives a reason if it
|
// canAdmitPod determines if a pod can be admitted, and gives a reason if it
|
||||||
// cannot. "pod" is new pod, while "pods" include all admitted pods plus the
|
// cannot. "pod" is new pod, while "pods" are all admitted pods
|
||||||
// new pod. The function returns a boolean value indicating whether the pod
|
// The function returns a boolean value indicating whether the pod
|
||||||
// can be admitted, a brief single-word reason and a message explaining why
|
// can be admitted, a brief single-word reason and a message explaining why
|
||||||
// the pod cannot be admitted.
|
// the pod cannot be admitted.
|
||||||
func (kl *Kubelet) canAdmitPod(pods []*api.Pod, pod *api.Pod) (bool, string, string) {
|
func (kl *Kubelet) canAdmitPod(pods []*api.Pod, pod *api.Pod) (bool, string, string) {
|
||||||
@ -2212,25 +2212,19 @@ func (kl *Kubelet) canAdmitPod(pods []*api.Pod, pod *api.Pod) (bool, string, str
|
|||||||
glog.Errorf("Cannot get Node info: %v", err)
|
glog.Errorf("Cannot get Node info: %v", err)
|
||||||
return false, "InvalidNodeInfo", "Kubelet cannot get node info."
|
return false, "InvalidNodeInfo", "Kubelet cannot get node info."
|
||||||
}
|
}
|
||||||
otherPods := []*api.Pod{}
|
|
||||||
for _, p := range pods {
|
|
||||||
if p != pod {
|
|
||||||
otherPods = append(otherPods, p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// the kubelet will invoke each pod admit handler in sequence
|
// the kubelet will invoke each pod admit handler in sequence
|
||||||
// if any handler rejects, the pod is rejected.
|
// if any handler rejects, the pod is rejected.
|
||||||
// TODO: move predicate check into a pod admitter
|
// TODO: move predicate check into a pod admitter
|
||||||
// TODO: move out of disk check into a pod admitter
|
// TODO: move out of disk check into a pod admitter
|
||||||
// TODO: out of resource eviction should have a pod admitter call-out
|
// TODO: out of resource eviction should have a pod admitter call-out
|
||||||
attrs := &lifecycle.PodAdmitAttributes{Pod: pod, OtherPods: otherPods}
|
attrs := &lifecycle.PodAdmitAttributes{Pod: pod, OtherPods: pods}
|
||||||
for _, podAdmitHandler := range kl.PodAdmitHandlers {
|
for _, podAdmitHandler := range kl.PodAdmitHandlers {
|
||||||
if result := podAdmitHandler.Admit(attrs); !result.Admit {
|
if result := podAdmitHandler.Admit(attrs); !result.Admit {
|
||||||
return false, result.Reason, result.Message
|
return false, result.Reason, result.Message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nodeInfo := schedulercache.NewNodeInfo(otherPods...)
|
nodeInfo := schedulercache.NewNodeInfo(pods...)
|
||||||
nodeInfo.SetNode(node)
|
nodeInfo.SetNode(node)
|
||||||
fit, err := predicates.GeneralPredicates(pod, nil, nodeInfo)
|
fit, err := predicates.GeneralPredicates(pod, nil, nodeInfo)
|
||||||
if !fit {
|
if !fit {
|
||||||
@ -2447,22 +2441,22 @@ func (kl *Kubelet) HandlePodAdditions(pods []*api.Pod) {
|
|||||||
start := kl.clock.Now()
|
start := kl.clock.Now()
|
||||||
sort.Sort(podsByCreationTime(pods))
|
sort.Sort(podsByCreationTime(pods))
|
||||||
for _, pod := range pods {
|
for _, pod := range pods {
|
||||||
kl.podManager.AddPod(pod)
|
|
||||||
if kubepod.IsMirrorPod(pod) {
|
if kubepod.IsMirrorPod(pod) {
|
||||||
|
kl.podManager.AddPod(pod)
|
||||||
kl.handleMirrorPod(pod, start)
|
kl.handleMirrorPod(pod, start)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Note that allPods includes the new pod since we added at the
|
// Note that allPods excludes the new pod.
|
||||||
// beginning of the loop.
|
|
||||||
allPods := kl.podManager.GetPods()
|
allPods := kl.podManager.GetPods()
|
||||||
// We failed pods that we rejected, so activePods include all admitted
|
// We failed pods that we rejected, so activePods include all admitted
|
||||||
// pods that are alive and the new pod.
|
// pods that are alive.
|
||||||
activePods := kl.filterOutTerminatedPods(allPods)
|
activePods := kl.filterOutTerminatedPods(allPods)
|
||||||
// Check if we can admit the pod; if not, reject it.
|
// Check if we can admit the pod; if not, reject it.
|
||||||
if ok, reason, message := kl.canAdmitPod(activePods, pod); !ok {
|
if ok, reason, message := kl.canAdmitPod(activePods, pod); !ok {
|
||||||
kl.rejectPod(pod, reason, message)
|
kl.rejectPod(pod, reason, message)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
kl.podManager.AddPod(pod)
|
||||||
mirrorPod, _ := kl.podManager.GetMirrorPodByPod(pod)
|
mirrorPod, _ := kl.podManager.GetMirrorPodByPod(pod)
|
||||||
kl.dispatchWork(pod, kubetypes.SyncPodCreate, mirrorPod, start)
|
kl.dispatchWork(pod, kubetypes.SyncPodCreate, mirrorPod, start)
|
||||||
kl.probeManager.AddPod(pod)
|
kl.probeManager.AddPod(pod)
|
||||||
|
@ -71,7 +71,7 @@ func (kl *Kubelet) runOnce(pods []*api.Pod, retryDelay time.Duration) (results [
|
|||||||
admitted := []*api.Pod{}
|
admitted := []*api.Pod{}
|
||||||
for _, pod := range pods {
|
for _, pod := range pods {
|
||||||
// Check if we can admit the pod.
|
// Check if we can admit the pod.
|
||||||
if ok, reason, message := kl.canAdmitPod(append(admitted, pod), pod); !ok {
|
if ok, reason, message := kl.canAdmitPod(admitted, pod); !ok {
|
||||||
kl.rejectPod(pod, reason, message)
|
kl.rejectPod(pod, reason, message)
|
||||||
} else {
|
} else {
|
||||||
admitted = append(admitted, pod)
|
admitted = append(admitted, pod)
|
||||||
|
Loading…
Reference in New Issue
Block a user