Skip to content

Commit

Permalink
Merge pull request #1502 from stgraber/ovn
Browse files Browse the repository at this point in the history
Fix duplicate OVN load-balancer entries
  • Loading branch information
hallyn authored Dec 13, 2024
2 parents e14ad3e + cf4fcf1 commit c8f7212
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions internal/server/network/ovn/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ var ErrExists = fmt.Errorf("object already exists")
// ErrNotFound indicates that a DB record doesn't exist.
var ErrNotFound = ovsdbClient.ErrNotFound

// ErrTooMany is returned when one match is expected but multiple are found.
var ErrTooMany = fmt.Errorf("too many objects found")

// ErrNotManaged indicates that a DB record wasn't created by Incus.
var ErrNotManaged = fmt.Errorf("object not incus-managed")
6 changes: 5 additions & 1 deletion internal/server/network/ovn/ovn_nb.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,14 @@ func (o *NB) get(ctx context.Context, m ovsdbModel.Model) error {
return fmt.Errorf("Bad collection type")
}

if rVal.Len() != 1 {
if rVal.Len() == 0 {
return ovsdbClient.ErrNotFound
}

if rVal.Len() > 1 {
return ErrTooMany
}

reflect.ValueOf(m).Elem().Set(rVal.Index(0))
return nil
}
8 changes: 6 additions & 2 deletions internal/server/network/ovn/ovn_nb_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2975,8 +2975,12 @@ func (o *NB) CreateLoadBalancer(ctx context.Context, loadBalancerName OVNLoadBal
}

err := o.get(ctx, &lb)
if err == nil {
// Delete the load balancer.
if err == nil || err == ErrTooMany {
// Delete the load balancer (by name in case there are duplicates).
lb := ovnNB.LoadBalancer{
Name: name,
}

deleteOps, err := o.client.Where(&lb).Delete()
if err != nil {
return err
Expand Down

0 comments on commit c8f7212

Please sign in to comment.