@@ -24,6 +24,7 @@ import (
24
24
corev1 "k8s.io/api/core/v1"
25
25
discovery "k8s.io/api/discovery/v1"
26
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
+ "k8s.io/apimachinery/pkg/types"
27
28
"k8s.io/client-go/kubernetes/fake"
28
29
"k8s.io/client-go/kubernetes/scheme"
29
30
"k8s.io/client-go/tools/record"
@@ -48,6 +49,7 @@ func TestReconcile(t *testing.T) {
48
49
subsets []corev1.EndpointSubset
49
50
epLabels map [string ]string
50
51
epAnnotations map [string ]string
52
+ uid string
51
53
endpointsDeletionPending bool
52
54
maxEndpointsPerSubset int32
53
55
existingEndpointSlices []* discovery.EndpointSlice
@@ -219,9 +221,19 @@ func TestReconcile(t *testing.T) {
219
221
Hostname : "pod-1" ,
220
222
}},
221
223
}},
224
+ uid : "d8f2c1f6-5285-4b3c-b3c1-9b89f9e7ed7a" ,
222
225
existingEndpointSlices : []* discovery.EndpointSlice {{
223
226
ObjectMeta : metav1.ObjectMeta {
224
- Name : "test-ep-1" ,
227
+ Name : "test-ep-1" ,
228
+ Namespace : "test" ,
229
+ OwnerReferences : []metav1.OwnerReference {
230
+ {
231
+ APIVersion : "v1" ,
232
+ Kind : "Endpoints" ,
233
+ Name : "test-ep" ,
234
+ UID : "d8f2c1f6-5285-4b3c-b3c1-9b89f9e7ed7a" ,
235
+ },
236
+ },
225
237
},
226
238
AddressType : discovery .AddressTypeIPv4 ,
227
239
Ports : []discovery.EndpointPort {{
@@ -237,6 +249,47 @@ func TestReconcile(t *testing.T) {
237
249
}},
238
250
expectedNumSlices : 1 ,
239
251
expectedClientActions : 0 ,
252
+ }, {
253
+ testName : "Endpoints with 1 subset, port, and address and existing slice with same fields but different OwnerReferences" ,
254
+ subsets : []corev1.EndpointSubset {{
255
+ Ports : []corev1.EndpointPort {{
256
+ Name : "http" ,
257
+ Port : 80 ,
258
+ Protocol : corev1 .ProtocolTCP ,
259
+ }},
260
+ Addresses : []corev1.EndpointAddress {{
261
+ IP : "10.0.0.1" ,
262
+ Hostname : "pod-1" ,
263
+ }},
264
+ }},
265
+ uid : "d8f2c1f6-5285-4b3c-b3c1-9b89f9e7ed7a" ,
266
+ existingEndpointSlices : []* discovery.EndpointSlice {{
267
+ ObjectMeta : metav1.ObjectMeta {
268
+ Name : "test-ep-1" ,
269
+ Namespace : "test" ,
270
+ OwnerReferences : []metav1.OwnerReference {
271
+ {
272
+ APIVersion : "v1" ,
273
+ Kind : "Endpoints" ,
274
+ Name : "test-ep" ,
275
+ UID : "fb91e798-1875-4857-b5eb-e2c878157b4d" ,
276
+ },
277
+ },
278
+ },
279
+ AddressType : discovery .AddressTypeIPv4 ,
280
+ Ports : []discovery.EndpointPort {{
281
+ Name : pointer .String ("http" ),
282
+ Port : pointer .Int32 (80 ),
283
+ Protocol : & protoTCP ,
284
+ }},
285
+ Endpoints : []discovery.Endpoint {{
286
+ Addresses : []string {"10.0.0.1" },
287
+ Hostname : pointer .String ("pod-1" ),
288
+ Conditions : discovery.EndpointConditions {Ready : pointer .Bool (true )},
289
+ }},
290
+ }},
291
+ expectedNumSlices : 1 ,
292
+ expectedClientActions : 1 ,
240
293
}, {
241
294
testName : "Endpoints with 1 subset, port, and address and existing slice with an additional annotation" ,
242
295
subsets : []corev1.EndpointSubset {{
@@ -1012,7 +1065,7 @@ func TestReconcile(t *testing.T) {
1012
1065
setupMetrics ()
1013
1066
namespace := "test"
1014
1067
endpoints := corev1.Endpoints {
1015
- ObjectMeta : metav1.ObjectMeta {Name : "test-ep" , Namespace : namespace , Labels : tc .epLabels , Annotations : tc .epAnnotations },
1068
+ ObjectMeta : metav1.ObjectMeta {Name : "test-ep" , Namespace : namespace , Labels : tc .epLabels , Annotations : tc .epAnnotations , UID : types . UID ( tc . uid ) },
1016
1069
Subsets : tc .subsets ,
1017
1070
}
1018
1071
0 commit comments