Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] [GT-537] Fix Replaced Member Zone during Replace operation #1491

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 41 additions & 10 deletions pkg/apis/deployment/v1/topology_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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 {
Expand Down
51 changes: 41 additions & 10 deletions pkg/apis/deployment/v2alpha1/topology_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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 {
Expand Down