Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions go-controller/pkg/libovsdb/libovsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ func NewNBClientWithConfig(cfg config.OvnAuthConfig, promRegistry prometheus.Reg
enableMetricsOption := client.WithMetricsRegistryNamespaceSubsystem(promRegistry, "ovnkube",
"master_libovsdb")

// define client indexes for objects that are using dbIDs
dbModel.SetIndexes(map[string][]model.ClientIndex{
nbdb.LoadBalancerTable: {{Columns: []model.ColumnKey{{Column: "name"}}}},
})

c, err := newClient(cfg, dbModel, stopCh, enableMetricsOption)
if err != nil {
return nil, err
Expand Down
29 changes: 3 additions & 26 deletions go-controller/pkg/libovsdbops/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,6 @@ func BuildLoadBalancer(name string, protocol nbdb.LoadBalancerProtocol, vips, op
}
}

// CreateLoadBalancersOps creates the provided load balancers returning the
// corresponding ops
func CreateLoadBalancersOps(nbClient libovsdbclient.Client, ops []libovsdb.Operation, lbs ...*nbdb.LoadBalancer) ([]libovsdb.Operation, error) {
opModels := make([]operationModel, 0, len(lbs))
for i := range lbs {
lb := lbs[i]
opModel := operationModel{
Model: lb,
OnModelUpdates: onModelUpdatesNone(),
ErrNotFound: false,
BulkOp: false,
}
opModels = append(opModels, opModel)
}

modelClient := newModelClient(nbClient)
return modelClient.CreateOrUpdateOps(ops, opModels...)
}

// CreateOrUpdateLoadBalancersOps creates or updates the provided load balancers
// returning the corresponding ops
func CreateOrUpdateLoadBalancersOps(nbClient libovsdbclient.Client, ops []libovsdb.Operation, lbs ...*nbdb.LoadBalancer) ([]libovsdb.Operation, error) {
Expand All @@ -85,7 +66,6 @@ func CreateOrUpdateLoadBalancersOps(nbClient libovsdbclient.Client, ops []libovs
lb := lbs[i]
opModel := operationModel{
Model: lb,
ModelPredicate: func(item *nbdb.LoadBalancer) bool { return item.Name == lb.Name },
OnModelUpdates: getNonZeroLoadBalancerMutableFields(lb),
ErrNotFound: false,
BulkOp: false,
Expand All @@ -107,7 +87,6 @@ func RemoveLoadBalancerVipsOps(nbClient libovsdbclient.Client, ops []libovsdb.Op
}
opModel := operationModel{
Model: lb,
ModelPredicate: func(item *nbdb.LoadBalancer) bool { return item.Name == lb.Name },
OnModelMutations: []interface{}{&lb.Vips},
ErrNotFound: true,
BulkOp: false,
Expand All @@ -127,11 +106,9 @@ func DeleteLoadBalancersOps(nbClient libovsdbclient.Client, ops []libovsdb.Opera
// can't use i in the predicate, for loop replaces it in-memory
lb := lbs[i]
opModel := operationModel{
Model: lb,
// TODO: remove UUID match from predicate once model_client prioritizes indexed search over predicate
ModelPredicate: func(item *nbdb.LoadBalancer) bool { return item.UUID == lb.UUID || item.Name == lb.Name },
ErrNotFound: false,
BulkOp: false,
Model: lb,
ErrNotFound: false,
BulkOp: false,
}
opModels = append(opModels, opModel)
}
Expand Down
5 changes: 2 additions & 3 deletions go-controller/pkg/libovsdbops/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func copyIndexes(model model.Model) model.Model {
case *nbdb.LoadBalancer:
return &nbdb.LoadBalancer{
UUID: t.UUID,
// client index
Name: t.Name,
}
case *nbdb.LoadBalancerGroup:
return &nbdb.LoadBalancerGroup{
Expand Down Expand Up @@ -362,9 +364,6 @@ func buildFailOnDuplicateOps(c client.Client, m model.Model) ([]ovsdb.Operation,
var field interface{}
var value string
switch t := m.(type) {
case *nbdb.LoadBalancer:
field = &t.Name
value = t.Name
case *nbdb.LogicalRouter:
field = &t.Name
value = t.Name
Expand Down
13 changes: 1 addition & 12 deletions go-controller/pkg/ovn/controller/services/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ func EnsureLBs(nbClient libovsdbclient.Client, service *corev1.Service, existing
}

lbs := make([]*nbdb.LoadBalancer, 0, len(LBs))
existinglbs := make([]*nbdb.LoadBalancer, 0, len(LBs))
newlbs := make([]*nbdb.LoadBalancer, 0, len(LBs))
addLBsToSwitch := map[string][]*nbdb.LoadBalancer{}
removeLBsFromSwitch := map[string][]*nbdb.LoadBalancer{}
addLBsToRouter := map[string][]*nbdb.LoadBalancer{}
Expand All @@ -117,13 +115,10 @@ func EnsureLBs(nbClient libovsdbclient.Client, service *corev1.Service, existing
existingGroups := sets.Set[string]{}
if existingLB != nil {
blb.UUID = existingLB.UUID
existinglbs = append(existinglbs, blb)
toDelete.Delete(existingLB.UUID)
existingRouters = sets.New[string](existingLB.Routers...)
existingSwitches = sets.New[string](existingLB.Switches...)
existingGroups = sets.New[string](existingLB.Groups...)
} else {
newlbs = append(newlbs, blb)
}
wantRouters := sets.New(lb.Routers...)
wantSwitches := sets.New(lb.Switches...)
Expand All @@ -136,18 +131,12 @@ func EnsureLBs(nbClient libovsdbclient.Client, service *corev1.Service, existing
mapLBDifferenceByKey(removeLBsFromGroups, existingGroups, wantGroups, blb)
}

ops, err := libovsdbops.CreateOrUpdateLoadBalancersOps(nbClient, nil, existinglbs...)
ops, err := libovsdbops.CreateOrUpdateLoadBalancersOps(nbClient, nil, lbs...)
if err != nil {
return fmt.Errorf("failed to create ops for ensuring update of service %s/%s load balancers: %w",
service.Namespace, service.Name, err)
}

ops, err = libovsdbops.CreateLoadBalancersOps(nbClient, ops, newlbs...)
if err != nil {
return fmt.Errorf("failed to create ops for ensuring creation of service %s/%s load balancers: %w",
service.Namespace, service.Name, err)
}

// cache switches for this round of ops
lswitches := map[string]*nbdb.LogicalSwitch{}
getSwitch := func(name string) *nbdb.LogicalSwitch {
Expand Down