Skip to content

Commit

Permalink
Update apbroute status with retry.
Browse files Browse the repository at this point in the history
Signed-off-by: Nadia Pinaeva <[email protected]>
  • Loading branch information
npinaeva committed Jul 3, 2023
1 parent 1b17eec commit 1c4fcec
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions go-controller/pkg/ovn/controller/apbroute/master_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/client-go/kubernetes"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/retry"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog/v2"

Expand Down Expand Up @@ -256,7 +257,7 @@ func (c *ExternalGatewayMasterController) processNextPolicyWorkItem(wg *sync.Wai
klog.Errorf("Failed to sync APB policy %s: %v", key, err)
}
// capture the error from processing the sync in the statuses message field
// TODO this will post many statuses, often the same
//TODO decide how to merge statuses from multiple ovnkube-controllers
statusErr := c.updateStatusAPBExternalRoute(key.(string), gwIPs, err)
if statusErr != nil {
klog.Warningf("Failed to update AdminPolicyBasedExternalRoutes %s status: %v", key, statusErr)
Expand Down Expand Up @@ -526,16 +527,24 @@ func (c *ExternalGatewayMasterController) updateStatusAPBExternalRoute(policyNam
return nil
}

// retrieve the policy for update
routePolicy, err := c.apbRoutePolicyClient.K8sV1().AdminPolicyBasedExternalRoutes().Get(context.TODO(), policyName, metav1.GetOptions{})
resultErr := retry.RetryOnConflict(util.OvnConflictBackoff, func() error {
// Informer cache should not be mutated, so get a copy of the object
routePolicy, err := c.apbRoutePolicyClient.K8sV1().AdminPolicyBasedExternalRoutes().Get(context.TODO(), policyName, metav1.GetOptions{})
if err != nil {
return err
}

if err != nil {
return err
}
updateStatus(routePolicy, strings.Join(sets.List(gwIPs), ","), processedError)
_, err = c.apbRoutePolicyClient.K8sV1().AdminPolicyBasedExternalRoutes().UpdateStatus(context.TODO(), routePolicy, metav1.UpdateOptions{})
if !apierrors.IsNotFound(err) {
return err
cpolicy := routePolicy.DeepCopy()
updateStatus(cpolicy, strings.Join(sets.List(gwIPs), ","), processedError)

_, err = c.apbRoutePolicyClient.K8sV1().AdminPolicyBasedExternalRoutes().UpdateStatus(context.TODO(), cpolicy, metav1.UpdateOptions{})
if !apierrors.IsNotFound(err) {
return err
}
return nil
})
if resultErr != nil {
return fmt.Errorf("failed to update AdminPolicyBasedExternalRoutes %s status: %v", policyName, resultErr)
}
return nil
}
Expand Down

0 comments on commit 1c4fcec

Please sign in to comment.