From 63e8109d317ad04aaff485f9ad1cfa215c5aad33 Mon Sep 17 00:00:00 2001 From: Yury Kulazhenkov Date: Wed, 10 Apr 2024 13:30:38 +0300 Subject: [PATCH] GetOvsPortForContIface should not return error if iface not found 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 --- pkg/ovsdb/ovsdb.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/ovsdb/ovsdb.go b/pkg/ovsdb/ovsdb.go index 767fc3a4..847aa3ff 100644 --- a/pkg/ovsdb/ovsdb.go +++ b/pkg/ovsdb/ovsdb.go @@ -33,6 +33,10 @@ const ( ovsTable = "Open_vSwitch" ) +var ( + errObjectNotFound = errors.New("object not found") +) + // Bridge defines an object in Bridge table type Bridge struct { UUID string `ovsdb:"_uuid"` @@ -631,6 +635,9 @@ func (ovsd *OvsDriver) GetOvsPortForContIface(contIface, contNetnsPath string) ( colums := []string{"name", "external_ids"} port, err := ovsd.findByCondition("Port", condition, colums) if err != nil { + if errors.Is(err, errObjectNotFound) { + return "", false, nil + } return "", false, err } @@ -745,7 +752,7 @@ func (ovsd *OvsDriver) findByCondition(table string, condition ovsdb.Condition, } if len(operationResult.Rows) != 1 { - return nil, fmt.Errorf("failed to find object from table %s", table) + return nil, fmt.Errorf("%w in the table %s", errObjectNotFound, table) } return operationResult.Rows[0], nil