Browse Source

cluster: pre-compute Zone's primary region

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/49/head
Alejandro Mery 7 months ago
parent
commit
982e16581c
  1. 16
      pkg/cluster/env.go
  2. 30
      pkg/cluster/regions.go
  3. 1
      pkg/cluster/zones.go

16
pkg/cluster/env.go

@ -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
pkg/cluster/regions.go

@ -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
pkg/cluster/zones.go

@ -19,6 +19,7 @@ type ZoneIterator interface {
// affinity.
type Zone struct {
zones *Cluster
region *Region
logger `json:"-" yaml:"-"`
ID rings.ZoneID

Loading…
Cancel
Save