-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove lingering nb/sb ctl calls from the code base #2697
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9e12506
Convert OVN Meter + Meter_Band ops to libovsdb
astoycos 95729a6
set NB_Global options with libovsdb
astoycos d47a3fc
Remove final nbctl calls from HO code
astoycos 1b94cbb
Remove final sbctl calls from Hybrid Overlay
astoycos c3472e1
Cleanup OVN package
astoycos c8c1899
Remove some nb/sb ctl helper functions
astoycos cd445c5
Move libovsdbops package
astoycos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
File renamed without changes.
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) | ||
} |
File renamed without changes.
File renamed without changes.
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,73 @@ | ||
package libovsdbops | ||
|
||
import ( | ||
"fmt" | ||
|
||
libovsdbclient "github.com/ovn-org/libovsdb/client" | ||
|
||
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/nbdb" | ||
) | ||
|
||
// CreateLSPOrMutateMac creates a given LSP or mutates its MAC address and adds it to a logical Switch | ||
func CreateLSPOrMutateMac(nbClient libovsdbclient.Client, nodeName, portName, portMAC string) error { | ||
existingNodeSwitch := &nbdb.LogicalSwitch{ | ||
Name: nodeName, | ||
} | ||
|
||
existingLSP := []nbdb.LogicalSwitchPort{} | ||
|
||
newLSP := &nbdb.LogicalSwitchPort{ | ||
Name: portName, | ||
Addresses: []string{portMAC}, | ||
} | ||
|
||
opModels := []OperationModel{ | ||
// For LSP's Name is a valid index, so no predicate is needed | ||
{ | ||
Model: newLSP, | ||
ExistingResult: &existingLSP, | ||
OnModelMutations: []interface{}{ | ||
newLSP.Addresses, | ||
}, | ||
DoAfter: func() { | ||
// Bulkop is false, so we won't get here if len existingLSP > 1 | ||
if len(existingLSP) == 1 { | ||
existingNodeSwitch.Ports = []string{existingLSP[0].UUID} | ||
} else { | ||
existingNodeSwitch.Ports = []string{newLSP.UUID} | ||
} | ||
}, | ||
}, | ||
{ | ||
Model: existingNodeSwitch, | ||
ModelPredicate: func(ls *nbdb.LogicalSwitch) bool { return ls.Name == nodeName }, | ||
OnModelMutations: []interface{}{ | ||
&existingNodeSwitch.Ports, | ||
}, | ||
ErrNotFound: true, | ||
}, | ||
} | ||
|
||
m := NewModelClient(nbClient) | ||
if _, err := m.CreateOrUpdate(opModels...); err != nil { | ||
return fmt.Errorf("failed to create or Mutate LSP %v and add it to Node %s , error: %v", newLSP, nodeName, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// LSPDelete performs an idepotent delete of the LSP provided by it's name | ||
func LSPDelete(nbClient libovsdbclient.Client, LSPName string) error { | ||
opModel := OperationModel{ | ||
Model: &nbdb.LogicalSwitchPort{ | ||
Name: LSPName, | ||
}, | ||
} | ||
|
||
m := NewModelClient(nbClient) | ||
if err := m.Delete(opModel); err != nil { | ||
return fmt.Errorf("failed to delete LSP %s, error: %v", LSPName, 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
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to self: Remove final sbctl calls from Hybrid Overlay commit looks good