From ce87b48497828f089d3950089cb1291bb69802a2 Mon Sep 17 00:00:00 2001 From: "(Brien Dieterle)" <(briend@gmail.com)> Date: Sat, 5 Sep 2020 01:30:59 +1000 Subject: [PATCH] Convert logs to use structured logging --- pkg/descheduler/evictions/evictions.go | 4 ++-- pkg/descheduler/strategies/lownodeutilization.go | 12 ++++++------ pkg/descheduler/strategies/node_affinity.go | 2 +- pkg/utils/predicates.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/descheduler/evictions/evictions.go b/pkg/descheduler/evictions/evictions.go index d04d9b5230..dec7a31222 100644 --- a/pkg/descheduler/evictions/evictions.go +++ b/pkg/descheduler/evictions/evictions.go @@ -112,9 +112,9 @@ func (pe *PodEvictor) EvictPod(ctx context.Context, pod *v1.Pod, node *v1.Node, pe.nodepodCount[node]++ if pe.dryRun { - klog.V(1).Infof("Evicted pod in dry run mode: %#v in namespace %#v%s", pod.Name, pod.Namespace, reason) + klog.V(1).InfoS("Evicted pod in dry run mode", "pod", klog.KObj(pod), "reason", reason) } else { - klog.V(1).Infof("Evicted pod: %#v in namespace %#v%s", pod.Name, pod.Namespace, reason) + klog.V(1).InfoS("Evicted pod", "pod", klog.KObj(pod), "reason", reason) eventBroadcaster := record.NewBroadcaster() eventBroadcaster.StartLogging(klog.V(3).Infof) eventBroadcaster.StartRecordingToSink(&clientcorev1.EventSinkImpl{Interface: pe.client.CoreV1().Events(pod.Namespace)}) diff --git a/pkg/descheduler/strategies/lownodeutilization.go b/pkg/descheduler/strategies/lownodeutilization.go index 4d608770a7..0e3378cd5c 100644 --- a/pkg/descheduler/strategies/lownodeutilization.go +++ b/pkg/descheduler/strategies/lownodeutilization.go @@ -98,14 +98,14 @@ func LowNodeUtilization(ctx context.Context, client clientset.Interface, strateg npm := createNodePodsMap(ctx, client, nodes) lowNodes, targetNodes := classifyNodes(npm, thresholds, targetThresholds) - klog.V(1).Infof("Criteria for a node under utilization: CPU: %v, Mem: %v, Pods: %v", - thresholds[v1.ResourceCPU], thresholds[v1.ResourceMemory], thresholds[v1.ResourcePods]) + klog.V(1).InfoS("Criteria for a node under utilization", + "CPU", thresholds[v1.ResourceCPU], "Mem", thresholds[v1.ResourceMemory], "Pods", thresholds[v1.ResourcePods]) if len(lowNodes) == 0 { klog.V(1).Infof("No node is underutilized, nothing to do here, you might tune your thresholds further") return } - klog.V(1).Infof("Total number of underutilized nodes: %v", len(lowNodes)) + klog.V(1).InfoS("Total number of underutilized nodes", "totalNumber", len(lowNodes)) if len(lowNodes) < strategy.Params.NodeResourceUtilizationThresholds.NumberOfNodes { klog.V(1).Infof("number of nodes underutilized (%v) is less than NumberOfNodes (%v), nothing to do here", len(lowNodes), strategy.Params.NodeResourceUtilizationThresholds.NumberOfNodes) @@ -122,10 +122,10 @@ func LowNodeUtilization(ctx context.Context, client clientset.Interface, strateg return } - klog.V(1).Infof("Criteria for a node above target utilization: CPU: %v, Mem: %v, Pods: %v", - targetThresholds[v1.ResourceCPU], targetThresholds[v1.ResourceMemory], targetThresholds[v1.ResourcePods]) - klog.V(1).Infof("Total number of nodes above target utilization: %v", len(targetNodes)) + klog.V(1).InfoS("Criteria for a node above target utilization", + "CPU", targetThresholds[v1.ResourceCPU], "Mem", targetThresholds[v1.ResourceMemory], "Pods", targetThresholds[v1.ResourcePods]) + klog.V(1).InfoS("Number of nodes above target utilization", "totalNumber", len(targetNodes)) evictable := podEvictor.Evictable(evictions.WithPriorityThreshold(thresholdPriority)) evictPodsFromTargetNodes( diff --git a/pkg/descheduler/strategies/node_affinity.go b/pkg/descheduler/strategies/node_affinity.go index 1dc95a9835..9a33cef7ea 100644 --- a/pkg/descheduler/strategies/node_affinity.go +++ b/pkg/descheduler/strategies/node_affinity.go @@ -104,5 +104,5 @@ func RemovePodsViolatingNodeAffinity(ctx context.Context, client clientset.Inter klog.Errorf("invalid nodeAffinityType: %v", nodeAffinity) } } - klog.V(1).Infof("Evicted %v pods", podEvictor.TotalEvicted()) + klog.V(1).InfoS("Number of evicted pods", "totalEvicted", podEvictor.TotalEvicted()) } diff --git a/pkg/utils/predicates.go b/pkg/utils/predicates.go index b991984b88..555d2f9d6b 100644 --- a/pkg/utils/predicates.go +++ b/pkg/utils/predicates.go @@ -70,7 +70,7 @@ func podMatchesNodeLabels(pod *v1.Pod, node *v1.Node) bool { // Match node selector for requiredDuringSchedulingIgnoredDuringExecution. if nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution != nil { nodeSelectorTerms := nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms - klog.V(10).Infof("Match for RequiredDuringSchedulingIgnoredDuringExecution node selector terms %+v", nodeSelectorTerms) + klog.V(10).InfoS("Match for RequiredDuringSchedulingIgnoredDuringExecution node selector terms", "terms", nodeSelectorTerms) return nodeMatchesNodeSelectorTerms(node, nodeSelectorTerms) } }