@@ -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 .Background ().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
@@ -115,16 +117,18 @@ func NewLowNodeUtilization(
115
117
// have the correct one or an error is triggered. XXX MetricsServer is
116
118
// deprecated, removed once dropped.
117
119
var usageClient usageClient = newRequestedUsageClient (
120
+ logger .WithValues ("client" , "RequestedUsageClient" ),
118
121
extendedResourceNames , handle .GetPodsAssignedToNodeFunc (),
119
122
)
120
123
if metrics != nil {
121
- usageClient , err = usageClientForMetrics (args , handle , extendedResourceNames )
124
+ usageClient , err = usageClientForMetrics (logger , args , handle , extendedResourceNames )
122
125
if err != nil {
123
126
return nil , err
124
127
}
125
128
}
126
129
127
130
return & LowNodeUtilization {
131
+ logger : logger ,
128
132
handle : handle ,
129
133
args : args ,
130
134
underCriteria : underCriteria ,
@@ -145,6 +149,8 @@ func (l *LowNodeUtilization) Name() string {
145
149
// utilized nodes to under utilized nodes. The goal here is to evenly
146
150
// distribute pods across nodes.
147
151
func (l * LowNodeUtilization ) Balance (ctx context.Context , nodes []* v1.Node ) * frameworktypes.Status {
152
+ logger := klog .FromContext (klog .NewContext (ctx , l .logger )).WithValues ("ExtensionPoint" , frameworktypes .BalanceExtensionPoint )
153
+
148
154
if err := l .usageClient .sync (ctx , nodes ); err != nil {
149
155
return & frameworktypes.Status {
150
156
Err : fmt .Errorf ("error getting node usage: %v" , err ),
@@ -192,7 +198,7 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
192
198
// underutilized but aren't schedulable are ignored.
193
199
func (nodeName string , usage , threshold api.ResourceThresholds ) bool {
194
200
if nodeutil .IsNodeUnschedulable (nodesMap [nodeName ]) {
195
- klog .V (2 ).InfoS (
201
+ logger .V (2 ).Info (
196
202
"Node is unschedulable, thus not considered as underutilized" ,
197
203
"node" , klog .KObj (nodesMap [nodeName ]),
198
204
)
@@ -217,7 +223,7 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
217
223
for nodeName := range nodeGroups [i ] {
218
224
classifiedNodes [nodeName ] = true
219
225
220
- klog . InfoS (
226
+ logger . Info (
221
227
"Node has been classified" ,
222
228
"category" , categories [i ],
223
229
"node" , klog .KObj (nodesMap [nodeName ]),
@@ -243,7 +249,7 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
243
249
// log nodes that are appropriately utilized.
244
250
for nodeName := range nodesMap {
245
251
if ! classifiedNodes [nodeName ] {
246
- klog . InfoS (
252
+ logger . Info (
247
253
"Node is appropriately utilized" ,
248
254
"node" , klog .KObj (nodesMap [nodeName ]),
249
255
"usage" , nodesUsageMap [nodeName ],
@@ -255,20 +261,20 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
255
261
lowNodes , highNodes := nodeInfos [0 ], nodeInfos [1 ]
256
262
257
263
// log messages for nodes with low and high utilization
258
- klog .V (1 ).InfoS ("Criteria for a node under utilization" , l . underCriteria ... )
259
- klog .V (1 ).InfoS ("Number of underutilized nodes" , "totalNumber" , len (lowNodes ))
260
- klog .V (1 ).InfoS ("Criteria for a node above target utilization" , l . overCriteria ... )
261
- klog .V (1 ).InfoS ("Number of overutilized nodes" , "totalNumber" , len (highNodes ))
264
+ logger .V (1 ).Info ("Criteria for a node under utilization" , " underCriteria" , klog . KObjSlice ( l . underCriteria ) )
265
+ logger .V (1 ).Info ("Number of underutilized nodes" , "totalNumber" , len (lowNodes ))
266
+ logger .V (1 ).Info ("Criteria for a node above target utilization" , " overCriteria" , klog . KObjSlice ( l . overCriteria ) )
267
+ logger .V (1 ).Info ("Number of overutilized nodes" , "totalNumber" , len (highNodes ))
262
268
263
269
if len (lowNodes ) == 0 {
264
- klog .V (1 ).InfoS (
270
+ logger .V (1 ).Info (
265
271
"No node is underutilized, nothing to do here, you might tune your thresholds further" ,
266
272
)
267
273
return nil
268
274
}
269
275
270
276
if len (lowNodes ) <= l .args .NumberOfNodes {
271
- klog .V (1 ).InfoS (
277
+ logger .V (1 ).Info (
272
278
"Number of nodes underutilized is less or equal than NumberOfNodes, nothing to do here" ,
273
279
"underutilizedNodes" , len (lowNodes ),
274
280
"numberOfNodes" , l .args .NumberOfNodes ,
@@ -277,12 +283,12 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
277
283
}
278
284
279
285
if len (lowNodes ) == len (nodes ) {
280
- klog .V (1 ).InfoS ("All nodes are underutilized, nothing to do here" )
286
+ logger .V (1 ).Info ("All nodes are underutilized, nothing to do here" )
281
287
return nil
282
288
}
283
289
284
290
if len (highNodes ) == 0 {
285
- klog .V (1 ).InfoS ("All nodes are under target utilization, nothing to do here" )
291
+ logger .V (1 ).Info ("All nodes are under target utilization, nothing to do here" )
286
292
return nil
287
293
}
288
294
@@ -359,6 +365,7 @@ func validatePrometheusMetricsUtilization(args *LowNodeUtilizationArgs) error {
359
365
// usageClientForMetrics returns the correct usage client based on the
360
366
// metrics source. XXX MetricsServer is deprecated, removed once dropped.
361
367
func usageClientForMetrics (
368
+ logger klog.Logger ,
362
369
args * LowNodeUtilizationArgs , handle frameworktypes.Handle , resources []v1.ResourceName ,
363
370
) (usageClient , error ) {
364
371
metrics := args .MetricsUtilization
@@ -368,6 +375,7 @@ func usageClientForMetrics(
368
375
return nil , fmt .Errorf ("metrics client not initialized" )
369
376
}
370
377
return newActualUsageClient (
378
+ logger .WithValues ("client" , "ActualUsageClient" ),
371
379
resources ,
372
380
handle .GetPodsAssignedToNodeFunc (),
373
381
handle .MetricsCollector (),
@@ -378,6 +386,7 @@ func usageClientForMetrics(
378
386
return nil , fmt .Errorf ("prometheus client not initialized" )
379
387
}
380
388
return newPrometheusUsageClient (
389
+ logger .WithValues ("client" , "PrometheusUsageClient" ),
381
390
handle .GetPodsAssignedToNodeFunc (),
382
391
handle .PrometheusClient (),
383
392
metrics .Prometheus .Query ,
0 commit comments