Skip to content

Commit

Permalink
fix ovn ic not clean lsp and lrp when az name contains "-" (#3542)
Browse files Browse the repository at this point in the history
* fix ovn ic not clean lsp and lrp when az name contains "-"

Signed-off-by: changluyi <[email protected]>

* fix golint

Signed-off-by: Changlu Yi <[email protected]>

* add comment

Signed-off-by: Changlu Yi <[email protected]>

---------

Signed-off-by: changluyi <[email protected]>
Signed-off-by: Changlu Yi <[email protected]>
  • Loading branch information
changluyi authored Dec 19, 2023
1 parent 65cf9ce commit 2f76694
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/controller/ovn_ic.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,26 @@ func (c *Controller) removeInterConnection(azName string) error {

if azName != "" {
if err := c.OVNNbClient.DeleteLogicalSwitchPorts(nil, func(lsp *ovnnb.LogicalSwitchPort) bool {
names := strings.Split(lsp.Name, "-")
return len(names) == 2 && names[1] == azName && strings.HasPrefix(names[0], "ts")
// add the code below because azName may have multi "-"
firstIndex := strings.Index(lsp.Name, "-")
if firstIndex != -1 {
firstPart := lsp.Name[:firstIndex]
secondPart := lsp.Name[firstIndex+1:]
return secondPart == azName && strings.HasPrefix(firstPart, util.InterconnectionSwitch)
}
return false
}); err != nil {
return err
}

if err := c.OVNNbClient.DeleteLogicalRouterPorts(nil, func(lrp *ovnnb.LogicalRouterPort) bool {
names := strings.Split(lrp.Name, "-")
return len(names) == 2 && names[0] == azName && strings.HasPrefix(names[1], "ts")
lastIndex := strings.LastIndex(lrp.Name, "-")
if lastIndex != -1 {
firstPart := lrp.Name[:lastIndex]
secondPart := lrp.Name[lastIndex+1:]
return firstPart == azName && strings.HasPrefix(secondPart, util.InterconnectionSwitch)
}
return false
}); err != nil {
return err
}
Expand Down

0 comments on commit 2f76694

Please sign in to comment.