mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #80503 from tedyu/spread-constaints
Refactor nested loop in getTPMapMatchingSpreadConstraints
This commit is contained in:
commit
50a0d38e3a
@ -232,20 +232,20 @@ func getTPMapMatchingSpreadConstraints(pod *v1.Pod, nodeInfoMap map[string]*sche
|
|||||||
if !podMatchesNodeSelectorAndAffinityTerms(pod, node) {
|
if !podMatchesNodeSelectorAndAffinityTerms(pod, node) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure current node's labels contains all topologyKeys in 'constraints'.
|
// Ensure current node's labels contains all topologyKeys in 'constraints'.
|
||||||
if !nodeLabelsMatchSpreadConstraints(node.Labels, constraints) {
|
if !nodeLabelsMatchSpreadConstraints(node.Labels, constraints) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeTopologyMaps := newTopologyPairsMaps()
|
nodeTopologyMaps := newTopologyPairsMaps()
|
||||||
// nodeInfo.Pods() can be empty; or all pods don't fit
|
for _, constraint := range constraints {
|
||||||
for _, existingPod := range nodeInfo.Pods() {
|
pairAdded := false
|
||||||
if existingPod.Namespace != pod.Namespace {
|
// nodeInfo.Pods() can be empty; or all pods don't fit
|
||||||
continue
|
for _, existingPod := range nodeInfo.Pods() {
|
||||||
}
|
if existingPod.Namespace != pod.Namespace {
|
||||||
podLabelSet := labels.Set(existingPod.Labels)
|
continue
|
||||||
for _, constraint := range constraints {
|
}
|
||||||
ok, err := podMatchesSpreadConstraint(podLabelSet, constraint)
|
ok, err := podMatchesSpreadConstraint(existingPod.Labels, constraint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errCh.SendErrorWithCancel(err, cancel)
|
errCh.SendErrorWithCancel(err, cancel)
|
||||||
return
|
return
|
||||||
@ -254,21 +254,20 @@ func getTPMapMatchingSpreadConstraints(pod *v1.Pod, nodeInfoMap map[string]*sche
|
|||||||
// constraint.TopologyKey is already guaranteed to be present
|
// constraint.TopologyKey is already guaranteed to be present
|
||||||
pair := topologyPair{key: constraint.TopologyKey, value: node.Labels[constraint.TopologyKey]}
|
pair := topologyPair{key: constraint.TopologyKey, value: node.Labels[constraint.TopologyKey]}
|
||||||
nodeTopologyMaps.addTopologyPair(pair, existingPod)
|
nodeTopologyMaps.addTopologyPair(pair, existingPod)
|
||||||
|
pairAdded = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// If needed, append topology pair without entry of pods.
|
||||||
// If needed, append topology pair without entry of pods.
|
// For example, on node-x, there is no pod matching spread constraints,
|
||||||
// For example, on node-x, there is no pod matching spread constraints,
|
// but node-x should be also considered as a match (with match number 0)
|
||||||
// but node-x should be also considered as a match (with match number 0)
|
// i.e. <node: node-x>: {}
|
||||||
// i.e. <node: node-x>: {}
|
if !pairAdded {
|
||||||
for _, constraint := range constraints {
|
pair := topologyPair{
|
||||||
// constraint.TopologyKey is already guaranteed to be present
|
key: constraint.TopologyKey,
|
||||||
pair := topologyPair{
|
value: node.Labels[constraint.TopologyKey],
|
||||||
key: constraint.TopologyKey,
|
}
|
||||||
value: node.Labels[constraint.TopologyKey],
|
nodeTopologyMaps.addTopologyPairWithoutPods(pair)
|
||||||
}
|
}
|
||||||
// addTopologyPairWithoutPods is a non-op if other pods match this pair
|
|
||||||
nodeTopologyMaps.addTopologyPairWithoutPods(pair)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
appendTopologyPairsMaps(nodeTopologyMaps)
|
appendTopologyPairsMaps(nodeTopologyMaps)
|
||||||
|
Loading…
Reference in New Issue
Block a user