Skip to content

Commit

Permalink
Perform repair across all networks
Browse files Browse the repository at this point in the history
Signed-off-by: Surya Seetharaman <[email protected]>
  • Loading branch information
tssurya committed Jan 6, 2025
1 parent b3dc386 commit 23a1356
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions go-controller/pkg/ovn/controller/admin_network_policy/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ func (c *Controller) repairAdminNetworkPolicies() error {
// We grab all the port groups that belong to ANP controller using externalIDs
// and compare the value with the name of existing ANPs. If no match is found
// we delete that port group along with all the acls in it.
predicateIDs := libovsdbops.NewDbObjectIDs(libovsdbops.PortGroupAdminNetworkPolicy, c.controllerName, nil)
p := libovsdbops.GetPredicate[*nbdb.PortGroup](predicateIDs, func(pg *nbdb.PortGroup) bool {
// This is done for all networks in the cluster
predicateIDs := libovsdbops.NewDbObjectIDsAcrossAllContollers(libovsdbops.PortGroupAdminNetworkPolicy, nil)
p := libovsdbops.GetPredicateAcrossAllControllers[*nbdb.PortGroup](predicateIDs, func(pg *nbdb.PortGroup) bool {
_, ok := existingANPs[pg.ExternalIDs[libovsdbops.ObjectNameKey.String()]]
return !ok // return if it doesn't exist in the cache
})
Expand All @@ -60,16 +61,16 @@ func (c *Controller) repairAdminNetworkPolicies() error {
}
// Deal with Address-Sets Repairs
// We grab all the AddressSets that belong to ANP controller using externalIDs
// and compare with the existing ANPs. The ones that don't match
// across all networks and compare with the existing ANPs. The ones that don't match
// will be deleted from the DB.
// NOTE: When we call syncAdminNetworkPolicy function after this for every ANP on startup,
// the right Address-sets will be recreated.
asPredicateIDs := libovsdbops.NewDbObjectIDs(libovsdbops.AddressSetAdminNetworkPolicy, c.controllerName, nil)
asPredicateIDs := libovsdbops.NewDbObjectIDsAcrossAllContollers(libovsdbops.AddressSetAdminNetworkPolicy, nil)
asPredicateFunc := func(as *nbdb.AddressSet) bool {
_, ok := existingANPs[as.ExternalIDs[libovsdbops.ObjectNameKey.String()]]
return !ok // if not present in cache then its stale
}
asPredicate := libovsdbops.GetPredicate[*nbdb.AddressSet](asPredicateIDs, asPredicateFunc)
asPredicate := libovsdbops.GetPredicateAcrossAllControllers[*nbdb.AddressSet](asPredicateIDs, asPredicateFunc)
if err := libovsdbops.DeleteAddressSetsWithPredicate(c.nbClient, asPredicate); err != nil {
return fmt.Errorf("failed to remove stale ANP address sets, err: %v", err)
}
Expand Down Expand Up @@ -105,8 +106,9 @@ func (c *Controller) repairBaselineAdminNetworkPolicy() error {
// We grab all the port groups that belong to BANP controller using externalIDs
// and compare the value with the name of existing BANPs. If no match is found
// we delete that port group along with all the acls in it.
predicateIDs := libovsdbops.NewDbObjectIDs(libovsdbops.PortGroupBaselineAdminNetworkPolicy, c.controllerName, nil)
p := libovsdbops.GetPredicate[*nbdb.PortGroup](predicateIDs, func(pg *nbdb.PortGroup) bool {
// This is done for all networks in the cluster
predicateIDs := libovsdbops.NewDbObjectIDsAcrossAllContollers(libovsdbops.PortGroupBaselineAdminNetworkPolicy, nil)
p := libovsdbops.GetPredicateAcrossAllControllers[*nbdb.PortGroup](predicateIDs, func(pg *nbdb.PortGroup) bool {
_, ok := existingBANPs[pg.ExternalIDs[libovsdbops.ObjectNameKey.String()]]
return !ok // return if it doesn't exist in the cache
})
Expand All @@ -124,17 +126,17 @@ func (c *Controller) repairBaselineAdminNetworkPolicy() error {
}
// Deal with Address-Sets Repairs
// We grab all the AddressSets that belong to BANP controller using externalIDs
// and compare with the existing ANPs. The ones that don't match
// across all networks and compare with the existing ANPs. The ones that don't match
// will be deleted from the DB.
// NOTE: When we call syncBaselineAdminNetworkPolicy function after this for every BANP on startup,
// the right Address-sets will be recreated.
// Since we clean ACLs before Address-sets we should not run into any referential ingegrity violation
asPredicateIDs := libovsdbops.NewDbObjectIDs(libovsdbops.AddressSetBaselineAdminNetworkPolicy, c.controllerName, nil)
asPredicateIDs := libovsdbops.NewDbObjectIDsAcrossAllContollers(libovsdbops.AddressSetBaselineAdminNetworkPolicy, nil)
asPredicateFunc := func(as *nbdb.AddressSet) bool {
_, ok := existingBANPs[as.ExternalIDs[libovsdbops.ObjectNameKey.String()]]
return !ok // if not present in cache then its stale
}
asPredicate := libovsdbops.GetPredicate[*nbdb.AddressSet](asPredicateIDs, asPredicateFunc)
asPredicate := libovsdbops.GetPredicateAcrossAllControllers[*nbdb.AddressSet](asPredicateIDs, asPredicateFunc)
if err := libovsdbops.DeleteAddressSetsWithPredicate(c.nbClient, asPredicate); err != nil {
return fmt.Errorf("failed to remove stale BANP address sets, err: %v", err)
}
Expand Down

0 comments on commit 23a1356

Please sign in to comment.