Skip to content

Commit c8f7212

Browse files
authored
Merge pull request #1502 from stgraber/ovn
Fix duplicate OVN load-balancer entries
2 parents e14ad3e + cf4fcf1 commit c8f7212

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

internal/server/network/ovn/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ var ErrExists = fmt.Errorf("object already exists")
1212
// ErrNotFound indicates that a DB record doesn't exist.
1313
var ErrNotFound = ovsdbClient.ErrNotFound
1414

15+
// ErrTooMany is returned when one match is expected but multiple are found.
16+
var ErrTooMany = fmt.Errorf("too many objects found")
17+
1518
// ErrNotManaged indicates that a DB record wasn't created by Incus.
1619
var ErrNotManaged = fmt.Errorf("object not incus-managed")

internal/server/network/ovn/ovn_nb.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,14 @@ func (o *NB) get(ctx context.Context, m ovsdbModel.Model) error {
207207
return fmt.Errorf("Bad collection type")
208208
}
209209

210-
if rVal.Len() != 1 {
210+
if rVal.Len() == 0 {
211211
return ovsdbClient.ErrNotFound
212212
}
213213

214+
if rVal.Len() > 1 {
215+
return ErrTooMany
216+
}
217+
214218
reflect.ValueOf(m).Elem().Set(rVal.Index(0))
215219
return nil
216220
}

internal/server/network/ovn/ovn_nb_actions.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,8 +2975,12 @@ func (o *NB) CreateLoadBalancer(ctx context.Context, loadBalancerName OVNLoadBal
29752975
}
29762976

29772977
err := o.get(ctx, &lb)
2978-
if err == nil {
2979-
// Delete the load balancer.
2978+
if err == nil || err == ErrTooMany {
2979+
// Delete the load balancer (by name in case there are duplicates).
2980+
lb := ovnNB.LoadBalancer{
2981+
Name: name,
2982+
}
2983+
29802984
deleteOps, err := o.client.Where(&lb).Delete()
29812985
if err != nil {
29822986
return err

0 commit comments

Comments
 (0)