Fixing Potential Race Condition in EndpointSlice Controller.

This adds a new EndpointSlice tracker to keep track of the expected resource versions of EndpointSlices associated with each Service managed by the EndpointSlice controller. This should prevent a potential race where a syncService call could happen with an incomplete view of EndpointSlices if additions or deletions hadn't fully propagated to the cache yet. Additionally, this ensures that external changes to EndpointSlices will be handled by the EndpointSlice controller.
This commit is contained in:
Rob Scott
2019-11-26 17:43:21 -08:00
parent e4ad76e298
commit c75787bb77
8 changed files with 449 additions and 3 deletions

View File

@@ -40,6 +40,7 @@ type reconciler struct {
client clientset.Interface
nodeLister corelisters.NodeLister
maxEndpointsPerSlice int32
endpointSliceTracker *endpointSliceTracker
metricsCache *metrics.Cache
}
@@ -212,6 +213,7 @@ func (r *reconciler) finalize(
}
errs = append(errs, fmt.Errorf("Error creating EndpointSlice for Service %s/%s: %v", service.Namespace, service.Name, err))
} else {
r.endpointSliceTracker.Update(endpointSlice)
metrics.EndpointSliceChanges.WithLabelValues("create").Inc()
}
}
@@ -222,6 +224,7 @@ func (r *reconciler) finalize(
if err != nil {
errs = append(errs, fmt.Errorf("Error updating %s EndpointSlice for Service %s/%s: %v", endpointSlice.Name, service.Namespace, service.Name, err))
} else {
r.endpointSliceTracker.Update(endpointSlice)
metrics.EndpointSliceChanges.WithLabelValues("update").Inc()
}
}
@@ -231,6 +234,7 @@ func (r *reconciler) finalize(
if err != nil {
errs = append(errs, fmt.Errorf("Error deleting %s EndpointSlice for Service %s/%s: %v", endpointSlice.Name, service.Namespace, service.Name, err))
} else {
r.endpointSliceTracker.Delete(endpointSlice)
metrics.EndpointSliceChanges.WithLabelValues("delete").Inc()
}
}