Prechádzať zdrojové kódy

support multiple ext client removal

Abhishek Kondur 2 rokov pred
rodič
commit
2f0b816524
3 zmenil súbory, kde vykonal 17 pridanie a 18 odobranie
  1. 2 2
      controllers/ext_client.go
  2. 1 6
      controllers/node.go
  3. 14 10
      mq/publishers.go

+ 2 - 2
controllers/ext_client.go

@@ -499,7 +499,7 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) {
 		if ingressNode, err := logic.GetNodeByID(newclient.IngressGatewayID); err == nil {
 			if ingressHost, err := logic.GetHost(ingressNode.HostID.String()); err == nil {
 				if replaceOldClient || !update.Enabled {
-					mq.BroadcastDelExtClient(ingressHost, &ingressNode, currentClient)
+					mq.BroadcastDelExtClient(ingressHost, &ingressNode, []models.ExtClient{currentClient})
 				}
 				if replaceOldClient || changedEnabled {
 					// broadcast update
@@ -581,7 +581,7 @@ func deleteExtClient(w http.ResponseWriter, r *http.Request) {
 	go func() {
 		ingressHost, err := logic.GetHost(ingressnode.HostID.String())
 		if err == nil {
-			go mq.BroadcastDelExtClient(ingressHost, &ingressnode, extclient)
+			go mq.BroadcastDelExtClient(ingressHost, &ingressnode, []models.ExtClient{extclient})
 		}
 
 		if err = mq.PublishDeleteExtClientDNS(&extclient); err != nil {

+ 1 - 6
controllers/node.go

@@ -585,12 +585,7 @@ func deleteIngressGateway(w http.ResponseWriter, r *http.Request) {
 	if len(removedClients) > 0 {
 		host, err := logic.GetHost(node.HostID.String())
 		if err == nil {
-			go mq.PublishSingleHostPeerUpdate(
-				context.Background(),
-				host,
-				nil,
-				removedClients[:],
-			)
+			mq.BroadcastDelExtClient(host, &node, removedClients)
 		}
 	}
 

+ 14 - 10
mq/publishers.go

@@ -291,22 +291,26 @@ func BroadcastExtClient(ingressHost *models.Host, ingressNode *models.Node) erro
 }
 
 // BroadcastDelExtClient - published msg to remove ext client from network
-func BroadcastDelExtClient(ingressHost *models.Host, ingressNode *models.Node, extclient models.ExtClient) error {
+func BroadcastDelExtClient(ingressHost *models.Host, ingressNode *models.Node, extclients []models.ExtClient) error {
 	// TODO - send fw update
 	go BroadcastAddOrUpdatePeer(ingressHost, ingressNode, true)
-	extPubKey, err := wgtypes.ParseKey(extclient.PublicKey)
-	if err != nil {
-		return err
+	peers := []wgtypes.PeerConfig{}
+	for _, extclient := range extclients {
+		extPubKey, err := wgtypes.ParseKey(extclient.PublicKey)
+		if err != nil {
+			continue
+		}
+		peers = append(peers, wgtypes.PeerConfig{
+			PublicKey: extPubKey,
+			Remove:    true,
+		})
+
 	}
 	p := models.PeerAction{
 		Action: models.RemovePeer,
-		Peers: []wgtypes.PeerConfig{
-			{
-				PublicKey: extPubKey,
-				Remove:    true,
-			},
-		},
+		Peers:  peers,
 	}
+
 	data, err := json.Marshal(p)
 	if err != nil {
 		return err