Skip to content

Commit 96580be

Browse files
committed
fix pg set port fail when lsp is already deleted
1 parent 905b541 commit 96580be

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

pkg/controller/node.go

+21-10
Original file line numberDiff line numberDiff line change
@@ -901,17 +901,23 @@ func (c *Controller) fetchPodsOnNode(nodeName string, pods []*v1.Pod) ([]string,
901901
return ports, nil
902902
}
903903

904-
func (c *Controller) checkPodsChangedOnNode(pgName string, nameIdMap map[string]string, pgPorts, ports []string) (bool, error) {
904+
func (c *Controller) checkPodsChangedOnNode(pgName string, nameIdMap map[string]string, pgPorts, ports []string) (bool, []string, error) {
905+
906+
toAddPorts := make([]string, 0)
905907
for _, port := range ports {
906908
if portId, ok := nameIdMap[port]; ok {
907909
if !util.IsStringIn(portId, pgPorts) {
908-
klog.Infof("pod on node changed, new added port %v should add to node port group %v", port, pgName)
909-
return true, nil
910+
toAddPorts = append(toAddPorts, port)
910911
}
911912
}
912913
}
913914

914-
return false, nil
915+
if len(toAddPorts) != 0 {
916+
klog.Infof("pod on node changed, new added port %v should add to node port group %v", toAddPorts, pgName)
917+
return true, toAddPorts, nil
918+
}
919+
920+
return false, toAddPorts, nil
915921
}
916922

917923
func (c *Controller) CheckNodePortGroup() {
@@ -955,14 +961,14 @@ func (c *Controller) checkAndUpdateNodePortGroup() error {
955961
// The port-group should already created when add node
956962
pgName := strings.Replace(node.Annotations[util.PortNameAnnotation], "-", ".", -1)
957963
nodeIP := node.Annotations[util.IpAddressAnnotation]
958-
964+
var toAddPorts []string
959965
ports, err := c.fetchPodsOnNode(node.Name, pods)
960966
if err != nil {
961967
klog.Errorf("failed to fetch pods for node %v, %v", node.Name, err)
962968
return err
963969
}
964970

965-
changed, err := c.checkPodsChangedOnNode(pgName, nameIdMap, namePortsMap[pgName], ports)
971+
changed, toAddPorts, err := c.checkPodsChangedOnNode(pgName, nameIdMap, namePortsMap[pgName], ports)
966972
if err != nil {
967973
klog.Errorf("failed to check pod status for node %v, %v", node.Name, err)
968974
continue
@@ -979,10 +985,15 @@ func (c *Controller) checkAndUpdateNodePortGroup() error {
979985
}
980986
lastNpExists[node.Name] = networkPolicyExists
981987

982-
err = c.ovnLegacyClient.SetPortsToPortGroup(pgName, ports)
983-
if err != nil {
984-
klog.Errorf("failed to set port group for node %v, %v", node.Name, err)
985-
return err
988+
if len(toAddPorts) != 0 {
989+
c.ovnPgKeyMutex.Lock(pgName)
990+
for _, toAddPort := range toAddPorts {
991+
if err = c.ovnClient.PortGroupAddPort(pgName, toAddPort); err != nil {
992+
c.ovnPgKeyMutex.Unlock(pgName)
993+
return err
994+
}
995+
}
996+
c.ovnPgKeyMutex.Unlock(pgName)
986997
}
987998

988999
if networkPolicyExists {

0 commit comments

Comments
 (0)