cluster: pre-compute Zone's primary region

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2024-06-03 00:14:53 +00:00
parent cede95e119
commit 982e16581c
3 changed files with 35 additions and 12 deletions
+4 -12
View File
@@ -163,18 +163,10 @@ func genEnvZoneNodes(z *Zone) string {
}
func genEnvZoneRegion(z *Zone) string {
var region string
z.ForEachRegion(func(r *Region) bool {
if r.IsPrimary() {
region = r.Name
return true
}
return false
})
return region
if z != nil && z.region != nil {
return z.region.Name
}
return ""
}
func genEnvZoneCephMonNames(m Machines) string {
+30
View File
@@ -102,6 +102,7 @@ func (m *Cluster) initRegions(_ *ScanOptions) error {
m.sortRegions()
m.scanRegionID()
m.computeZonesRegion()
return nil
}
@@ -277,6 +278,35 @@ func (m *Cluster) scanRegionID() {
}
}
func (m *Cluster) computeZonesRegion() {
fn := func(r *Region, z *Zone) {
if z.region != nil {
m.error(nil).
WithField("zone", z.Name).
WithField("region", []string{
z.region.Name,
r.Name,
}).
Print("zone in two regions")
} else {
z.region = r
}
}
m.ForEachRegion(func(r *Region) bool {
var term bool
if r.IsPrimary() {
r.ForEachZone(func(z *Zone) bool {
fn(r, z)
return term
})
}
return term
})
}
func (m *Cluster) getRegion(name string) (*Region, bool) {
for i := range m.Regions {
r := &m.Regions[i]
+1
View File
@@ -19,6 +19,7 @@ type ZoneIterator interface {
// affinity.
type Zone struct {
zones *Cluster
region *Region
logger `json:"-" yaml:"-"`
ID rings.ZoneID