@@ -175,17 +175,15 @@ func (t *TopologyGroup) Hash() uint64 {
175
175
}
176
176
177
177
// nextDomainTopologySpread returns a scheduling.Requirement that includes a node domain that a pod should be scheduled to.
178
- // If there are multiple eligible domains, we return any random domain that satisfies the `maxSkew` configuration.
178
+ // If there are multiple eligible domains, we return all eligible domains that satisfies the `maxSkew` configuration.
179
179
// If there are no eligible domains, we return a `DoesNotExist` requirement, implying that we could not satisfy the topologySpread requirement.
180
180
// nolint:gocyclo
181
181
func (t * TopologyGroup ) nextDomainTopologySpread (pod * v1.Pod , podDomains , nodeDomains * scheduling.Requirement ) * scheduling.Requirement {
182
182
// min count is calculated across all domains
183
183
min := t .domainMinCount (podDomains )
184
184
selfSelecting := t .selects (pod )
185
185
186
- minDomain := ""
187
- minCount := int32 (math .MaxInt32 )
188
-
186
+ candidateDomains := []string {}
189
187
// If we are explicitly selecting on specific node domains ("In" requirement),
190
188
// this is going to be more efficient to iterate through
191
189
// This is particularly useful when considering the hostname topology key that can have a
@@ -196,9 +194,8 @@ func (t *TopologyGroup) nextDomainTopologySpread(pod *v1.Pod, podDomains, nodeDo
196
194
if selfSelecting {
197
195
count ++
198
196
}
199
- if count - min <= t .maxSkew && count < minCount {
200
- minDomain = domain
201
- minCount = count
197
+ if count - min <= t .maxSkew {
198
+ candidateDomains = append (candidateDomains , domain )
202
199
}
203
200
}
204
201
}
@@ -212,18 +209,17 @@ func (t *TopologyGroup) nextDomainTopologySpread(pod *v1.Pod, podDomains, nodeDo
212
209
if selfSelecting {
213
210
count ++
214
211
}
215
- if count - min <= t .maxSkew && count < minCount {
216
- minDomain = domain
217
- minCount = count
212
+ if count - min <= t .maxSkew {
213
+ candidateDomains = append (candidateDomains , domain )
218
214
}
219
215
}
220
216
}
221
217
}
222
- if minDomain == "" {
218
+ if len ( candidateDomains ) == 0 {
223
219
// avoids an error message about 'zone in [""]', preferring 'zone in []'
224
220
return scheduling .NewRequirement (podDomains .Key , v1 .NodeSelectorOpDoesNotExist )
225
221
}
226
- return scheduling .NewRequirement (podDomains .Key , v1 .NodeSelectorOpIn , minDomain )
222
+ return scheduling .NewRequirement (podDomains .Key , v1 .NodeSelectorOpIn , candidateDomains ... )
227
223
}
228
224
229
225
func (t * TopologyGroup ) domainMinCount (domains * scheduling.Requirement ) int32 {
0 commit comments