Merge pull request #98518 from tanjing2020/change-log

migrate default_preemption.go to structured logging
This commit is contained in:
Kubernetes Prow Robot 2021-02-03 19:54:28 -08:00 committed by GitHub
commit ebe7380b38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ package defaultpreemption
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"math" "math"
"math/rand" "math/rand"
@ -125,15 +126,16 @@ func (pl *DefaultPreemption) preempt(ctx context.Context, state *framework.Cycle
// It's safe to directly fetch pod here. Because the informer cache has already been // It's safe to directly fetch pod here. Because the informer cache has already been
// initialized when creating the Scheduler obj, i.e., factory.go#MakeDefaultErrorFunc(). // initialized when creating the Scheduler obj, i.e., factory.go#MakeDefaultErrorFunc().
// However, tests may need to manually initialize the shared pod informer. // However, tests may need to manually initialize the shared pod informer.
podNamespace, podName := pod.Namespace, pod.Name
pod, err := pl.podLister.Pods(pod.Namespace).Get(pod.Name) pod, err := pl.podLister.Pods(pod.Namespace).Get(pod.Name)
if err != nil { if err != nil {
klog.Errorf("Error getting the updated preemptor pod object: %v", err) klog.ErrorS(err, "getting the updated preemptor pod object", "pod", klog.KRef(podNamespace, podName))
return "", err return "", err
} }
// 1) Ensure the preemptor is eligible to preempt other pods. // 1) Ensure the preemptor is eligible to preempt other pods.
if !PodEligibleToPreemptOthers(pod, nodeLister, m[pod.Status.NominatedNodeName]) { if !PodEligibleToPreemptOthers(pod, nodeLister, m[pod.Status.NominatedNodeName]) {
klog.V(5).Infof("Pod %v/%v is not eligible for more preemption.", pod.Namespace, pod.Name) klog.V(5).InfoS("Pod is not eligible for more preemption", "pod", klog.KObj(pod))
return "", nil return "", nil
} }
@ -208,10 +210,10 @@ func (pl *DefaultPreemption) FindCandidates(ctx context.Context, state *framewor
} }
potentialNodes, unschedulableNodeStatus := nodesWherePreemptionMightHelp(allNodes, m) potentialNodes, unschedulableNodeStatus := nodesWherePreemptionMightHelp(allNodes, m)
if len(potentialNodes) == 0 { if len(potentialNodes) == 0 {
klog.V(3).Infof("Preemption will not help schedule pod %v/%v on any node.", pod.Namespace, pod.Name) klog.V(3).InfoS("Preemption will not help schedule pod on any node", "pod", klog.KObj(pod))
// In this case, we should clean-up any existing nominated node name of the pod. // In this case, we should clean-up any existing nominated node name of the pod.
if err := util.ClearNominatedNodeName(pl.fh.ClientSet(), pod); err != nil { if err := util.ClearNominatedNodeName(pl.fh.ClientSet(), pod); err != nil {
klog.Errorf("Cannot clear 'NominatedNodeName' field of pod %v/%v: %v", pod.Namespace, pod.Name, err) klog.ErrorS(err, "cannot clear 'NominatedNodeName' field of pod", "pod", klog.KObj(pod))
// We do not return as this error is not critical. // We do not return as this error is not critical.
} }
return nil, unschedulableNodeStatus, nil return nil, unschedulableNodeStatus, nil
@ -245,7 +247,7 @@ func (pl *DefaultPreemption) FindCandidates(ctx context.Context, state *framewor
// terminating pods on the node, we don't consider this for preempting more pods. // terminating pods on the node, we don't consider this for preempting more pods.
func PodEligibleToPreemptOthers(pod *v1.Pod, nodeInfos framework.NodeInfoLister, nominatedNodeStatus *framework.Status) bool { func PodEligibleToPreemptOthers(pod *v1.Pod, nodeInfos framework.NodeInfoLister, nominatedNodeStatus *framework.Status) bool {
if pod.Spec.PreemptionPolicy != nil && *pod.Spec.PreemptionPolicy == v1.PreemptNever { if pod.Spec.PreemptionPolicy != nil && *pod.Spec.PreemptionPolicy == v1.PreemptNever {
klog.V(5).Infof("Pod %v/%v is not eligible for preemption because it has a preemptionPolicy of %v", pod.Namespace, pod.Name, v1.PreemptNever) klog.V(5).InfoS("Pod is not eligible for preemption because it has a preemptionPolicy of Never", "pod", klog.KObj(pod))
return false return false
} }
nomNodeName := pod.Status.NominatedNodeName nomNodeName := pod.Status.NominatedNodeName
@ -388,8 +390,8 @@ func CallExtenders(extenders []framework.Extender, pod *v1.Pod, nodeLister frame
nodeNameToVictims, err := extender.ProcessPreemption(pod, victimsMap, nodeLister) nodeNameToVictims, err := extender.ProcessPreemption(pod, victimsMap, nodeLister)
if err != nil { if err != nil {
if extender.IsIgnorable() { if extender.IsIgnorable() {
klog.Warningf("Skipping extender %v as it returned error %v and has ignorable flag set", klog.InfoS("Skipping extender as it returned error and has ignorable flag set",
extender, err) "extender", extender, "err", err)
continue continue
} }
return nil, err return nil, err
@ -446,7 +448,7 @@ func SelectCandidate(candidates []Candidate) Candidate {
} }
// We shouldn't reach here. // We shouldn't reach here.
klog.Errorf("should not reach here, no candidate selected from %v.", candidates) klog.ErrorS(errors.New("no candidate selected"), "should not reach here", "candidates", candidates)
// To not break the whole flow, return the first candidate. // To not break the whole flow, return the first candidate.
return candidates[0] return candidates[0]
} }
@ -561,7 +563,7 @@ func pickOneNodeForPreemption(nodesToVictims map[string]*extenderv1.Victims) str
if latestStartTime == nil { if latestStartTime == nil {
// If the earliest start time of all pods on the 1st node is nil, just return it, // If the earliest start time of all pods on the 1st node is nil, just return it,
// which is not expected to happen. // which is not expected to happen.
klog.Errorf("earliestStartTime is nil for node %s. Should not reach here.", minNodes2[0]) klog.ErrorS(errors.New("earliestStartTime is nil for node"), "should not reach here", "node", minNodes2[0])
return minNodes2[0] return minNodes2[0]
} }
nodeToReturn := minNodes2[0] nodeToReturn := minNodes2[0]
@ -570,7 +572,7 @@ func pickOneNodeForPreemption(nodesToVictims map[string]*extenderv1.Victims) str
// Get earliest start time of all pods on the current node. // Get earliest start time of all pods on the current node.
earliestStartTimeOnNode := util.GetEarliestPodStartTime(nodesToVictims[node]) earliestStartTimeOnNode := util.GetEarliestPodStartTime(nodesToVictims[node])
if earliestStartTimeOnNode == nil { if earliestStartTimeOnNode == nil {
klog.Errorf("earliestStartTime is nil for node %s. Should not reach here.", node) klog.ErrorS(errors.New("earliestStartTime is nil for node"), "should not reach here", "node", node)
continue continue
} }
if earliestStartTimeOnNode.After(latestStartTime.Time) { if earliestStartTimeOnNode.After(latestStartTime.Time) {
@ -671,7 +673,7 @@ func selectVictimsOnNode(
} }
rpi := pi.Pod rpi := pi.Pod
victims = append(victims, rpi) victims = append(victims, rpi)
klog.V(5).Infof("Pod %v/%v is a potential preemption victim on node %v.", rpi.Namespace, rpi.Name, nodeInfo.Node().Name) klog.V(5).InfoS("Pod is a potential preemption victim on node", "pod", klog.KObj(rpi), "node", nodeInfo.Node().Name)
} }
return fits, nil return fits, nil
} }
@ -698,7 +700,7 @@ func selectVictimsOnNode(
func PrepareCandidate(c Candidate, fh framework.Handle, cs kubernetes.Interface, pod *v1.Pod, pluginName string) error { func PrepareCandidate(c Candidate, fh framework.Handle, cs kubernetes.Interface, pod *v1.Pod, pluginName string) error {
for _, victim := range c.Victims().Pods { for _, victim := range c.Victims().Pods {
if err := util.DeletePod(cs, victim); err != nil { if err := util.DeletePod(cs, victim); err != nil {
klog.Errorf("Error preempting pod %v/%v: %v", victim.Namespace, victim.Name, err) klog.ErrorS(err, "preempting pod", "pod", klog.KObj(victim))
return err return err
} }
// If the victim is a WaitingPod, send a reject message to the PermitPlugin // If the victim is a WaitingPod, send a reject message to the PermitPlugin
@ -716,7 +718,7 @@ func PrepareCandidate(c Candidate, fh framework.Handle, cs kubernetes.Interface,
// lets scheduler find another place for them. // lets scheduler find another place for them.
nominatedPods := getLowerPriorityNominatedPods(fh.PreemptHandle(), pod, c.Name()) nominatedPods := getLowerPriorityNominatedPods(fh.PreemptHandle(), pod, c.Name())
if err := util.ClearNominatedNodeName(cs, nominatedPods...); err != nil { if err := util.ClearNominatedNodeName(cs, nominatedPods...); err != nil {
klog.Errorf("Cannot clear 'NominatedNodeName' field: %v", err) klog.ErrorS(err, "cannot clear 'NominatedNodeName' field")
// We do not return as this error is not critical. // We do not return as this error is not critical.
} }