@@ -166,7 +166,7 @@ type scaleDownResourcesDelta map[string]int64
166166// used as a value in scaleDownResourcesLimits if actual limit could not be obtained due to errors talking to cloud provider
167167const scaleDownLimitUnknown = math .MinInt64
168168
169- func computeScaleDownResourcesLeftLimits (nodes []* schedulernodeinfo. NodeInfo , resourceLimiter * cloudprovider.ResourceLimiter , cp cloudprovider.CloudProvider , timestamp time.Time ) scaleDownResourcesLimits {
169+ func computeScaleDownResourcesLeftLimits (nodes []* apiv1. Node , resourceLimiter * cloudprovider.ResourceLimiter , cp cloudprovider.CloudProvider , timestamp time.Time ) scaleDownResourcesLimits {
170170 totalCores , totalMem := calculateScaleDownCoresMemoryTotal (nodes , timestamp )
171171
172172 var totalGpus map [string ]int64
@@ -208,10 +208,9 @@ func computeAboveMin(total int64, min int64) int64 {
208208
209209}
210210
211- func calculateScaleDownCoresMemoryTotal (nodes []* schedulernodeinfo. NodeInfo , timestamp time.Time ) (int64 , int64 ) {
211+ func calculateScaleDownCoresMemoryTotal (nodes []* apiv1. Node , timestamp time.Time ) (int64 , int64 ) {
212212 var coresTotal , memoryTotal int64
213- for _ , nodeInfo := range nodes {
214- node := nodeInfo .Node ()
213+ for _ , node := range nodes {
215214 if isNodeBeingDeleted (node , timestamp ) {
216215 // Nodes being deleted do not count towards total cluster resources
217216 continue
@@ -225,16 +224,15 @@ func calculateScaleDownCoresMemoryTotal(nodes []*schedulernodeinfo.NodeInfo, tim
225224 return coresTotal , memoryTotal
226225}
227226
228- func calculateScaleDownGpusTotal (nodes []* schedulernodeinfo. NodeInfo , cp cloudprovider.CloudProvider , timestamp time.Time ) (map [string ]int64 , error ) {
227+ func calculateScaleDownGpusTotal (nodes []* apiv1. Node , cp cloudprovider.CloudProvider , timestamp time.Time ) (map [string ]int64 , error ) {
229228 type gpuInfo struct {
230229 name string
231230 count int64
232231 }
233232
234233 result := make (map [string ]int64 )
235234 ngCache := make (map [string ]gpuInfo )
236- for _ , nodeInfo := range nodes {
237- node := nodeInfo .Node ()
235+ for _ , node := range nodes {
238236 if isNodeBeingDeleted (node , timestamp ) {
239237 // Nodes being deleted do not count towards total cluster resources
240238 continue
@@ -753,6 +751,9 @@ func (sd *ScaleDown) TryToScaleDown(pdbs []*policyv1.PodDisruptionBudget, curren
753751
754752 nodesWithoutMaster := filterOutMasters (allNodeInfos )
755753 nodesWithoutMasterNames := make ([]string , 0 , len (nodesWithoutMaster ))
754+ for _ , node := range nodesWithoutMaster {
755+ nodesWithoutMasterNames = append (nodesWithoutMasterNames , node .Name )
756+ }
756757
757758 candidateNames := make ([]string , 0 )
758759 readinessMap := make (map [string ]bool )
@@ -770,17 +771,16 @@ func (sd *ScaleDown) TryToScaleDown(pdbs []*policyv1.PodDisruptionBudget, curren
770771
771772 nodeGroupSize := utils .GetNodeGroupSizeMap (sd .context .CloudProvider )
772773 resourcesWithLimits := resourceLimiter .GetResources ()
773- for _ , nodeInfo := range nodesWithoutMaster {
774- node := nodeInfo .Node ()
775- nodesWithoutMasterNames = append (nodesWithoutMasterNames , node .Name )
774+ for nodeName , unneededSince := range sd .unneededNodes {
775+ klog .V (2 ).Infof ("%s was unneeded for %s" , nodeName , currentTime .Sub (unneededSince ).String ())
776776
777- unneededSince , found := sd .unneededNodes [ node . Name ]
778- if ! found {
779- // Node is not unneeded.
777+ nodeInfo , err := sd .context . ClusterSnapshot . NodeInfos (). Get ( nodeName )
778+ if err != nil {
779+ klog . Errorf ( "Can't retrieve unneeded node %s from snapshot, err: %v" , nodeName , err )
780780 continue
781781 }
782782
783- klog . V ( 2 ). Infof ( "%s was unneeded for %s" , node . Name , currentTime . Sub ( unneededSince ). String () )
783+ node := nodeInfo . Node ( )
784784
785785 // Check if node is marked with no scale down annotation.
786786 if hasNoScaleDownAnnotation (node ) {
@@ -1326,11 +1326,11 @@ func isMasterNode(nodeInfo *schedulernodeinfo.NodeInfo) bool {
13261326 return false
13271327}
13281328
1329- func filterOutMasters (nodeInfos []* schedulernodeinfo.NodeInfo ) []* schedulernodeinfo. NodeInfo {
1330- result := make ([]* schedulernodeinfo. NodeInfo , 0 , len (nodeInfos ))
1329+ func filterOutMasters (nodeInfos []* schedulernodeinfo.NodeInfo ) []* apiv1. Node {
1330+ result := make ([]* apiv1. Node , 0 , len (nodeInfos ))
13311331 for _ , nodeInfo := range nodeInfos {
13321332 if ! isMasterNode (nodeInfo ) {
1333- result = append (result , nodeInfo )
1333+ result = append (result , nodeInfo . Node () )
13341334 }
13351335 }
13361336 return result
0 commit comments