diff --git a/pkg/controller/util/endpointslice/endpointslice_tracker.go b/pkg/controller/util/endpointslice/endpointslice_tracker.go index 8138ca59b70..35b58f988d2 100644 --- a/pkg/controller/util/endpointslice/endpointslice_tracker.go +++ b/pkg/controller/util/endpointslice/endpointslice_tracker.go @@ -84,7 +84,7 @@ func (est *EndpointSliceTracker) ShouldSync(endpointSlice *discovery.EndpointSli // 1. One or more of the provided EndpointSlices have older generations than the // corresponding tracked ones. // 2. The tracker is expecting one or more of the provided EndpointSlices to be -// deleted. +// deleted. (EndpointSlices that have already been marked for deletion are ignored here.) // 3. The tracker is tracking EndpointSlices that have not been provided. func (est *EndpointSliceTracker) StaleSlices(service *v1.Service, endpointSlices []*discovery.EndpointSlice) bool { est.lock.Lock() @@ -100,6 +100,9 @@ func (est *EndpointSliceTracker) StaleSlices(service *v1.Service, endpointSlices providedSlices[endpointSlice.UID] = endpointSlice.Generation g, ok := gfs[endpointSlice.UID] if ok && (g == deletionExpected || g > endpointSlice.Generation) { + if endpointSlice.DeletionTimestamp != nil { + continue + } return true } } diff --git a/pkg/controller/util/endpointslice/endpointslice_tracker_test.go b/pkg/controller/util/endpointslice/endpointslice_tracker_test.go index ca73ed20978..b7b0d7fc1e7 100644 --- a/pkg/controller/util/endpointslice/endpointslice_tracker_test.go +++ b/pkg/controller/util/endpointslice/endpointslice_tracker_test.go @@ -124,6 +124,10 @@ func TestEndpointSliceTrackerStaleSlices(t *testing.T) { epSlice1NewerGen := epSlice1.DeepCopy() epSlice1NewerGen.Generation = 2 + epTerminatingSlice := epSlice1.DeepCopy() + now := metav1.Now() + epTerminatingSlice.DeletionTimestamp = &now + testCases := []struct { name string tracker *EndpointSliceTracker @@ -208,6 +212,18 @@ func TestEndpointSliceTrackerStaleSlices(t *testing.T) { serviceParam: &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "svc1", Namespace: "ns1"}}, slicesParam: []*discovery.EndpointSlice{}, expectNewer: true, + }, { + name: "slice in params is has non nil deletion timestamp", + tracker: &EndpointSliceTracker{ + generationsByService: map[types.NamespacedName]GenerationsBySlice{ + {Name: "svc1", Namespace: "ns1"}: { + epSlice1.UID: epSlice1.Generation, + }, + }, + }, + serviceParam: &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "svc1", Namespace: "ns1"}}, + slicesParam: []*discovery.EndpointSlice{epTerminatingSlice}, + expectNewer: false, }} for _, tc := range testCases {