Browse Source

cluster: further remove wg1 support

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/58/head
Alejandro Mery 5 months ago
parent
commit
6e3bb24b36
  1. 43
      pkg/cluster/rings.go
  2. 18
      pkg/cluster/wireguard.go

43
pkg/cluster/rings.go

@ -191,15 +191,7 @@ func (r *Ring) AddPeer(p *Machine) bool {
},
}
switch {
case r.ID == rings.RingZeroID:
r.setRingZeroAllowedIPs(rp)
case p.IsGateway():
r.setRingOneGatewayAllowedIPs(rp)
default:
r.setRingOneNodeAllowedIPs(rp)
}
r.setRingZeroAllowedIPs(rp)
r.Peers = append(r.Peers, rp)
return true
}
@ -215,39 +207,6 @@ func (r *Ring) setRingZeroAllowedIPs(rp *RingPeer) {
rp.AllowCIDR(rp.Address, 32)
}
func (r *Ring) setRingOneGatewayAllowedIPs(rp *RingPeer) {
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)
}
return false
})
// ring1 gateways also connect to all ring0 addresses
r.ForEachZone(func(z *Zone) bool {
z.ForEachMachine(func(p *Machine) bool {
if p.IsGateway() {
addr, _ := p.RingZeroAddress()
rp.AllowCIDR(addr, 32)
}
return false
})
return false
})
}
func (*Ring) setRingOneNodeAllowedIPs(rp *RingPeer) {
// only to the peer itself
rp.AllowCIDR(rp.Address, 32)
}
// ForEachMachine calls a function for each Machine in the ring
// until instructed to terminate the loop
func (r *Ring) ForEachMachine(fn func(*Machine) bool) {

18
pkg/cluster/wireguard.go

@ -82,13 +82,6 @@ func (m *Cluster) WriteWireguardConfig(ring rings.RingID) error {
switch ring {
case rings.RingZeroID:
return writeWireguardConfig(m, m, ring)
case rings.RingOneID:
var err error
m.ForEachZone(func(z *Zone) bool {
err = writeWireguardConfig(m, z, ring)
return err != nil
})
return err
default:
return ErrInvalidRing(ring)
}
@ -100,8 +93,6 @@ func (z *Zone) WriteWireguardConfig(ring rings.RingID) error {
switch ring {
case rings.RingZeroID:
return writeWireguardConfig(z.zones, z.zones, ring)
case rings.RingOneID:
return writeWireguardConfig(z.zones, z, ring)
default:
return ErrInvalidRing(ring)
}
@ -165,13 +156,6 @@ func (m *Cluster) SyncWireguardConfig(ring rings.RingID) error {
switch ring {
case rings.RingZeroID:
return syncWireguardConfig(m, m, ring)
case rings.RingOneID:
var err error
m.ForEachZone(func(z *Zone) bool {
err = syncWireguardConfig(m, z, ring)
return err != nil
})
return err
default:
return ErrInvalidRing(ring)
}
@ -183,8 +167,6 @@ func (z *Zone) SyncWireguardConfig(ring rings.RingID) error {
switch ring {
case rings.RingZeroID:
return syncWireguardConfig(z.zones, z.zones, ring)
case rings.RingOneID:
return syncWireguardConfig(z.zones, z, ring)
default:
return ErrInvalidRing(ring)
}

Loading…
Cancel
Save