From 48ece57bbc02a5629986b4378ded3d951c3bb577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nagy=20K=C3=A1roly=20G=C3=A1briel?= Date: Thu, 25 Jul 2024 21:05:47 +0300 Subject: [PATCH] cluster: fix wg1.conf generator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nagy Károly Gábriel --- pkg/cluster/rings.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/cluster/rings.go b/pkg/cluster/rings.go index 161f4a5..64833c6 100644 --- a/pkg/cluster/rings.go +++ b/pkg/cluster/rings.go @@ -225,17 +225,28 @@ func (r *Ring) setRingZeroAllowedIPs(rp *RingPeer) { rp.AllowCIDR(rp.Address, 32) } +// revive:disable:cognitive-complexity func (r *Ring) setRingOneGatewayAllowedIPs(rp *RingPeer) { + // revive:enable:cognitive-complexity regionID, zoneID, _, _ := r.Decode(rp.Address) // peer rp.AllowCIDR(rp.Address, 32) // ring1 gateways connect to all other ring1 networks - r.ForEachZone(func(z *Zone) bool { - if !z.Is(regionID, zoneID) { - subnet := z.RingOnePrefix() - rp.AllowSubnet(subnet) + m, ok := r.ZoneIterator.(RegionIterator) + if !ok { + panic("Cannot iterate Region from Zone") + } + m.ForEachRegion(func(r2 *Region) bool { + if r2.IsPrimary() { + r.ForEachZone(func(z *Zone) bool { + if !z.Is(regionID, zoneID) { + subnet := z.RingOnePrefix() + rp.AllowSubnet(subnet) + } + return false + }) } return false })