Ignore EndpointSlices that are already marked for deletion

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
This commit is contained in:
Sanskar Jaiswal 2022-04-23 01:31:45 +05:30
parent f02682c628
commit 7d8048dd59
2 changed files with 20 additions and 1 deletions

View File

@ -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
}
}

View File

@ -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 {