From 6bbe817e4b24b374cb073db9de5aa45d5039510d Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 31 Jan 2022 22:56:07 -0500 Subject: [PATCH] fix network sync --- controllers/node_grpc.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/controllers/node_grpc.go b/controllers/node_grpc.go index ba2cd1c5..8172f81b 100644 --- a/controllers/node_grpc.go +++ b/controllers/node_grpc.go @@ -12,6 +12,7 @@ import ( "github.com/gravitl/netmaker/logic" "github.com/gravitl/netmaker/models" "github.com/gravitl/netmaker/servercfg" + "github.com/gravitl/netmaker/serverctl" ) // NodeServiceServer - represents the service server for gRPC @@ -144,15 +145,25 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.Object) } func getServerAddrs(node *models.Node) { - serverNode := logic.GetServerNodes(node.Network)[0] + serverNodes := logic.GetServerNodes(node.Network) //pubIP, _ := servercfg.GetPublicIP() - var serverAddrs = []models.ServerAddr{ - { - IsLeader: true, - Address: serverNode.Address, - ID: serverNode.ID, - }, + if len(serverNodes) == 0 { + if err := serverctl.SyncServerNetwork(node); err != nil { + return + } } + + var serverAddrs = make([]models.ServerAddr, 1) + + for _, node := range serverNodes { + + serverAddrs = append(serverAddrs, models.ServerAddr{ + IsLeader: logic.IsLeader(&node), + Address: node.Address, + ID: node.ID, + }) + } + networkSettings, _ := logic.GetParentNetwork(node.Network) // TODO consolidate functionality around files networkSettings.NodesLastModified = time.Now().Unix()