@@ -1008,6 +1008,63 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
10081008 endpointsHandler .ValidateRequestCount (t , 0 )
10091009}
10101010
1011+ func TestSyncEndpointsItemsPreexistingIdenticalUnsorted (t * testing.T ) {
1012+ ns := metav1 .NamespaceDefault
1013+ testServer , endpointsHandler := makeTestServer (t , ns )
1014+ defer testServer .Close ()
1015+ tCtx := ktesting .Init (t )
1016+ endpoints := newController (tCtx , testServer .URL , 0 * time .Second )
1017+ pod0 := testPod (ns , 0 , 1 , true , ipv4only )
1018+ pod1 := testPod (ns , 1 , 1 , true , ipv4only )
1019+
1020+ subsets := []v1.EndpointSubset {{
1021+ Addresses : []v1.EndpointAddress {
1022+ // known to not be packed correctly according to the current hash
1023+ {IP : pod1 .Status .PodIPs [0 ].IP , NodeName : & emptyNodeName , TargetRef : & v1.ObjectReference {Kind : "Pod" , Name : pod1 .Name , Namespace : ns }},
1024+ {IP : pod0 .Status .PodIPs [0 ].IP , NodeName : & emptyNodeName , TargetRef : & v1.ObjectReference {Kind : "Pod" , Name : pod0 .Name , Namespace : ns }},
1025+ },
1026+ Ports : []v1.EndpointPort {{Port : 8080 , Protocol : "TCP" }},
1027+ }}
1028+
1029+ // Assert that endpoints are not repacked correctly according to the current hash.
1030+ // We want to prove that this does not cause a re-sync.
1031+ repacked := endptspkg .RepackSubsets (subsets )
1032+ if reflect .DeepEqual (subsets , repacked ) {
1033+ t .Errorf ("subsets were already in sorted order" )
1034+ }
1035+
1036+ endpoints .endpointsStore .Add (& v1.Endpoints {
1037+ ObjectMeta : metav1.ObjectMeta {
1038+ ResourceVersion : "1" ,
1039+ Name : "foo" ,
1040+ Namespace : ns ,
1041+ Labels : map [string ]string {
1042+ LabelManagedBy : ControllerName ,
1043+ },
1044+ },
1045+ Subsets : subsets ,
1046+ })
1047+
1048+ endpoints .podStore .Add (pod0 )
1049+ endpoints .podStore .Add (pod1 )
1050+
1051+ endpoints .serviceStore .Add (& v1.Service {
1052+ ObjectMeta : metav1.ObjectMeta {Name : "foo" , Namespace : metav1 .NamespaceDefault },
1053+ Spec : v1.ServiceSpec {
1054+ Selector : map [string ]string {"foo" : "bar" },
1055+ Ports : []v1.ServicePort {{Port : 80 , Protocol : "TCP" , TargetPort : intstr .FromInt32 (8080 )}},
1056+ IPFamilies : []v1.IPFamily {v1 .IPv4Protocol },
1057+ },
1058+ })
1059+ err := endpoints .syncService (tCtx , ns + "/foo" )
1060+ if err != nil {
1061+ t .Errorf ("Unexpected error syncing service %v" , err )
1062+ }
1063+
1064+ // syncing should've been a no-op
1065+ endpointsHandler .ValidateRequestCount (t , 0 )
1066+ }
1067+
10111068func TestSyncEndpointsItems (t * testing.T ) {
10121069 ns := "other"
10131070 testServer , endpointsHandler := makeTestServer (t , ns )
0 commit comments