mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
fix network peer configuration when just joining the cluster before store is synced
This commit is contained in:
@@ -242,9 +242,13 @@ func (nc *networkController) handleMachineChanges(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
slog.Info("Subscribed to machine changes in the cluster to reconfigure network peers.")
|
slog.Info("Subscribed to machine changes in the cluster to reconfigure network peers.")
|
||||||
|
|
||||||
slog.Info("Reconfiguring network peers with the current machines.", "machines", len(machines))
|
// The machine store may be empty when a machine first joins the cluster, before store synchronization
|
||||||
if err = nc.configurePeers(machines); err != nil {
|
// completes. Skip configuration now and apply it when the store changes are received.
|
||||||
slog.Error("Failed to configure peers.", "err", err)
|
if len(machines) > 0 {
|
||||||
|
slog.Info("Reconfiguring network peers with the current machines.", "machines", len(machines))
|
||||||
|
if err = nc.configurePeers(machines); err != nil {
|
||||||
|
slog.Error("Failed to configure peers.", "err", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// For simplicity, reconfigure all peers on any change.
|
// For simplicity, reconfigure all peers on any change.
|
||||||
for {
|
for {
|
||||||
@@ -269,6 +273,10 @@ func (nc *networkController) handleMachineChanges(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nc *networkController) configurePeers(machines []*pb.MachineInfo) error {
|
func (nc *networkController) configurePeers(machines []*pb.MachineInfo) error {
|
||||||
|
if len(machines) == 0 {
|
||||||
|
return fmt.Errorf("no machines to configure peers")
|
||||||
|
}
|
||||||
|
|
||||||
nc.state.mu.RLock()
|
nc.state.mu.RLock()
|
||||||
currentPeerEndpoints := make(map[string]*netip.AddrPort, len(nc.state.Network.Peers))
|
currentPeerEndpoints := make(map[string]*netip.AddrPort, len(nc.state.Network.Peers))
|
||||||
for _, p := range nc.state.Network.Peers {
|
for _, p := range nc.state.Network.Peers {
|
||||||
|
|||||||
Reference in New Issue
Block a user