Compare commits

..

7 Commits

Author SHA1 Message Date
amery c84318448c cluster: pre-compute Zone's primary region
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-06-03 00:21:40 +00:00
amery 410a9f8e30 cluster: run initRegions() before scanZoneIDs()
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-06-03 00:19:25 +00:00
amery 1df02f2b2b cluster: assign valid rings.RegionID to each primary region
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-06-03 00:19:23 +00:00
amery 7f849415ca cluster: use rings.ZoneID and rings.NodeID types
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-06-03 00:16:13 +00:00
amery bb40f395d9 rings: fix NodeZeroMax/NodeMax to not accept .255
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-06-03 00:16:08 +00:00
amery f4b837f3e0 rings: add String() to RegionID, ZoneID, NodeID
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-06-03 00:16:00 +00:00
amery d98c879409 build-sys: use revive 1.3.7 instead of master
Signed-off-by: Alejandro Mery <amery@jpi.io>
2024-06-03 00:16:00 +00:00
4 changed files with 44 additions and 19 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ TMPDIR ?= .tmp
REVIVE ?= $(GOBIN)/revive
REVIVE_CONF ?= $(TOOLSDIR)/revive.toml
REVIVE_RUN_ARGS ?= -config $(REVIVE_CONF) -formatter friendly
REVIVE_INSTALL_URL ?= github.com/mgechev/revive@master
REVIVE_VERSION ?= v1.3.7
REVIVE_INSTALL_URL ?= github.com/mgechev/revive@$(REVIVE_VERSION)
GO_INSTALL_URLS = \
$(REVIVE_INSTALL_URL) \
+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 {
+37 -6
View File
@@ -31,7 +31,7 @@ type Region struct {
Regions []string `json:",omitempty" yaml:",omitempty"`
}
// IsPrimary() indicates the region is primary and corresponds
// IsPrimary indicates the region is primary and corresponds
// to a kubernetes cluster.
func (r *Region) IsPrimary() bool {
return r != nil && r.Cluster != nil
@@ -100,7 +100,10 @@ func (m *Cluster) initRegions(_ *ScanOptions) error {
m.finishRegion(r)
}
return m.finishRegions()
m.sortRegions()
m.scanRegionID()
m.computeZonesRegion()
return nil
}
func (m *Cluster) setRegionZones(name string, zones ...*Zone) {
@@ -218,12 +221,12 @@ func (m *Cluster) finishRegion(r *Region) {
r.Regions = sub
}
func (m *Cluster) finishRegions() error {
// revive:disable:cognitive-complexity
func (m *Cluster) scanRegionID() {
// revive:enable:cognitive-complexity
var max rings.RegionID
var missing bool
m.sortRegions()
// check IDs
ids := make(map[rings.RegionID]bool)
fn := func(r *Region) bool {
@@ -273,7 +276,35 @@ func (m *Cluster) finishRegions() error {
m.ForEachRegion(fn)
}
return nil
}
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) {
+1
View File
@@ -19,6 +19,7 @@ type ZoneIterator interface {
// affinity.
type Zone struct {
zones *Cluster
region *Region
logger `json:"-" yaml:"-"`
ID rings.ZoneID