From f4aad52885766b489b0262c2c877ee5161126b94 Mon Sep 17 00:00:00 2001 From: Shivanshu Raj Shrivastava Date: Thu, 28 Oct 2021 14:40:17 +0530 Subject: [PATCH] migrated preemption.go, stateful.go, resource_allocation.go to structured logging --- pkg/kubelet/preemption/preemption.go | 2 +- .../plugins/examples/stateful/stateful.go | 2 +- .../plugins/noderesources/resource_allocation.go | 9 ++++----- pkg/scheduler/framework/preemption/preemption.go | 16 ++++++++-------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/pkg/kubelet/preemption/preemption.go b/pkg/kubelet/preemption/preemption.go index ca1b1770f9d..5f0fb5e03c0 100644 --- a/pkg/kubelet/preemption/preemption.go +++ b/pkg/kubelet/preemption/preemption.go @@ -98,7 +98,7 @@ func (c *CriticalPodAdmissionHandler) evictPodsToFreeRequests(admitPod *v1.Pod, // record that we are evicting the pod c.recorder.Eventf(pod, v1.EventTypeWarning, events.PreemptContainer, message) // this is a blocking call and should only return when the pod and its containers are killed. - klog.V(3).InfoS("Preempting pod to free up resources", "pod", klog.KObj(pod), "podUID", pod.UID, "insufficientResources", insufficientResources.toString()) + klog.V(3).InfoS("Preempting pod to free up resources", "pod", klog.KObj(pod), "podUID", pod.UID, "insufficientResources", insufficientResources) err := c.killPodFunc(pod, true, nil, func(status *v1.PodStatus) { status.Phase = v1.PodFailed status.Reason = events.PreemptContainer diff --git a/pkg/scheduler/framework/plugins/examples/stateful/stateful.go b/pkg/scheduler/framework/plugins/examples/stateful/stateful.go index 6458d8228c6..2eb22468da8 100644 --- a/pkg/scheduler/framework/plugins/examples/stateful/stateful.go +++ b/pkg/scheduler/framework/plugins/examples/stateful/stateful.go @@ -84,7 +84,7 @@ func (mp *MultipointExample) PreBind(ctx context.Context, state *framework.Cycle // New initializes a new plugin and returns it. func New(config *runtime.Unknown, _ framework.Handle) (framework.Plugin, error) { if config == nil { - klog.Error("MultipointExample configuration cannot be empty") + klog.ErrorS(nil, "MultipointExample configuration cannot be empty") return nil, fmt.Errorf("MultipointExample configuration cannot be empty") } mp := MultipointExample{} diff --git a/pkg/scheduler/framework/plugins/noderesources/resource_allocation.go b/pkg/scheduler/framework/plugins/noderesources/resource_allocation.go index e174c99a6ba..032e23a49fa 100644 --- a/pkg/scheduler/framework/plugins/noderesources/resource_allocation.go +++ b/pkg/scheduler/framework/plugins/noderesources/resource_allocation.go @@ -66,10 +66,9 @@ func (r *resourceAllocationScorer) score( score := r.scorer(requested, allocatable) if klog.V(10).Enabled() { - klog.Infof( - "%v -> %v: %v, map of allocatable resources %v, map of requested resources %v ,score %d,", - pod.Name, node.Name, r.Name, - allocatable, requested, score, + klog.InfoS("Listing internal info for allocatable resources, requested resources and score", "pod", + klog.KObj(pod), "node", klog.KObj(node), "resourceAllocationScorer", r.Name, + "allocatableResource", allocatable, "requestedResource", requested, "resourceScore", score, ) } @@ -100,7 +99,7 @@ func calculateResourceAllocatableRequest(nodeInfo *framework.NodeInfo, pod *v1.P } } if klog.V(10).Enabled() { - klog.Infof("requested resource %v not considered for node score calculation", resource) + klog.InfoS("Requested resource is omitted for node score calculation", "resourceName", resource) } return 0, 0 } diff --git a/pkg/scheduler/framework/preemption/preemption.go b/pkg/scheduler/framework/preemption/preemption.go index ca62fc56146..2a516bf21b5 100644 --- a/pkg/scheduler/framework/preemption/preemption.go +++ b/pkg/scheduler/framework/preemption/preemption.go @@ -132,7 +132,7 @@ func (ev *Evaluator) Preempt(ctx context.Context, pod *v1.Pod, m framework.NodeT podNamespace, podName := pod.Namespace, pod.Name pod, err := ev.PodLister.Pods(pod.Namespace).Get(pod.Name) if err != nil { - klog.ErrorS(err, "getting the updated preemptor pod object", "pod", klog.KRef(podNamespace, podName)) + klog.ErrorS(err, "Getting the updated preemptor pod object", "pod", klog.KRef(podNamespace, podName)) return nil, framework.AsStatus(err) } @@ -196,7 +196,7 @@ func (ev *Evaluator) findCandidates(ctx context.Context, pod *v1.Pod, m framewor 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. if err := util.ClearNominatedNodeName(ev.Handler.ClientSet(), pod); err != nil { - klog.ErrorS(err, "cannot clear 'NominatedNodeName' field of pod", "pod", klog.KObj(pod)) + klog.ErrorS(err, "Cannot clear 'NominatedNodeName' field of pod", "pod", klog.KObj(pod)) // We do not return as this error is not critical. } return nil, unschedulableNodeStatus, nil @@ -213,7 +213,7 @@ func (ev *Evaluator) findCandidates(ctx context.Context, pod *v1.Pod, m framewor for i := offset; i < offset+10 && i < int32(len(potentialNodes)); i++ { sample = append(sample, potentialNodes[i].Node().Name) } - klog.Infof("from a pool of %d nodes (offset: %d, sample %d nodes: %v), ~%d candidates will be chosen", len(potentialNodes), offset, len(sample), sample, numCandidates) + klog.InfoS("Selecting candidates from a pool of nodes", "potentialNodesCount", len(potentialNodes), "offset", offset, "sampleLength", len(sample), "sample", sample, "candidates", numCandidates) } candidates, nodeStatuses, err := ev.DryRunPreemption(ctx, pod, potentialNodes, pdbs, offset, numCandidates) for node, nodeStatus := range unschedulableNodeStatus { @@ -257,7 +257,7 @@ func (ev *Evaluator) callExtenders(pod *v1.Pod, candidates []Candidate) ([]Candi if victims == nil || len(victims.Pods) == 0 { if extender.IsIgnorable() { delete(nodeNameToVictims, nodeName) - klog.InfoS("Ignoring node without victims", "node", nodeName) + klog.InfoS("Ignoring node without victims", "node", klog.KRef("", nodeName)) continue } return nil, framework.AsStatus(fmt.Errorf("expected at least one victim pod on node %q", nodeName)) @@ -307,7 +307,7 @@ func (ev *Evaluator) SelectCandidate(candidates []Candidate) Candidate { } // We shouldn't reach here. - klog.ErrorS(errors.New("no candidate selected"), "should not reach here", "candidates", candidates) + klog.ErrorS(errors.New("no candidate selected"), "Should not reach here", "candidates", candidates) // To not break the whole flow, return the first candidate. return candidates[0] } @@ -339,7 +339,7 @@ func (ev *Evaluator) prepareCandidate(c Candidate, pod *v1.Pod, pluginName strin // lets scheduler find another place for them. nominatedPods := getLowerPriorityNominatedPods(fh, pod, c.Name()) if err := util.ClearNominatedNodeName(cs, nominatedPods...); err != nil { - klog.ErrorS(err, "cannot clear 'NominatedNodeName' field") + klog.ErrorS(err, "Cannot clear 'NominatedNodeName' field") // We do not return as this error is not critical. } @@ -481,7 +481,7 @@ func pickOneNodeForPreemption(nodesToVictims map[string]*extenderv1.Victims) str if latestStartTime == nil { // If the earliest start time of all pods on the 1st node is nil, just return it, // which is not expected to happen. - klog.ErrorS(errors.New("earliestStartTime is nil for node"), "should not reach here", "node", minNodes2[0]) + klog.ErrorS(errors.New("earliestStartTime is nil for node"), "Should not reach here", "node", klog.KRef("", minNodes2[0])) return minNodes2[0] } nodeToReturn := minNodes2[0] @@ -490,7 +490,7 @@ func pickOneNodeForPreemption(nodesToVictims map[string]*extenderv1.Victims) str // Get earliest start time of all pods on the current node. earliestStartTimeOnNode := util.GetEarliestPodStartTime(nodesToVictims[node]) if earliestStartTimeOnNode == nil { - klog.ErrorS(errors.New("earliestStartTime is nil for node"), "should not reach here", "node", node) + klog.ErrorS(errors.New("earliestStartTime is nil for node"), "Should not reach here", "node", klog.KRef("", node)) continue } if earliestStartTimeOnNode.After(latestStartTime.Time) {