Skip to content

Commit

Permalink
fix lsp not updated correctly when logical switch is changed
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian committed May 14, 2024
1 parent 93e0489 commit 3f51a01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions pkg/ovs/ovn-nb-logical_switch_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/kubevirt/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 3f51a01

Please sign in to comment.