Skip to content

Commit

Permalink
fix: not update lsp into another ls
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 committed Dec 4, 2024
1 parent e642eef commit 7e7adaf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pkg/ovs/ovn-nb-logical_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ func (c *OVNNbClient) LogicalSwitchUpdatePortOp(lsName, lspUUID string, op ovsdb
return nil, nil
}

if lsName == "" && op == ovsdb.MutateOperationDelete {
if op == ovsdb.MutateOperationDelete {
// given ls for deleting lsp is not always real
lsList, err := c.ListLogicalSwitch(false, func(ls *ovnnb.LogicalSwitch) bool {
return slices.Contains(ls.Ports, lspUUID)
})
Expand Down
9 changes: 7 additions & 2 deletions pkg/ovs/ovn-nb-logical_switch_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@ func (c *OVNNbClient) CreateLogicalSwitchPort(lsName, lspName, ip, mac, podName,
return fmt.Errorf("failed to update logical switch port %s: %w", lspName, err)
}
return nil
}
if ops, err = c.LogicalSwitchUpdatePortOp(existingLsp.ExternalIDs[logicalSwitchKey], existingLsp.UUID, ovsdb.MutateOperationDelete); err != nil {
} else {

Check failure on line 108 in pkg/ovs/ovn-nb-logical_switch_port.go

View workflow job for this annotation

GitHub Actions / Build kube-ovn

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
// delete lsp from the old logical switch
err := fmt.Errorf("logical switch port %s already exists in old logical switch %s, delete it", lspName, existingLsp.ExternalIDs[logicalSwitchKey])
klog.Error(err)
if err := c.DeleteLogicalSwitchPort(lspName); err != nil {
klog.Error(err)
}
// enqueue to re-create lsp in the new logical switch
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ovs/ovn-nb-logical_switch_port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() {
err = nbClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, vips, true, dhcpUUIDs, vpcName)
require.NoError(t, err)
err = nbClient.CreateLogicalSwitchPort(lsName2, lspName, ips, mac, podName, podNamespace, true, sgs, vips, true, dhcpUUIDs, vpcName)
require.NoError(t, err)
require.Error(t, err)
})

t.Run("failed client create logical switch port op error", func(t *testing.T) {
Expand Down

0 comments on commit 7e7adaf

Please sign in to comment.