@@ -122,22 +122,64 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
122
122
}
123
123
}
124
124
125
- lowNodes , sourceNodes := classifyNodes (
126
- getNodeUsage (nodes , l .usageClient ),
127
- getNodeThresholds (nodes , l .args .Thresholds , l .args .TargetThresholds , l .resourceNames , l .args .UseDeviationThresholds , l .usageClient ),
128
- // The node has to be schedulable (to be able to move workload there)
129
- func (node * v1.Node , usage NodeUsage , threshold NodeThresholds ) bool {
130
- if nodeutil .IsNodeUnschedulable (node ) {
131
- klog .V (2 ).InfoS ("Node is unschedulable, thus not considered as underutilized" , "node" , klog .KObj (node ))
132
- return false
133
- }
134
- return isNodeWithLowUtilization (usage , threshold .lowResourceThreshold )
135
- },
136
- func (node * v1.Node , usage NodeUsage , threshold NodeThresholds ) bool {
137
- return isNodeAboveTargetUtilization (usage , threshold .highResourceThreshold )
125
+ nodesMap , nodesUsageMap , podListMap := getNodeUsageSnapshot (nodes , l .usageClient )
126
+ var nodeThresholdsMap map [string ][]api.ResourceThresholds
127
+ if l .args .UseDeviationThresholds {
128
+ nodeThresholdsMap = getNodeThresholdsFromAverageNodeUsage (nodes , l .usageClient , l .args .Thresholds , l .args .TargetThresholds )
129
+ } else {
130
+ nodeThresholdsMap = getStaticNodeThresholds (nodes , l .args .Thresholds , l .args .TargetThresholds )
131
+ }
132
+ nodesUsageAsNodeThresholdsMap := nodeUsageToResourceThresholds (nodesUsageMap , nodesMap )
133
+
134
+ nodeGroups := classifyNodeUsage (
135
+ nodesUsageAsNodeThresholdsMap ,
136
+ nodeThresholdsMap ,
137
+ []classifierFnc {
138
+ // underutilization
139
+ func (nodeName string , usage , threshold api.ResourceThresholds ) bool {
140
+ if nodeutil .IsNodeUnschedulable (nodesMap [nodeName ]) {
141
+ klog .V (2 ).InfoS ("Node is unschedulable, thus not considered as underutilized" , "node" , klog .KObj (nodesMap [nodeName ]))
142
+ return false
143
+ }
144
+ return isNodeBelowThreshold (usage , threshold )
145
+ },
146
+ // overutilization
147
+ func (nodeName string , usage , threshold api.ResourceThresholds ) bool {
148
+ return isNodeAboveThreshold (usage , threshold )
149
+ },
138
150
},
139
151
)
140
152
153
+ // convert groups node []NodeInfo
154
+ nodeInfos := make ([][]NodeInfo , 2 )
155
+ category := []string {"underutilized" , "overutilized" }
156
+ listedNodes := map [string ]struct {}{}
157
+ for i := range nodeGroups {
158
+ for nodeName := range nodeGroups [i ] {
159
+ klog .InfoS ("Node is " + category [i ], "node" , klog .KObj (nodesMap [nodeName ]), "usage" , nodesUsageMap [nodeName ], "usagePercentage" , resourceUsagePercentages (nodesUsageMap [nodeName ], nodesMap [nodeName ], true ))
160
+ listedNodes [nodeName ] = struct {}{}
161
+ nodeInfos [i ] = append (nodeInfos [i ], NodeInfo {
162
+ NodeUsage : NodeUsage {
163
+ node : nodesMap [nodeName ],
164
+ usage : nodesUsageMap [nodeName ], // get back the original node usage
165
+ allPods : podListMap [nodeName ],
166
+ },
167
+ thresholds : NodeThresholds {
168
+ lowResourceThreshold : resourceThresholdsToNodeUsage (nodeThresholdsMap [nodeName ][0 ], nodesMap [nodeName ]),
169
+ highResourceThreshold : resourceThresholdsToNodeUsage (nodeThresholdsMap [nodeName ][1 ], nodesMap [nodeName ]),
170
+ },
171
+ })
172
+ }
173
+ }
174
+ for nodeName := range nodesMap {
175
+ if _ , ok := listedNodes [nodeName ]; ! ok {
176
+ klog .InfoS ("Node is appropriately utilized" , "node" , klog .KObj (nodesMap [nodeName ]), "usage" , nodesUsageMap [nodeName ], "usagePercentage" , resourceUsagePercentages (nodesUsageMap [nodeName ], nodesMap [nodeName ], true ))
177
+ }
178
+ }
179
+
180
+ lowNodes := nodeInfos [0 ]
181
+ sourceNodes := nodeInfos [1 ]
182
+
141
183
// log message for nodes with low utilization
142
184
klog .V (1 ).InfoS ("Criteria for a node under utilization" , l .underutilizationCriteria ... )
143
185
klog .V (1 ).InfoS ("Number of underutilized nodes" , "totalNumber" , len (lowNodes ))
0 commit comments