@@ -76,8 +76,9 @@ func (c *ReplicaCalculator) GetResourceReplicas(currentReplicas int32, targetUti
76
76
return 0 , 0 , 0 , time.Time {}, fmt .Errorf ("no pods returned by selector while calculating replica count" )
77
77
}
78
78
79
- readyPodCount , ignoredPods , missingPods := groupPods (podList , metrics , resource , c .cpuInitializationPeriod , c .delayOfInitialReadinessStatus )
79
+ readyPodCount , unreadyPods , missingPods , ignoredPods := groupPods (podList , metrics , resource , c .cpuInitializationPeriod , c .delayOfInitialReadinessStatus )
80
80
removeMetricsForPods (metrics , ignoredPods )
81
+ removeMetricsForPods (metrics , unreadyPods )
81
82
requests , err := calculatePodRequests (podList , resource )
82
83
if err != nil {
83
84
return 0 , 0 , 0 , time.Time {}, err
@@ -92,7 +93,7 @@ func (c *ReplicaCalculator) GetResourceReplicas(currentReplicas int32, targetUti
92
93
return 0 , 0 , 0 , time.Time {}, err
93
94
}
94
95
95
- rebalanceIgnored := len (ignoredPods ) > 0 && usageRatio > 1.0
96
+ rebalanceIgnored := len (unreadyPods ) > 0 && usageRatio > 1.0
96
97
if ! rebalanceIgnored && len (missingPods ) == 0 {
97
98
if math .Abs (1.0 - usageRatio ) <= c .tolerance {
98
99
// return the current replicas if the change would be too small
@@ -119,7 +120,7 @@ func (c *ReplicaCalculator) GetResourceReplicas(currentReplicas int32, targetUti
119
120
120
121
if rebalanceIgnored {
121
122
// on a scale-up, treat unready pods as using 0% of the resource request
122
- for podName := range ignoredPods {
123
+ for podName := range unreadyPods {
123
124
metrics [podName ] = metricsclient.PodMetric {Value : 0 }
124
125
}
125
126
}
@@ -184,16 +185,17 @@ func (c *ReplicaCalculator) calcPlainMetricReplicas(metrics metricsclient.PodMet
184
185
return 0 , 0 , fmt .Errorf ("no pods returned by selector while calculating replica count" )
185
186
}
186
187
187
- readyPodCount , ignoredPods , missingPods := groupPods (podList , metrics , resource , c .cpuInitializationPeriod , c .delayOfInitialReadinessStatus )
188
+ readyPodCount , unreadyPods , missingPods , ignoredPods := groupPods (podList , metrics , resource , c .cpuInitializationPeriod , c .delayOfInitialReadinessStatus )
188
189
removeMetricsForPods (metrics , ignoredPods )
190
+ removeMetricsForPods (metrics , unreadyPods )
189
191
190
192
if len (metrics ) == 0 {
191
193
return 0 , 0 , fmt .Errorf ("did not receive metrics for any ready pods" )
192
194
}
193
195
194
196
usageRatio , utilization := metricsclient .GetMetricUtilizationRatio (metrics , targetUtilization )
195
197
196
- rebalanceIgnored := len (ignoredPods ) > 0 && usageRatio > 1.0
198
+ rebalanceIgnored := len (unreadyPods ) > 0 && usageRatio > 1.0
197
199
198
200
if ! rebalanceIgnored && len (missingPods ) == 0 {
199
201
if math .Abs (1.0 - usageRatio ) <= c .tolerance {
@@ -221,7 +223,7 @@ func (c *ReplicaCalculator) calcPlainMetricReplicas(metrics metricsclient.PodMet
221
223
222
224
if rebalanceIgnored {
223
225
// on a scale-up, treat unready pods as using 0% of the resource request
224
- for podName := range ignoredPods {
226
+ for podName := range unreadyPods {
225
227
metrics [podName ] = metricsclient.PodMetric {Value : 0 }
226
228
}
227
229
}
@@ -366,16 +368,18 @@ func (c *ReplicaCalculator) GetExternalPerPodMetricReplicas(statusReplicas int32
366
368
return replicaCount , utilization , timestamp , nil
367
369
}
368
370
369
- func groupPods (pods []* v1.Pod , metrics metricsclient.PodMetricsInfo , resource v1.ResourceName , cpuInitializationPeriod , delayOfInitialReadinessStatus time.Duration ) (readyPodCount int , ignoredPods sets. String , missingPods sets.String ) {
371
+ func groupPods (pods []* v1.Pod , metrics metricsclient.PodMetricsInfo , resource v1.ResourceName , cpuInitializationPeriod , delayOfInitialReadinessStatus time.Duration ) (readyPodCount int , unreadyPods , missingPods , ignoredPods sets.String ) {
370
372
missingPods = sets .NewString ()
373
+ unreadyPods = sets .NewString ()
371
374
ignoredPods = sets .NewString ()
372
375
for _ , pod := range pods {
373
376
if pod .DeletionTimestamp != nil || pod .Status .Phase == v1 .PodFailed {
377
+ ignoredPods .Insert (pod .Name )
374
378
continue
375
379
}
376
380
// Pending pods are ignored.
377
381
if pod .Status .Phase == v1 .PodPending {
378
- ignoredPods .Insert (pod .Name )
382
+ unreadyPods .Insert (pod .Name )
379
383
continue
380
384
}
381
385
// Pods missing metrics.
@@ -386,22 +390,22 @@ func groupPods(pods []*v1.Pod, metrics metricsclient.PodMetricsInfo, resource v1
386
390
}
387
391
// Unready pods are ignored.
388
392
if resource == v1 .ResourceCPU {
389
- var ignorePod bool
393
+ var unready bool
390
394
_ , condition := podutil .GetPodCondition (& pod .Status , v1 .PodReady )
391
395
if condition == nil || pod .Status .StartTime == nil {
392
- ignorePod = true
396
+ unready = true
393
397
} else {
394
398
// Pod still within possible initialisation period.
395
399
if pod .Status .StartTime .Add (cpuInitializationPeriod ).After (time .Now ()) {
396
400
// Ignore sample if pod is unready or one window of metric wasn't collected since last state transition.
397
- ignorePod = condition .Status == v1 .ConditionFalse || metric .Timestamp .Before (condition .LastTransitionTime .Time .Add (metric .Window ))
401
+ unready = condition .Status == v1 .ConditionFalse || metric .Timestamp .Before (condition .LastTransitionTime .Time .Add (metric .Window ))
398
402
} else {
399
403
// Ignore metric if pod is unready and it has never been ready.
400
- ignorePod = condition .Status == v1 .ConditionFalse && pod .Status .StartTime .Add (delayOfInitialReadinessStatus ).After (condition .LastTransitionTime .Time )
404
+ unready = condition .Status == v1 .ConditionFalse && pod .Status .StartTime .Add (delayOfInitialReadinessStatus ).After (condition .LastTransitionTime .Time )
401
405
}
402
406
}
403
- if ignorePod {
404
- ignoredPods .Insert (pod .Name )
407
+ if unready {
408
+ unreadyPods .Insert (pod .Name )
405
409
continue
406
410
}
407
411
}
0 commit comments