mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
fix planner loop ends before finishing replica assignments
This commit is contained in:
parent
295b4eee80
commit
8b720ffaeb
@ -18,7 +18,6 @@ package planer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"math"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
fed_api "k8s.io/kubernetes/federation/apis/federation"
|
fed_api "k8s.io/kubernetes/federation/apis/federation"
|
||||||
@ -152,9 +151,7 @@ func (p *Planner) Plan(replicasToDistribute int64, availableClusters []string, c
|
|||||||
// TODO: Prove that clusterCount * log(replicas) iterations solves the problem or adjust the number.
|
// TODO: Prove that clusterCount * log(replicas) iterations solves the problem or adjust the number.
|
||||||
// TODO: This algorithm is O(clusterCount^2 * log(replicas)) which is good for up to 100 clusters.
|
// TODO: This algorithm is O(clusterCount^2 * log(replicas)) which is good for up to 100 clusters.
|
||||||
// Find something faster.
|
// Find something faster.
|
||||||
replicasAtStart := remainingReplicas
|
for trial := 0; modified && remainingReplicas > 0; trial++ {
|
||||||
for trial := 0; trial < int(2*(1+math.Log(float64(replicasAtStart)))*float64(len(availableClusters))) &&
|
|
||||||
modified && remainingReplicas > 0; trial++ {
|
|
||||||
|
|
||||||
modified = false
|
modified = false
|
||||||
weightSum := int64(0)
|
weightSum := int64(0)
|
||||||
|
@ -109,6 +109,42 @@ func TestEqualWithExisting(t *testing.T) {
|
|||||||
map[string]int64{"A": 30},
|
map[string]int64{"A": 30},
|
||||||
map[string]int64{"A": 30, "B": 20})
|
map[string]int64{"A": 30, "B": 20})
|
||||||
|
|
||||||
|
doCheckWithExisting(t, map[string]fed_api.ClusterReplicaSetPreferences{
|
||||||
|
"*": {Weight: 1}},
|
||||||
|
15, []string{"A", "B"},
|
||||||
|
map[string]int64{"A": 0, "B": 8},
|
||||||
|
map[string]int64{"A": 7, "B": 8})
|
||||||
|
|
||||||
|
doCheckWithExisting(t, map[string]fed_api.ClusterReplicaSetPreferences{
|
||||||
|
"*": {Weight: 1}},
|
||||||
|
15, []string{"A", "B"},
|
||||||
|
map[string]int64{"A": 1, "B": 8},
|
||||||
|
map[string]int64{"A": 7, "B": 8})
|
||||||
|
|
||||||
|
doCheckWithExisting(t, map[string]fed_api.ClusterReplicaSetPreferences{
|
||||||
|
"*": {Weight: 1}},
|
||||||
|
15, []string{"A", "B"},
|
||||||
|
map[string]int64{"A": 4, "B": 8},
|
||||||
|
map[string]int64{"A": 7, "B": 8})
|
||||||
|
|
||||||
|
doCheckWithExisting(t, map[string]fed_api.ClusterReplicaSetPreferences{
|
||||||
|
"*": {Weight: 1}},
|
||||||
|
15, []string{"A", "B"},
|
||||||
|
map[string]int64{"A": 5, "B": 8},
|
||||||
|
map[string]int64{"A": 7, "B": 8})
|
||||||
|
|
||||||
|
doCheckWithExisting(t, map[string]fed_api.ClusterReplicaSetPreferences{
|
||||||
|
"*": {Weight: 1}},
|
||||||
|
15, []string{"A", "B"},
|
||||||
|
map[string]int64{"A": 6, "B": 8},
|
||||||
|
map[string]int64{"A": 7, "B": 8})
|
||||||
|
|
||||||
|
doCheckWithExisting(t, map[string]fed_api.ClusterReplicaSetPreferences{
|
||||||
|
"*": {Weight: 1}},
|
||||||
|
15, []string{"A", "B"},
|
||||||
|
map[string]int64{"A": 7, "B": 8},
|
||||||
|
map[string]int64{"A": 7, "B": 8})
|
||||||
|
|
||||||
doCheckWithExisting(t, map[string]fed_api.ClusterReplicaSetPreferences{
|
doCheckWithExisting(t, map[string]fed_api.ClusterReplicaSetPreferences{
|
||||||
"*": {Weight: 1}},
|
"*": {Weight: 1}},
|
||||||
500000, []string{"A", "B"},
|
500000, []string{"A", "B"},
|
||||||
|
Loading…
Reference in New Issue
Block a user