@@ -318,6 +318,7 @@ func TestReconcileEndpointSlicesSomePreexisting(t *testing.T) {
318
318
}
319
319
320
320
existingSlices := []* discovery.EndpointSlice {endpointSlice1 , endpointSlice2 }
321
+ cmc := newCacheMutationCheck (existingSlices )
321
322
createEndpointSlices (t , client , namespace , existingSlices )
322
323
323
324
numActionsBefore := len (client .Actions ())
@@ -332,6 +333,9 @@ func TestReconcileEndpointSlicesSomePreexisting(t *testing.T) {
332
333
// 1 new slice (0->100) + 1 updated slice (62->89)
333
334
expectUnorderedSlicesWithLengths (t , fetchEndpointSlices (t , client , namespace ), []int {89 , 61 , 100 })
334
335
expectMetrics (t , expectedMetrics {desiredSlices : 3 , actualSlices : 3 , desiredEndpoints : 250 , addedPerSync : 127 , removedPerSync : 0 , numCreated : 1 , numUpdated : 1 , numDeleted : 0 })
336
+
337
+ // ensure cache mutation has not occurred
338
+ cmc .Check (t )
335
339
}
336
340
337
341
// now with preexisting slices, we have 300 pods matching a service
@@ -370,6 +374,7 @@ func TestReconcileEndpointSlicesSomePreexistingWorseAllocation(t *testing.T) {
370
374
}
371
375
372
376
existingSlices := []* discovery.EndpointSlice {endpointSlice1 , endpointSlice2 }
377
+ cmc := newCacheMutationCheck (existingSlices )
373
378
createEndpointSlices (t , client , namespace , existingSlices )
374
379
375
380
numActionsBefore := len (client .Actions ())
@@ -383,6 +388,9 @@ func TestReconcileEndpointSlicesSomePreexistingWorseAllocation(t *testing.T) {
383
388
// 2 new slices (100, 52) in addition to existing slices (74, 74)
384
389
expectUnorderedSlicesWithLengths (t , fetchEndpointSlices (t , client , namespace ), []int {74 , 74 , 100 , 52 })
385
390
expectMetrics (t , expectedMetrics {desiredSlices : 3 , actualSlices : 4 , desiredEndpoints : 300 , addedPerSync : 152 , removedPerSync : 0 , numCreated : 2 , numUpdated : 0 , numDeleted : 0 })
391
+
392
+ // ensure cache mutation has not occurred
393
+ cmc .Check (t )
386
394
}
387
395
388
396
// In some cases, such as a service port change, all slices for that service will require a change
@@ -445,6 +453,7 @@ func TestReconcileEndpointSlicesRecycling(t *testing.T) {
445
453
existingSlices [sliceNum ].Endpoints = append (existingSlices [sliceNum ].Endpoints , podToEndpoint (pod , & corev1.Node {}, & svc ))
446
454
}
447
455
456
+ cmc := newCacheMutationCheck (existingSlices )
448
457
createEndpointSlices (t , client , namespace , existingSlices )
449
458
450
459
numActionsBefore := len (client .Actions ())
@@ -463,6 +472,9 @@ func TestReconcileEndpointSlicesRecycling(t *testing.T) {
463
472
// thanks to recycling, we get a free repack of endpoints, resulting in 3 full slices instead of 10 mostly empty slices
464
473
expectUnorderedSlicesWithLengths (t , fetchEndpointSlices (t , client , namespace ), []int {100 , 100 , 100 })
465
474
expectMetrics (t , expectedMetrics {desiredSlices : 3 , actualSlices : 3 , desiredEndpoints : 300 , addedPerSync : 300 , removedPerSync : 0 , numCreated : 0 , numUpdated : 3 , numDeleted : 7 })
475
+
476
+ // ensure cache mutation has not occurred
477
+ cmc .Check (t )
466
478
}
467
479
468
480
// In this test, we want to verify that endpoints are added to a slice that will
@@ -493,6 +505,7 @@ func TestReconcileEndpointSlicesUpdatePacking(t *testing.T) {
493
505
}
494
506
existingSlices = append (existingSlices , slice2 )
495
507
508
+ cmc := newCacheMutationCheck (existingSlices )
496
509
createEndpointSlices (t , client , namespace , existingSlices )
497
510
498
511
// ensure that endpoints in each slice will be marked for update.
@@ -519,6 +532,9 @@ func TestReconcileEndpointSlicesUpdatePacking(t *testing.T) {
519
532
520
533
// additional pods should get added to fuller slice
521
534
expectUnorderedSlicesWithLengths (t , fetchEndpointSlices (t , client , namespace ), []int {95 , 20 })
535
+
536
+ // ensure cache mutation has not occurred
537
+ cmc .Check (t )
522
538
}
523
539
524
540
// In this test, we want to verify that old EndpointSlices with a deprecated IP
@@ -552,6 +568,7 @@ func TestReconcileEndpointSlicesReplaceDeprecated(t *testing.T) {
552
568
553
569
createEndpointSlices (t , client , namespace , existingSlices )
554
570
571
+ cmc := newCacheMutationCheck (existingSlices )
555
572
r := newReconciler (client , []* corev1.Node {{ObjectMeta : metav1.ObjectMeta {Name : "node-1" }}}, defaultMaxEndpointsPerSlice )
556
573
reconcileHelper (t , r , & svc , pods , existingSlices , time .Now ())
557
574
@@ -569,6 +586,9 @@ func TestReconcileEndpointSlicesReplaceDeprecated(t *testing.T) {
569
586
t .Errorf ("Expected address type to be IPv4, got %s" , endpointSlice .AddressType )
570
587
}
571
588
}
589
+
590
+ // ensure cache mutation has not occurred
591
+ cmc .Check (t )
572
592
}
573
593
574
594
// Named ports can map to different port numbers on different pods.
0 commit comments