33
33
_ = Describe ("" , Label (ClusterIPLabel ), testClusterIPServiceImport )
34
34
_ = Describe ("" , Label (HeadlessLabel ), testHeadlessServiceImport )
35
35
_ = Describe ("" , Label (ExternalNameLabel ), testExternalNameService )
36
+ _ = Describe ("" , testServiceTypeConflict )
36
37
)
37
38
38
39
func testGeneralServiceImport () {
@@ -47,14 +48,15 @@ func testGeneralServiceImport() {
47
48
t .createServiceExport (& clients [0 ], helloServiceExport )
48
49
})
49
50
50
- assertHasKeyValues := func (actual , expected map [string ]string ) {
51
+ assertHasKeyValues := func (g Gomega , actual , expected map [string ]string ) {
51
52
for k , v := range expected {
52
- Expect (actual ).To (HaveKeyWithValue (k , v ), reportNonConformant ("" ))
53
+ g . Expect (actual ).To (HaveKeyWithValue (k , v ), reportNonConformant ("" ))
53
54
}
54
55
}
55
- assertNotHasKeyValues := func (actual , expected map [string ]string ) {
56
+
57
+ assertNotHasKeyValues := func (g Gomega , actual , expected map [string ]string ) {
56
58
for k , v := range expected {
57
- Expect (actual ).ToNot (HaveKeyWithValue (k , v ), reportNonConformant ("" ))
59
+ g . Expect (actual ).ToNot (HaveKeyWithValue (k , v ), reportNonConformant ("" ))
58
60
}
59
61
}
60
62
@@ -66,10 +68,7 @@ func testGeneralServiceImport() {
66
68
67
69
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/blob/master/keps/sig-multicluster/1645-multi-cluster-services-api/README.md#importing-services" )
68
70
69
- serviceImport := t .awaitServiceImport (& clients [0 ], t .helloService .Name , func (serviceImport * v1alpha1.ServiceImport ) bool {
70
- return true
71
- })
72
- Expect (serviceImport ).NotTo (BeNil (), "ServiceImport was not found" )
71
+ t .awaitServiceImport (& clients [0 ], t .helloService .Name , false , nil )
73
72
74
73
By (fmt .Sprintf ("Exporting the service on the second cluster %q" , clients [1 ].name ))
75
74
@@ -109,16 +108,14 @@ func testGeneralServiceImport() {
109
108
Label (OptionalLabel ), Label (ExportedLabelsLabel ), func () {
110
109
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#labels-and-annotations" )
111
110
112
- serviceImport := t .awaitServiceImport (& clients [0 ], helloServiceName , func ( serviceImport * v1alpha1. ServiceImport ) bool {
113
- return len ( serviceImport . Labels ) > 0
114
- } )
115
- Expect ( serviceImport ). NotTo ( BeNil (), "ServiceImport was not found" )
111
+ t .awaitServiceImport (& clients [0 ], helloServiceName , false ,
112
+ func ( g Gomega , serviceImport * v1alpha1. ServiceImport ) {
113
+ assertHasKeyValues ( g , serviceImport . Annotations , helloServiceExport . Annotations )
114
+ assertNotHasKeyValues ( g , serviceImport . Annotations , t . helloService . Annotations )
116
115
117
- assertHasKeyValues (serviceImport .Annotations , helloServiceExport .Annotations )
118
- assertNotHasKeyValues (serviceImport .Annotations , t .helloService .Annotations )
119
-
120
- assertHasKeyValues (serviceImport .Labels , helloServiceExport .Labels )
121
- assertNotHasKeyValues (serviceImport .Labels , t .helloService .Labels )
116
+ assertHasKeyValues (g , serviceImport .Labels , helloServiceExport .Labels )
117
+ assertNotHasKeyValues (g , serviceImport .Labels , t .helloService .Labels )
118
+ })
122
119
})
123
120
})
124
121
@@ -141,16 +138,14 @@ func testGeneralServiceImport() {
141
138
t .awaitServiceExportCondition (& clients [0 ], v1alpha1 .ServiceExportConflict , metav1 .ConditionTrue )
142
139
t .awaitServiceExportCondition (& clients [1 ], v1alpha1 .ServiceExportConflict , metav1 .ConditionTrue )
143
140
144
- serviceImport := t .awaitServiceImport (& clients [0 ], t .helloService .Name , func (serviceImport * v1alpha1.ServiceImport ) bool {
145
- return len (serviceImport .Labels ) > 0
146
- })
147
- Expect (serviceImport ).NotTo (BeNil (), "ServiceImport was not found" )
148
-
149
- assertHasKeyValues (serviceImport .Annotations , helloServiceExport .Annotations )
150
- assertNotHasKeyValues (serviceImport .Annotations , tt .helloServiceExport2 .Annotations )
141
+ t .awaitServiceImport (& clients [0 ], t .helloService .Name , false ,
142
+ func (g Gomega , serviceImport * v1alpha1.ServiceImport ) {
143
+ assertHasKeyValues (g , serviceImport .Annotations , helloServiceExport .Annotations )
144
+ assertNotHasKeyValues (g , serviceImport .Annotations , tt .helloServiceExport2 .Annotations )
151
145
152
- assertHasKeyValues (serviceImport .Labels , helloServiceExport .Labels )
153
- assertNotHasKeyValues (serviceImport .Labels , tt .helloServiceExport2 .Labels )
146
+ assertHasKeyValues (g , serviceImport .Labels , helloServiceExport .Labels )
147
+ assertNotHasKeyValues (g , serviceImport .Labels , tt .helloServiceExport2 .Labels )
148
+ })
154
149
})
155
150
})
156
151
})
@@ -173,9 +168,7 @@ func testClusterIPServiceImport() {
173
168
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#importing-services" )
174
169
175
170
for i := range clients {
176
- serviceImport := t .awaitServiceImport (& clients [i ], helloServiceName , nil )
177
- Expect (serviceImport ).NotTo (BeNil (), reportNonConformant (fmt .Sprintf ("ServiceImport was not found on cluster %q" ,
178
- clients [i ].name )))
171
+ serviceImport := t .awaitServiceImport (& clients [i ], helloServiceName , true , nil )
179
172
180
173
Expect (serviceImport .Spec .Type ).To (Equal (v1alpha1 .ClusterSetIP ), reportNonConformant (
181
174
fmt .Sprintf ("ServiceImport on cluster %q has type %q" , clients [i ].name , serviceImport .Spec .Type )))
@@ -195,37 +188,32 @@ func testClusterIPServiceImport() {
195
188
Label (RequiredLabel ), func () {
196
189
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#session-affinity" )
197
190
198
- serviceImport := t .awaitServiceImport (& clients [0 ], helloServiceName , nil )
199
- Expect (serviceImport ). NotTo ( BeNil ( ), "ServiceImport was not found" )
191
+ t .awaitServiceImport (& clients [0 ], helloServiceName , false , func ( g Gomega , serviceImport * v1alpha1. ServiceImport ) {
192
+ g . Expect (serviceImport . Spec . SessionAffinity ). To ( Equal ( t . helloService . Spec . SessionAffinity ), reportNonConformant ( "" ) )
200
193
201
- Expect (serviceImport .Spec .SessionAffinity ).To (Equal (t .helloService .Spec .SessionAffinity ), reportNonConformant ("" ))
202
-
203
- Expect (serviceImport .Spec .SessionAffinityConfig ).To (Equal (t .helloService .Spec .SessionAffinityConfig ), reportNonConformant (
204
- "The SessionAffinityConfig of the ServiceImport does not match the exported Service's SessionAffinityConfig" ))
194
+ g .Expect (serviceImport .Spec .SessionAffinityConfig ).To (Equal (t .helloService .Spec .SessionAffinityConfig ), reportNonConformant (
195
+ "The SessionAffinityConfig of the ServiceImport does not match the exported Service's SessionAffinityConfig" ))
196
+ })
205
197
})
206
198
207
199
Specify ("An IP should be allocated for a ClusterSetIP ServiceImport" , Label (RequiredLabel ), func () {
208
200
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#clustersetip" )
209
201
210
- serviceImport := t .awaitServiceImport (& clients [0 ], t .helloService .Name , func ( serviceImport * v1alpha1. ServiceImport ) bool {
211
- return len ( serviceImport . Spec . IPs ) > 0
212
- } )
213
- Expect ( serviceImport ). NotTo ( BeNil (), "ServiceImport was not found" )
202
+ serviceImport := t .awaitServiceImport (& clients [0 ], t .helloService .Name , false ,
203
+ func ( g Gomega , serviceImport * v1alpha1. ServiceImport ) {
204
+ g . Expect ( serviceImport . Spec . IPs ). ToNot ( BeEmpty (), reportNonConformant ( "" ) )
205
+ } )
214
206
215
- Expect (serviceImport .Spec .IPs ).ToNot (BeEmpty (), reportNonConformant ("" ))
216
207
Expect (net .ParseIP (serviceImport .Spec .IPs [0 ])).ToNot (BeNil (),
217
208
reportNonConformant (fmt .Sprintf ("The value %q is not a valid IP" , serviceImport .Spec .IPs [0 ])))
218
209
})
219
210
220
211
Specify ("The ports for a ClusterSetIP ServiceImport should match those of the exported service" , Label (RequiredLabel ), func () {
221
212
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#service-port" )
222
213
223
- serviceImport := t .awaitServiceImport (& clients [0 ], helloServiceName , func (serviceImport * v1alpha1.ServiceImport ) bool {
224
- return len ( serviceImport .Spec .Ports ) > 0
214
+ t .awaitServiceImport (& clients [0 ], helloServiceName , false , func (g Gomega , serviceImport * v1alpha1.ServiceImport ) {
215
+ g . Expect ( sortMCSPorts ( serviceImport .Spec .Ports )). To ( Equal ( toMCSPorts ( t . helloService . Spec . Ports )), reportNonConformant ( "" ))
225
216
})
226
- Expect (serviceImport ).NotTo (BeNil (), "ServiceImport was not found" )
227
-
228
- Expect (sortMCSPorts (serviceImport .Spec .Ports )).To (Equal (toMCSPorts (t .helloService .Spec .Ports )), reportNonConformant ("" ))
229
217
})
230
218
231
219
Context ("A ClusterIP service exported on two clusters" , func () {
@@ -246,13 +234,11 @@ func testClusterIPServiceImport() {
246
234
Specify ("should expose the union of the constituent service ports" , Label (RequiredLabel ), func () {
247
235
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#service-port" )
248
236
249
- serviceImport := t .awaitServiceImport (& clients [0 ], t .helloService .Name , func (serviceImport * v1alpha1.ServiceImport ) bool {
250
- return len (serviceImport .Spec .Ports ) == 3
251
- })
252
- Expect (serviceImport ).NotTo (BeNil (), "ServiceImport was not found" )
253
-
254
- Expect (sortMCSPorts (serviceImport .Spec .Ports )).To (Equal (toMCSPorts (
255
- append (t .helloService .Spec .Ports , tt .helloService2 .Spec .Ports [1 ]))), reportNonConformant ("" ))
237
+ t .awaitServiceImport (& clients [0 ], t .helloService .Name , false ,
238
+ func (g Gomega , serviceImport * v1alpha1.ServiceImport ) {
239
+ g .Expect (sortMCSPorts (serviceImport .Spec .Ports )).To (Equal (toMCSPorts (
240
+ append (t .helloService .Spec .Ports , tt .helloService2 .Spec .Ports [1 ]))), reportNonConformant ("" ))
241
+ })
256
242
})
257
243
})
258
244
@@ -268,13 +254,11 @@ func testClusterIPServiceImport() {
268
254
t .awaitServiceExportCondition (& clients [0 ], v1alpha1 .ServiceExportConflict , metav1 .ConditionTrue )
269
255
t .awaitServiceExportCondition (& clients [1 ], v1alpha1 .ServiceExportConflict , metav1 .ConditionTrue )
270
256
271
- serviceImport := t .awaitServiceImport (& clients [0 ], t .helloService .Name , func (serviceImport * v1alpha1.ServiceImport ) bool {
272
- return len (serviceImport .Spec .Ports ) == len (t .helloService .Spec .Ports )
273
- })
274
- Expect (serviceImport ).NotTo (BeNil (), "ServiceImport was not found" )
275
-
276
- Expect (sortMCSPorts (serviceImport .Spec .Ports )).To (Equal (toMCSPorts (t .helloService .Spec .Ports )),
277
- reportNonConformant ("The service ports were not resolved correctly" ))
257
+ t .awaitServiceImport (& clients [0 ], t .helloService .Name , false ,
258
+ func (g Gomega , serviceImport * v1alpha1.ServiceImport ) {
259
+ g .Expect (sortMCSPorts (serviceImport .Spec .Ports )).To (Equal (toMCSPorts (t .helloService .Spec .Ports )),
260
+ reportNonConformant ("The service ports were not resolved correctly" ))
261
+ })
278
262
})
279
263
})
280
264
})
@@ -296,9 +280,7 @@ func testHeadlessServiceImport() {
296
280
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#service-types" )
297
281
298
282
for i := range clients {
299
- serviceImport := t .awaitServiceImport (& clients [i ], helloServiceName , nil )
300
- Expect (serviceImport ).NotTo (BeNil (), reportNonConformant (fmt .Sprintf ("ServiceImport was not found on cluster %q" ,
301
- clients [i ].name )))
283
+ serviceImport := t .awaitServiceImport (& clients [i ], helloServiceName , true , nil )
302
284
303
285
Expect (serviceImport .Spec .Type ).To (Equal (v1alpha1 .Headless ), reportNonConformant (
304
286
fmt .Sprintf ("ServiceImport on cluster %q has type %q" , clients [i ].name , serviceImport .Spec .Type )))
@@ -317,8 +299,7 @@ func testHeadlessServiceImport() {
317
299
Specify ("No clusterset IP should be allocated for a Headless ServiceImport" , Label (RequiredLabel ), func () {
318
300
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#clustersetip" )
319
301
320
- serviceImport := t .awaitServiceImport (& clients [0 ], t .helloService .Name , nil )
321
- Expect (serviceImport ).NotTo (BeNil (), "ServiceImport was not found" )
302
+ t .awaitServiceImport (& clients [0 ], t .helloService .Name , false , nil )
322
303
323
304
Consistently (func () []string {
324
305
return t .getServiceImport (& clients [0 ], t .helloService .Name ).Spec .IPs
@@ -346,3 +327,30 @@ func testExternalNameService() {
346
327
"the ServiceImport should not exist for an ExternalName service" )
347
328
})
348
329
}
330
+
331
+ func testServiceTypeConflict () {
332
+ t := newTwoClusterTestDriver (newTestDriver ())
333
+
334
+ BeforeEach (func () {
335
+ t .helloService2 .Spec .ClusterIP = corev1 .ClusterIPNone
336
+ })
337
+
338
+ JustBeforeEach (func () {
339
+ t .createServiceExport (& clients [0 ], newHelloServiceExport ())
340
+ })
341
+
342
+ Specify ("A service exported on two clusters with conflicting headlessness should apply the conflict resolution policy and " +
343
+ "report a Conflict condition on the ServiceExport" , Label (RequiredLabel ), func () {
344
+ AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#headlessness" )
345
+
346
+ t .awaitServiceExportCondition (& clients [0 ], v1alpha1 .ServiceExportConflict , metav1 .ConditionTrue )
347
+ t .awaitServiceExportCondition (& clients [1 ], v1alpha1 .ServiceExportConflict , metav1 .ConditionTrue )
348
+
349
+ for i := range clients {
350
+ serviceImport := t .awaitServiceImport (& clients [i ], helloServiceName , true , nil )
351
+
352
+ Expect (serviceImport .Spec .Type ).To (Equal (v1alpha1 .ClusterSetIP ), reportNonConformant (
353
+ fmt .Sprintf ("ServiceImport on cluster %q has type %q" , clients [i ].name , serviceImport .Spec .Type )))
354
+ }
355
+ })
356
+ }
0 commit comments