@@ -30,6 +30,7 @@ import (
30
30
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31
31
"k8s.io/apimachinery/pkg/runtime"
32
32
"k8s.io/apimachinery/pkg/util/intstr"
33
+ "k8s.io/apimachinery/pkg/util/wait"
33
34
"k8s.io/client-go/informers"
34
35
"k8s.io/client-go/kubernetes/fake"
35
36
k8stesting "k8s.io/client-go/testing"
@@ -274,6 +275,39 @@ func TestSyncServiceEndpointSliceLabelSelection(t *testing.T) {
274
275
cmc .Check (t )
275
276
}
276
277
278
+ func TestOnEndpointSliceUpdate (t * testing.T ) {
279
+ _ , esController := newController ([]string {"node-1" }, time .Duration (0 ))
280
+ ns := metav1 .NamespaceDefault
281
+ serviceName := "testing-1"
282
+ epSlice1 := & discovery.EndpointSlice {
283
+ ObjectMeta : metav1.ObjectMeta {
284
+ Name : "matching-1" ,
285
+ Namespace : ns ,
286
+ Labels : map [string ]string {
287
+ discovery .LabelServiceName : serviceName ,
288
+ discovery .LabelManagedBy : controllerName ,
289
+ },
290
+ },
291
+ AddressType : discovery .AddressTypeIPv4 ,
292
+ }
293
+
294
+ epSlice2 := epSlice1 .DeepCopy ()
295
+ epSlice2 .Labels [discovery .LabelManagedBy ] = "something else"
296
+
297
+ assert .Equal (t , 0 , esController .queue .Len ())
298
+ esController .onEndpointSliceUpdate (epSlice1 , epSlice2 )
299
+ err := wait .PollImmediate (100 * time .Millisecond , 3 * time .Second , func () (bool , error ) {
300
+ if esController .queue .Len () > 0 {
301
+ return true , nil
302
+ }
303
+ return false , nil
304
+ })
305
+ if err != nil {
306
+ t .Fatalf ("unexpected error waiting for add to queue" )
307
+ }
308
+ assert .Equal (t , 1 , esController .queue .Len ())
309
+ }
310
+
277
311
// Ensure SyncService handles a variety of protocols and IPs appropriately.
278
312
func TestSyncServiceFull (t * testing.T ) {
279
313
client , esController := newController ([]string {"node-1" }, time .Duration (0 ))
0 commit comments