Skip to content

Commit 31a62ea

Browse files
committed
support multiple domains in scheduling
1 parent b172f77 commit 31a62ea

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

pkg/controllers/provisioning/scheduling/topologygroup.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,15 @@ func (t *TopologyGroup) Hash() uint64 {
175175
}
176176

177177
// 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.
179179
// If there are no eligible domains, we return a `DoesNotExist` requirement, implying that we could not satisfy the topologySpread requirement.
180180
// nolint:gocyclo
181181
func (t *TopologyGroup) nextDomainTopologySpread(pod *v1.Pod, podDomains, nodeDomains *scheduling.Requirement) *scheduling.Requirement {
182182
// min count is calculated across all domains
183183
min := t.domainMinCount(podDomains)
184184
selfSelecting := t.selects(pod)
185185

186-
minDomain := ""
187-
minCount := int32(math.MaxInt32)
188-
186+
candidateDomains := []string{}
189187
// If we are explicitly selecting on specific node domains ("In" requirement),
190188
// this is going to be more efficient to iterate through
191189
// 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
196194
if selfSelecting {
197195
count++
198196
}
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)
202199
}
203200
}
204201
}
@@ -212,18 +209,17 @@ func (t *TopologyGroup) nextDomainTopologySpread(pod *v1.Pod, podDomains, nodeDo
212209
if selfSelecting {
213210
count++
214211
}
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)
218214
}
219215
}
220216
}
221217
}
222-
if minDomain == "" {
218+
if len(candidateDomains) == 0 {
223219
// avoids an error message about 'zone in [""]', preferring 'zone in []'
224220
return scheduling.NewRequirement(podDomains.Key, v1.NodeSelectorOpDoesNotExist)
225221
}
226-
return scheduling.NewRequirement(podDomains.Key, v1.NodeSelectorOpIn, minDomain)
222+
return scheduling.NewRequirement(podDomains.Key, v1.NodeSelectorOpIn, candidateDomains...)
227223
}
228224

229225
func (t *TopologyGroup) domainMinCount(domains *scheduling.Requirement) int32 {

0 commit comments

Comments
 (0)