From 2f76694f8d4d53d6189236267c6575a6602bf32d Mon Sep 17 00:00:00 2001 From: changluyi <47097611+changluyi@users.noreply.github.com> Date: Tue, 19 Dec 2023 12:01:29 +0800 Subject: [PATCH] fix ovn ic not clean lsp and lrp when az name contains "-" (#3542) * fix ovn ic not clean lsp and lrp when az name contains "-" Signed-off-by: changluyi * fix golint Signed-off-by: Changlu Yi * add comment Signed-off-by: Changlu Yi --------- Signed-off-by: changluyi Signed-off-by: Changlu Yi --- pkg/controller/ovn_ic.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/controller/ovn_ic.go b/pkg/controller/ovn_ic.go index 1e59785dde3..64c54b06531 100644 --- a/pkg/controller/ovn_ic.go +++ b/pkg/controller/ovn_ic.go @@ -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 }