Skip to content

Commit

Permalink
libovsdbops: add FindSwitchByName rename findSwitch
Browse files Browse the repository at this point in the history
findSwitch only sets the UUID in the provided parameter.
So, renaming it to findSwitchUUID

Signed-off-by: Flavio Fernandes <flaviof@redhat.com>
  • Loading branch information
flavio-fernandes committed Jan 31, 2022
1 parent 4e9e424 commit d92eab2
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions go-controller/pkg/libovsdbops/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
)

// findSwitch looks up the switch in the cache and sets the UUID
func findSwitch(nbClient libovsdbclient.Client, lswitch *nbdb.LogicalSwitch) error {
// findSwitchUUID looks up the switch in the cache and sets the UUID
func findSwitchUUID(nbClient libovsdbclient.Client, lswitch *nbdb.LogicalSwitch) error {
if lswitch.UUID != "" && !IsNamedUUID(lswitch.UUID) {
return nil
}
Expand Down Expand Up @@ -119,6 +119,24 @@ func FindAllNodeLocalSwitches(nbClient libovsdbclient.Client) ([]nbdb.LogicalSwi
return switches, nil
}

// FindSwitchByName finds switch with provided name. If more than one is found, it will error.
func FindSwitchByName(nbClient libovsdbclient.Client, name string) (*nbdb.LogicalSwitch, error) {
nameSearch := func(item *nbdb.LogicalSwitch) bool {
return item.Name == name
}

switches, err := findSwitchesByPredicate(nbClient, nameSearch)
if err != nil {
return nil, err
}

if len(switches) > 1 {
return nil, fmt.Errorf("unexpectedly found multiple switches with same name: %+v", switches)
}

return &switches[0], nil
}

func AddLoadBalancersToSwitchOps(nbClient libovsdbclient.Client, ops []libovsdb.Operation, lswitch *nbdb.LogicalSwitch, lbs ...*nbdb.LoadBalancer) ([]libovsdb.Operation, error) {
if ops == nil {
ops = []libovsdb.Operation{}
Expand All @@ -127,7 +145,7 @@ func AddLoadBalancersToSwitchOps(nbClient libovsdbclient.Client, ops []libovsdb.
return ops, nil
}

err := findSwitch(nbClient, lswitch)
err := findSwitchUUID(nbClient, lswitch)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -157,7 +175,7 @@ func RemoveLoadBalancersFromSwitchOps(nbClient libovsdbclient.Client, ops []libo
return ops, nil
}

err := findSwitch(nbClient, lswitch)
err := findSwitchUUID(nbClient, lswitch)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d92eab2

Please sign in to comment.