Browse Source

cluster: add recursive RegionIterator to Zone

Signed-off-by: Alejandro Mery <amery@jpi.io>
Alejandro Mery 9 months ago
parent
commit
32c1cc3384
  1. 23
      pkg/cluster/regions.go

23
pkg/cluster/regions.go

@ -9,6 +9,7 @@ var (
_ MachineIterator = (*Region)(nil)
_ ZoneIterator = (*Region)(nil)
_ RegionIterator = (*Zone)(nil)
_ RegionIterator = (*Cluster)(nil)
)
@ -131,6 +132,28 @@ func (m *Cluster) appendRegionRegions(name string, subs ...string) {
})
}
// ForEachRegion calls a function on all regions this zone belongs to.
func (z *Zone) ForEachRegion(fn func(*Region) bool) {
if fn == nil {
return
}
z.zones.ForEachRegion(func(r *Region) bool {
var match bool
r.ForEachZone(func(z2 *Zone) bool {
match = (z == z2)
return match
})
if match && fn(r) {
return true
}
return false
})
}
func (z *Zone) appendRegions(regions ...string) error {
for _, s := range regions {
// TODO: validate

Loading…
Cancel
Save