From 3f51a01edb28dae2799b7c0b33d2a3a18a51d467 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Tue, 14 May 2024 01:48:46 +0000 Subject: [PATCH] fix lsp not updated correctly when logical switch is changed Signed-off-by: zhangzujian --- pkg/ovs/ovn-nb-logical_switch_port.go | 25 +++++++++++++++---------- test/e2e/kubevirt/e2e_test.go | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pkg/ovs/ovn-nb-logical_switch_port.go b/pkg/ovs/ovn-nb-logical_switch_port.go index be082b76a6e7..56c116ea64b4 100644 --- a/pkg/ovs/ovn-nb-logical_switch_port.go +++ b/pkg/ovs/ovn-nb-logical_switch_port.go @@ -89,30 +89,35 @@ func buildLogicalSwitchPort(lspName, lsName, ip, mac, podName, namespace string, } func (c *OVNNbClient) CreateLogicalSwitchPort(lsName, lspName, ip, mac, podName, namespace string, portSecurity bool, securityGroups, vips string, enableDHCP bool, dhcpOptions *DHCPOptionsUUIDs, vpc string) error { - exist, err := c.LogicalSwitchPortExists(lspName) + existingLsp, err := c.GetLogicalSwitchPort(lspName, true) if err != nil { klog.Error(err) return err } - // update if exists - if exist { - lsp := buildLogicalSwitchPort(lspName, lsName, ip, mac, podName, namespace, portSecurity, securityGroups, vips, enableDHCP, dhcpOptions, vpc) - if err := c.UpdateLogicalSwitchPort(lsp, &lsp.Addresses, &lsp.Dhcpv4Options, &lsp.Dhcpv6Options, &lsp.PortSecurity, &lsp.ExternalIDs); err != nil { + var ops []ovsdb.Operation + lsp := buildLogicalSwitchPort(lspName, lsName, ip, mac, podName, namespace, portSecurity, securityGroups, vips, enableDHCP, dhcpOptions, vpc) + if existingLsp != nil { + if lsp.ExternalIDs[logicalSwitchKey] == lsName { + if err := c.UpdateLogicalSwitchPort(lsp, &lsp.Addresses, &lsp.Dhcpv4Options, &lsp.Dhcpv6Options, &lsp.PortSecurity, &lsp.ExternalIDs); err != nil { + klog.Error(err) + return fmt.Errorf("failed to update logical switch port %s: %v", lspName, err) + } + return nil + } + if ops, err = c.LogicalSwitchUpdatePortOp(lsp.ExternalIDs[logicalSwitchKey], existingLsp.UUID, ovsdb.MutateOperationDelete); err != nil { klog.Error(err) - return fmt.Errorf("failed to update logical switch port %s: %v", lspName, err) + return err } - return nil } - lsp := buildLogicalSwitchPort(lspName, lsName, ip, mac, podName, namespace, portSecurity, securityGroups, vips, enableDHCP, dhcpOptions, vpc) - ops, err := c.CreateLogicalSwitchPortOp(lsp, lsName) + createLspOps, err := c.CreateLogicalSwitchPortOp(lsp, lsName) if err != nil { klog.Error(err) return fmt.Errorf("generate operations for creating logical switch port %s: %v", lspName, err) } - if err = c.Transact("lsp-add", ops); err != nil { + if err = c.Transact("lsp-add", append(ops, createLspOps...)); err != nil { return fmt.Errorf("create logical switch port %s: %v", lspName, err) } diff --git a/test/e2e/kubevirt/e2e_test.go b/test/e2e/kubevirt/e2e_test.go index 8bb98bf9f72f..abefab2e3eca 100644 --- a/test/e2e/kubevirt/e2e_test.go +++ b/test/e2e/kubevirt/e2e_test.go @@ -62,7 +62,7 @@ var _ = framework.Describe("[group:kubevirt]", func() { vmClient.DeleteSync(vmName) ginkgo.By("Deleting subnet " + subnetName) - vmClient.DeleteSync(subnetName) + subnetClient.DeleteSync(subnetName) }) framework.ConformanceIt("should be able to keep pod ips after vm pod is deleted", func() {