-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove final sbctl calls from Hybrid Overlay
Remove the final sbctl calls regarding mac_bindings from the hybrid overlay code and convert to libovsdb Ensure we index mac_binding by both possible options, the `logical_port` OR `ip` columns Signed-off-by: astoycos <[email protected]>
- Loading branch information
astoycos
committed
Dec 8, 2021
1 parent
0b5350f
commit 1a290c2
Showing
5 changed files
with
92 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package libovsdbops | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
libovsdbclient "github.com/ovn-org/libovsdb/client" | ||
|
||
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/sbdb" | ||
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types" | ||
) | ||
|
||
func findDatapathByPredicate(sbClient libovsdbclient.Client, lookupFcn func(dp *sbdb.DatapathBinding) bool) (*sbdb.DatapathBinding, error) { | ||
ctx, cancel := context.WithTimeout(context.Background(), types.OVSDBTimeout) | ||
defer cancel() | ||
datapathBindings := []sbdb.DatapathBinding{} | ||
err := sbClient.WhereCache(lookupFcn).List(ctx, &datapathBindings) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(datapathBindings) != 1 { | ||
return nil, fmt.Errorf("multiple datapath bindings found for a given lookup function") | ||
} | ||
|
||
return &datapathBindings[0], nil | ||
} | ||
|
||
func FindDatapathByExternalIDs(sbClient libovsdbclient.Client, externalIDs map[string]string) (*sbdb.DatapathBinding, error) { | ||
datapathLookupFcn := func(dp *sbdb.DatapathBinding) bool { | ||
datapathMatch := false | ||
for k, v := range externalIDs { | ||
if itemVal, ok := dp.ExternalIDs[k]; ok { | ||
if itemVal == v { | ||
datapathMatch = true | ||
} | ||
} | ||
} | ||
|
||
return datapathMatch | ||
} | ||
|
||
return findDatapathByPredicate(sbClient, datapathLookupFcn) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package libovsdbops | ||
|
||
import ( | ||
libovsdbclient "github.com/ovn-org/libovsdb/client" | ||
|
||
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/sbdb" | ||
) | ||
|
||
// Create or UpdateMacBinding either create a new mac binding or ensure the existing one has the | ||
// correct datapath, logical_port, ip, and mac column entries | ||
func CreateOrUpdateMacBinding(sbClient libovsdbclient.Client, mb *sbdb.MACBinding) error { | ||
opModel := OperationModel{ | ||
// no predicate needed, ip and logical_port columns are indexes | ||
Model: mb, | ||
OnModelUpdates: []interface{}{ | ||
&mb.Datapath, | ||
&mb.LogicalPort, | ||
&mb.IP, | ||
&mb.MAC, | ||
}, | ||
} | ||
|
||
m := NewModelClient(sbClient) | ||
if _, err := m.CreateOrUpdate(opModel); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters