bugfix: endpoints controller track resource version conrrectly
The endpoints controller store the resource version of the previous Endpoints objects to avoid issues related to stale information on the cache. However, there can be update operations that succeed without increasing the resource version, causing the endpoints controller to declare stale the existing Resource Version and stopping the Endpoints to be updated. Co-Author-By: Quan Tian <quan.tian@broadcom.com> Co-Author-By: Yang Yang <yyyng@amazon.com>
This commit is contained in:
committed by
Swetha Repakula
parent
aae6745a67
commit
dad9c77a74
@@ -532,12 +532,13 @@ func (e *Controller) syncService(ctx context.Context, key string) error {
|
||||
}
|
||||
|
||||
logger.V(4).Info("Update endpoints", "service", klog.KObj(service), "readyEndpoints", totalReadyEps, "notreadyEndpoints", totalNotReadyEps)
|
||||
var updatedEndpoints *v1.Endpoints
|
||||
if createEndpoints {
|
||||
// No previous endpoints, create them
|
||||
_, err = e.client.CoreV1().Endpoints(service.Namespace).Create(ctx, newEndpoints, metav1.CreateOptions{})
|
||||
} else {
|
||||
// Pre-existing
|
||||
_, err = e.client.CoreV1().Endpoints(service.Namespace).Update(ctx, newEndpoints, metav1.UpdateOptions{})
|
||||
updatedEndpoints, err = e.client.CoreV1().Endpoints(service.Namespace).Update(ctx, newEndpoints, metav1.UpdateOptions{})
|
||||
}
|
||||
if err != nil {
|
||||
if createEndpoints && errors.IsForbidden(err) {
|
||||
@@ -564,7 +565,10 @@ func (e *Controller) syncService(ctx context.Context, key string) error {
|
||||
// If the current endpoints is updated we track the old resource version, so
|
||||
// if we obtain this resource version again from the lister we know is outdated
|
||||
// and we need to retry later to wait for the informer cache to be up-to-date.
|
||||
if !createEndpoints {
|
||||
// there are some operations (webhooks, truncated endpoints, ...) that can potentially cause endpoints updates became noop
|
||||
// and return the same resourceVersion.
|
||||
// Ref: https://issues.k8s.io/127370 , https://issues.k8s.io/126578
|
||||
if updatedEndpoints != nil && updatedEndpoints.ResourceVersion != currentEndpoints.ResourceVersion {
|
||||
e.staleEndpointsTracker.Stale(currentEndpoints)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user