Skip to content

Commit fb9f655

Browse files
authored
GetOvsPortForContIface should not return error if iface not found (#305)
Currently the function returns '"",false, err' in case if interface not found. The signature and usage of this function assume that the function should not return and error in case if interface not found. Fix the function to return '"", false, nil' in case if the interface not found. This change fixes CmdDel for scenario when CmdDel is called after failed CmdAdd or when port was manually removed from the ovs. Signed-off-by: Yury Kulazhenkov <[email protected]>
1 parent 7434914 commit fb9f655

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/ovsdb/ovsdb.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const (
3333
ovsTable = "Open_vSwitch"
3434
)
3535

36+
var (
37+
errObjectNotFound = errors.New("object not found")
38+
)
39+
3640
// Bridge defines an object in Bridge table
3741
type Bridge struct {
3842
UUID string `ovsdb:"_uuid"`
@@ -631,6 +635,9 @@ func (ovsd *OvsDriver) GetOvsPortForContIface(contIface, contNetnsPath string) (
631635
colums := []string{"name", "external_ids"}
632636
port, err := ovsd.findByCondition("Port", condition, colums)
633637
if err != nil {
638+
if errors.Is(err, errObjectNotFound) {
639+
return "", false, nil
640+
}
634641
return "", false, err
635642
}
636643

@@ -745,7 +752,7 @@ func (ovsd *OvsDriver) findByCondition(table string, condition ovsdb.Condition,
745752
}
746753

747754
if len(operationResult.Rows) != 1 {
748-
return nil, fmt.Errorf("failed to find object from table %s", table)
755+
return nil, fmt.Errorf("%w in the table %s", errObjectNotFound, table)
749756
}
750757

751758
return operationResult.Rows[0], nil

0 commit comments

Comments
 (0)