Browse Source

cluster: allow empty wgN.conf files as markers to enable the ring

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/31/head
Alejandro Mery 1 year ago
parent
commit
543824a54a
  1. 12
      pkg/cluster/machine_rings.go
  2. 2
      pkg/wireguard/config.go

12
pkg/cluster/machine_rings.go

@ -118,8 +118,9 @@ func (m *Machine) tryApplyWireguardConfig(ring int) error {
} }
} }
func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error { func (m *Machine) applyWireguardConfigNode(ring int, wg *wireguard.Config) error {
addr := wg.GetAddress() addr := wg.GetAddress()
if !core.IsZero(addr) {
zoneID, nodeID, ok := Rings[ring].Decode(addr) zoneID, nodeID, ok := Rings[ring].Decode(addr)
if !ok { if !ok {
return fmt.Errorf("%s: invalid address", addr) return fmt.Errorf("%s: invalid address", addr)
@ -128,11 +129,20 @@ func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error {
if err := m.applyZoneNodeID(zoneID, nodeID); err != nil { if err := m.applyZoneNodeID(zoneID, nodeID); err != nil {
return core.Wrap(err, "%s: invalid address", addr) return core.Wrap(err, "%s: invalid address", addr)
} }
}
if err := m.applyWireguardInterfaceConfig(ring, wg.Interface); err != nil { if err := m.applyWireguardInterfaceConfig(ring, wg.Interface); err != nil {
return core.Wrap(err, "interface") return core.Wrap(err, "interface")
} }
return nil
}
func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error {
if err := m.applyWireguardConfigNode(ring, wg); err != nil {
return err
}
for _, peer := range wg.Peer { for _, peer := range wg.Peer {
err := m.applyWireguardPeerConfig(ring, peer) err := m.applyWireguardPeerConfig(ring, peer)
switch { switch {

2
pkg/wireguard/config.go

@ -175,11 +175,13 @@ func (p interfaceConfig) Export() (InterfaceConfig, error) {
ListenPort: p.ListenPort, ListenPort: p.ListenPort,
} }
if p.PrivateKey != "" {
out.PrivateKey, err = PrivateKeyFromBase64(p.PrivateKey) out.PrivateKey, err = PrivateKeyFromBase64(p.PrivateKey)
if err != nil { if err != nil {
err = core.Wrap(err, "PrivateKey") err = core.Wrap(err, "PrivateKey")
return InterfaceConfig{}, err return InterfaceConfig{}, err
} }
}
return out, nil return out, nil
} }

Loading…
Cancel
Save