@@ -43,6 +43,7 @@ var _ frameworktypes.BalancePlugin = &LowNodeUtilization{}
43
43
// nodes. Note that CPU/Memory requests are used to calculate nodes'
44
44
// utilization and not the actual resource usage.
45
45
type LowNodeUtilization struct {
46
+ logger klog.Logger
46
47
handle frameworktypes.Handle
47
48
args * LowNodeUtilizationArgs
48
49
podFilter func (pod * v1.Pod ) bool
@@ -66,6 +67,7 @@ func NewLowNodeUtilization(
66
67
genericArgs ,
67
68
)
68
69
}
70
+ logger := klog .FromContext (ctx ).WithValues ("plugin" , LowNodeUtilizationPluginName )
69
71
70
72
// resourceNames holds a list of resources for which the user has
71
73
// provided thresholds for. extendedResourceNames holds those as well
@@ -105,16 +107,18 @@ func NewLowNodeUtilization(
105
107
// have the correct one or an error is triggered. XXX MetricsServer is
106
108
// deprecated, removed once dropped.
107
109
var usageClient usageClient = newRequestedUsageClient (
110
+ logger .WithValues ("client" , "RequestedUsageClient" ),
108
111
extendedResourceNames , handle .GetPodsAssignedToNodeFunc (),
109
112
)
110
113
if metrics != nil {
111
- usageClient , err = usageClientForMetrics (args , handle , extendedResourceNames )
114
+ usageClient , err = usageClientForMetrics (logger , args , handle , extendedResourceNames )
112
115
if err != nil {
113
116
return nil , err
114
117
}
115
118
}
116
119
117
120
return & LowNodeUtilization {
121
+ logger : logger ,
118
122
handle : handle ,
119
123
args : args ,
120
124
underCriteria : thresholdsToKeysAndValues (args .Thresholds ),
@@ -135,6 +139,8 @@ func (l *LowNodeUtilization) Name() string {
135
139
// utilized nodes to under utilized nodes. The goal here is to evenly
136
140
// distribute pods across nodes.
137
141
func (l * LowNodeUtilization ) Balance (ctx context.Context , nodes []* v1.Node ) * frameworktypes.Status {
142
+ logger := klog .FromContext (klog .NewContext (ctx , l .logger )).WithValues ("ExtensionPoint" , frameworktypes .BalanceExtensionPoint )
143
+
138
144
if err := l .usageClient .sync (ctx , nodes ); err != nil {
139
145
return & frameworktypes.Status {
140
146
Err : fmt .Errorf ("error getting node usage: %v" , err ),
@@ -182,7 +188,7 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
182
188
// underutilized but aren't schedulable are ignored.
183
189
func (nodeName string , usage , threshold api.ResourceThresholds ) bool {
184
190
if nodeutil .IsNodeUnschedulable (nodesMap [nodeName ]) {
185
- klog .V (2 ).InfoS (
191
+ logger .V (2 ).Info (
186
192
"Node is unschedulable, thus not considered as underutilized" ,
187
193
"node" , klog .KObj (nodesMap [nodeName ]),
188
194
)
@@ -207,7 +213,7 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
207
213
for nodeName := range nodeGroups [i ] {
208
214
classifiedNodes [nodeName ] = true
209
215
210
- klog . InfoS (
216
+ logger . Info (
211
217
"Node has been classified" ,
212
218
"category" , categories [i ],
213
219
"node" , klog .KObj (nodesMap [nodeName ]),
@@ -233,7 +239,7 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
233
239
// log nodes that are appropriately utilized.
234
240
for nodeName := range nodesMap {
235
241
if ! classifiedNodes [nodeName ] {
236
- klog . InfoS (
242
+ logger . Info (
237
243
"Node is appropriately utilized" ,
238
244
"node" , klog .KObj (nodesMap [nodeName ]),
239
245
"usage" , nodesUsageMap [nodeName ],
@@ -245,20 +251,20 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
245
251
lowNodes , highNodes := nodeInfos [0 ], nodeInfos [1 ]
246
252
247
253
// log messages for nodes with low and high utilization
248
- klog .V (1 ).InfoS ("Criteria for a node under utilization" , l .underCriteria ... )
249
- klog .V (1 ).InfoS ("Number of underutilized nodes" , "totalNumber" , len (lowNodes ))
250
- klog .V (1 ).InfoS ("Criteria for a node above target utilization" , l .overCriteria ... )
251
- klog .V (1 ).InfoS ("Number of overutilized nodes" , "totalNumber" , len (highNodes ))
254
+ logger .V (1 ).Info ("Criteria for a node under utilization" , l .underCriteria ... )
255
+ logger .V (1 ).Info ("Number of underutilized nodes" , "totalNumber" , len (lowNodes ))
256
+ logger .V (1 ).Info ("Criteria for a node above target utilization" , l .overCriteria ... )
257
+ logger .V (1 ).Info ("Number of overutilized nodes" , "totalNumber" , len (highNodes ))
252
258
253
259
if len (lowNodes ) == 0 {
254
- klog .V (1 ).InfoS (
260
+ logger .V (1 ).Info (
255
261
"No node is underutilized, nothing to do here, you might tune your thresholds further" ,
256
262
)
257
263
return nil
258
264
}
259
265
260
266
if len (lowNodes ) <= l .args .NumberOfNodes {
261
- klog .V (1 ).InfoS (
267
+ logger .V (1 ).Info (
262
268
"Number of nodes underutilized is less or equal than NumberOfNodes, nothing to do here" ,
263
269
"underutilizedNodes" , len (lowNodes ),
264
270
"numberOfNodes" , l .args .NumberOfNodes ,
@@ -267,12 +273,12 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
267
273
}
268
274
269
275
if len (lowNodes ) == len (nodes ) {
270
- klog .V (1 ).InfoS ("All nodes are underutilized, nothing to do here" )
276
+ logger .V (1 ).Info ("All nodes are underutilized, nothing to do here" )
271
277
return nil
272
278
}
273
279
274
280
if len (highNodes ) == 0 {
275
- klog .V (1 ).InfoS ("All nodes are under target utilization, nothing to do here" )
281
+ logger .V (1 ).Info ("All nodes are under target utilization, nothing to do here" )
276
282
return nil
277
283
}
278
284
@@ -349,6 +355,7 @@ func validatePrometheusMetricsUtilization(args *LowNodeUtilizationArgs) error {
349
355
// usageClientForMetrics returns the correct usage client based on the
350
356
// metrics source. XXX MetricsServer is deprecated, removed once dropped.
351
357
func usageClientForMetrics (
358
+ logger klog.Logger ,
352
359
args * LowNodeUtilizationArgs , handle frameworktypes.Handle , resources []v1.ResourceName ,
353
360
) (usageClient , error ) {
354
361
metrics := args .MetricsUtilization
@@ -358,6 +365,7 @@ func usageClientForMetrics(
358
365
return nil , fmt .Errorf ("metrics client not initialized" )
359
366
}
360
367
return newActualUsageClient (
368
+ logger .WithValues ("client" , "ActualUsageClient" ),
361
369
resources ,
362
370
handle .GetPodsAssignedToNodeFunc (),
363
371
handle .MetricsCollector (),
@@ -368,6 +376,7 @@ func usageClientForMetrics(
368
376
return nil , fmt .Errorf ("prometheus client not initialized" )
369
377
}
370
378
return newPrometheusUsageClient (
379
+ logger .WithValues ("client" , "PrometheusUsageClient" ),
371
380
handle .GetPodsAssignedToNodeFunc (),
372
381
handle .PrometheusClient (),
373
382
metrics .Prometheus .Query ,
0 commit comments