mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Bugfix] Fix Replaced Member Zone during Replace operation (#1491)
This commit is contained in:
parent
28d9d91871
commit
3b0c7cc6b5
3 changed files with 83 additions and 20 deletions
|
@ -11,6 +11,7 @@
|
|||
- (Feature) License ArangoDeployment Fetcher
|
||||
- (Feature) K8S Resources Compare Generic
|
||||
- (Feature) Add support for CRD validation schemas
|
||||
- (Bugfix) Fix Replaced Member Zone during Replace operation
|
||||
|
||||
## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
|
||||
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks
|
||||
|
|
|
@ -27,6 +27,20 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
)
|
||||
|
||||
type TopologyZoneFilter func(g ServerGroup, id string) bool
|
||||
|
||||
func TopologyZoneFilterMerge(functions ...TopologyZoneFilter) TopologyZoneFilter {
|
||||
return func(g ServerGroup, id string) bool {
|
||||
for _, f := range functions {
|
||||
if !f(g, id) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
type TopologyStatus struct {
|
||||
ID types.UID `json:"id"`
|
||||
|
||||
|
@ -53,25 +67,42 @@ func (t *TopologyStatus) Equal(b *TopologyStatus) bool {
|
|||
}
|
||||
|
||||
func (t *TopologyStatus) GetLeastUsedZone(group ServerGroup) int {
|
||||
return t.GetLeastUsedZoneWithFilter(group)
|
||||
}
|
||||
|
||||
func (t *TopologyStatus) GetLeastUsedZoneWithFilter(group ServerGroup, filters ...TopologyZoneFilter) int {
|
||||
if t == nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
r, m := -1, math.MaxInt64
|
||||
// If no zones are found
|
||||
if len(t.Zones) == 0 {
|
||||
return -1
|
||||
}
|
||||
|
||||
for i, z := range t.Zones {
|
||||
if n, ok := z.Members[group.AsRoleAbbreviated()]; ok {
|
||||
if v := len(n); v < m {
|
||||
r, m = i, v
|
||||
}
|
||||
} else {
|
||||
if v := 0; v < m {
|
||||
r, m = i, v
|
||||
counts := make([]int, len(t.Zones))
|
||||
|
||||
for id, zone := range t.Zones {
|
||||
c := 0
|
||||
|
||||
for _, member := range zone.Members[group.AsRoleAbbreviated()] {
|
||||
if TopologyZoneFilterMerge(filters...)(group, member) {
|
||||
c++
|
||||
}
|
||||
}
|
||||
|
||||
counts[id] = c
|
||||
}
|
||||
|
||||
max := 0
|
||||
|
||||
for id := 1; id < len(counts); id++ {
|
||||
if counts[id] < counts[max] {
|
||||
max = id
|
||||
}
|
||||
}
|
||||
|
||||
return r
|
||||
return max
|
||||
}
|
||||
|
||||
func (t *TopologyStatus) RegisterTopologyLabel(zone int, label string) bool {
|
||||
|
|
|
@ -27,6 +27,20 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
)
|
||||
|
||||
type TopologyZoneFilter func(g ServerGroup, id string) bool
|
||||
|
||||
func TopologyZoneFilterMerge(functions ...TopologyZoneFilter) TopologyZoneFilter {
|
||||
return func(g ServerGroup, id string) bool {
|
||||
for _, f := range functions {
|
||||
if !f(g, id) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
type TopologyStatus struct {
|
||||
ID types.UID `json:"id"`
|
||||
|
||||
|
@ -53,25 +67,42 @@ func (t *TopologyStatus) Equal(b *TopologyStatus) bool {
|
|||
}
|
||||
|
||||
func (t *TopologyStatus) GetLeastUsedZone(group ServerGroup) int {
|
||||
return t.GetLeastUsedZoneWithFilter(group)
|
||||
}
|
||||
|
||||
func (t *TopologyStatus) GetLeastUsedZoneWithFilter(group ServerGroup, filters ...TopologyZoneFilter) int {
|
||||
if t == nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
r, m := -1, math.MaxInt64
|
||||
// If no zones are found
|
||||
if len(t.Zones) == 0 {
|
||||
return -1
|
||||
}
|
||||
|
||||
for i, z := range t.Zones {
|
||||
if n, ok := z.Members[group.AsRoleAbbreviated()]; ok {
|
||||
if v := len(n); v < m {
|
||||
r, m = i, v
|
||||
}
|
||||
} else {
|
||||
if v := 0; v < m {
|
||||
r, m = i, v
|
||||
counts := make([]int, len(t.Zones))
|
||||
|
||||
for id, zone := range t.Zones {
|
||||
c := 0
|
||||
|
||||
for _, member := range zone.Members[group.AsRoleAbbreviated()] {
|
||||
if TopologyZoneFilterMerge(filters...)(group, member) {
|
||||
c++
|
||||
}
|
||||
}
|
||||
|
||||
counts[id] = c
|
||||
}
|
||||
|
||||
max := 0
|
||||
|
||||
for id := 1; id < len(counts); id++ {
|
||||
if counts[id] < counts[max] {
|
||||
max = id
|
||||
}
|
||||
}
|
||||
|
||||
return r
|
||||
return max
|
||||
}
|
||||
|
||||
func (t *TopologyStatus) RegisterTopologyLabel(zone int, label string) bool {
|
||||
|
|
Loading…
Reference in a new issue