@@ -47,14 +47,15 @@ func testGeneralServiceImport() {
47
47
t .createServiceExport (& clients [0 ], helloServiceExport )
48
48
})
49
49
50
- assertHasKeyValues := func (actual , expected map [string ]string ) {
50
+ assertHasKeyValues := func (g Gomega , actual , expected map [string ]string ) {
51
51
for k , v := range expected {
52
- Expect (actual ).To (HaveKeyWithValue (k , v ), reportNonConformant ("" ))
52
+ g . Expect (actual ).To (HaveKeyWithValue (k , v ), reportNonConformant ("" ))
53
53
}
54
54
}
55
- assertNotHasKeyValues := func (actual , expected map [string ]string ) {
55
+
56
+ assertNotHasKeyValues := func (g Gomega , actual , expected map [string ]string ) {
56
57
for k , v := range expected {
57
- Expect (actual ).ToNot (HaveKeyWithValue (k , v ), reportNonConformant ("" ))
58
+ g . Expect (actual ).ToNot (HaveKeyWithValue (k , v ), reportNonConformant ("" ))
58
59
}
59
60
}
60
61
@@ -66,10 +67,7 @@ func testGeneralServiceImport() {
66
67
67
68
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/blob/master/keps/sig-multicluster/1645-multi-cluster-services-api/README.md#importing-services" )
68
69
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" )
70
+ t .awaitServiceImport (& clients [0 ], t .helloService .Name , false , nil )
73
71
74
72
By (fmt .Sprintf ("Exporting the service on the second cluster %q" , clients [1 ].name ))
75
73
@@ -109,16 +107,14 @@ func testGeneralServiceImport() {
109
107
Label (OptionalLabel ), Label (ExportedLabelsLabel ), func () {
110
108
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#labels-and-annotations" )
111
109
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" )
110
+ t .awaitServiceImport (& clients [0 ], helloServiceName , false ,
111
+ func ( g Gomega , serviceImport * v1alpha1. ServiceImport ) {
112
+ assertHasKeyValues ( g , serviceImport . Annotations , helloServiceExport . Annotations )
113
+ assertNotHasKeyValues ( g , serviceImport . Annotations , t . helloService . Annotations )
116
114
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 )
115
+ assertHasKeyValues (g , serviceImport .Labels , helloServiceExport .Labels )
116
+ assertNotHasKeyValues (g , serviceImport .Labels , t .helloService .Labels )
117
+ })
122
118
})
123
119
})
124
120
@@ -141,16 +137,14 @@ func testGeneralServiceImport() {
141
137
t .awaitServiceExportCondition (& clients [0 ], v1alpha1 .ServiceExportConflict , metav1 .ConditionTrue )
142
138
t .awaitServiceExportCondition (& clients [1 ], v1alpha1 .ServiceExportConflict , metav1 .ConditionTrue )
143
139
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 )
140
+ t .awaitServiceImport (& clients [0 ], t .helloService .Name , false ,
141
+ func (g Gomega , serviceImport * v1alpha1.ServiceImport ) {
142
+ assertHasKeyValues (g , serviceImport .Annotations , helloServiceExport .Annotations )
143
+ assertNotHasKeyValues (g , serviceImport .Annotations , tt .helloServiceExport2 .Annotations )
151
144
152
- assertHasKeyValues (serviceImport .Labels , helloServiceExport .Labels )
153
- assertNotHasKeyValues (serviceImport .Labels , tt .helloServiceExport2 .Labels )
145
+ assertHasKeyValues (g , serviceImport .Labels , helloServiceExport .Labels )
146
+ assertNotHasKeyValues (g , serviceImport .Labels , tt .helloServiceExport2 .Labels )
147
+ })
154
148
})
155
149
})
156
150
})
@@ -173,9 +167,7 @@ func testClusterIPServiceImport() {
173
167
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#importing-services" )
174
168
175
169
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 )))
170
+ serviceImport := t .awaitServiceImport (& clients [i ], helloServiceName , true , nil )
179
171
180
172
Expect (serviceImport .Spec .Type ).To (Equal (v1alpha1 .ClusterSetIP ), reportNonConformant (
181
173
fmt .Sprintf ("ServiceImport on cluster %q has type %q" , clients [i ].name , serviceImport .Spec .Type )))
@@ -195,37 +187,32 @@ func testClusterIPServiceImport() {
195
187
Label (RequiredLabel ), func () {
196
188
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#session-affinity" )
197
189
198
- serviceImport := t .awaitServiceImport (& clients [0 ], helloServiceName , nil )
199
- Expect (serviceImport ). NotTo ( BeNil ( ), "ServiceImport was not found" )
190
+ t .awaitServiceImport (& clients [0 ], helloServiceName , false , func ( g Gomega , serviceImport * v1alpha1. ServiceImport ) {
191
+ g . Expect (serviceImport . Spec . SessionAffinity ). To ( Equal ( t . helloService . Spec . SessionAffinity ), reportNonConformant ( "" ) )
200
192
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" ))
193
+ g .Expect (serviceImport .Spec .SessionAffinityConfig ).To (Equal (t .helloService .Spec .SessionAffinityConfig ), reportNonConformant (
194
+ "The SessionAffinityConfig of the ServiceImport does not match the exported Service's SessionAffinityConfig" ))
195
+ })
205
196
})
206
197
207
198
Specify ("An IP should be allocated for a ClusterSetIP ServiceImport" , Label (RequiredLabel ), func () {
208
199
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#clustersetip" )
209
200
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" )
201
+ serviceImport := t .awaitServiceImport (& clients [0 ], t .helloService .Name , false ,
202
+ func ( g Gomega , serviceImport * v1alpha1. ServiceImport ) {
203
+ g . Expect ( serviceImport . Spec . IPs ). ToNot ( BeEmpty (), reportNonConformant ( "" ) )
204
+ } )
214
205
215
- Expect (serviceImport .Spec .IPs ).ToNot (BeEmpty (), reportNonConformant ("" ))
216
206
Expect (net .ParseIP (serviceImport .Spec .IPs [0 ])).ToNot (BeNil (),
217
207
reportNonConformant (fmt .Sprintf ("The value %q is not a valid IP" , serviceImport .Spec .IPs [0 ])))
218
208
})
219
209
220
210
Specify ("The ports for a ClusterSetIP ServiceImport should match those of the exported service" , Label (RequiredLabel ), func () {
221
211
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#service-port" )
222
212
223
- serviceImport := t .awaitServiceImport (& clients [0 ], helloServiceName , func (serviceImport * v1alpha1.ServiceImport ) bool {
224
- return len ( serviceImport .Spec .Ports ) > 0
213
+ t .awaitServiceImport (& clients [0 ], helloServiceName , false , func (g Gomega , serviceImport * v1alpha1.ServiceImport ) {
214
+ g . Expect ( sortMCSPorts ( serviceImport .Spec .Ports )). To ( Equal ( toMCSPorts ( t . helloService . Spec . Ports )), reportNonConformant ( "" ))
225
215
})
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
216
})
230
217
231
218
Context ("A ClusterIP service exported on two clusters" , func () {
@@ -246,13 +233,11 @@ func testClusterIPServiceImport() {
246
233
Specify ("should expose the union of the constituent service ports" , Label (RequiredLabel ), func () {
247
234
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#service-port" )
248
235
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 ("" ))
236
+ t .awaitServiceImport (& clients [0 ], t .helloService .Name , false ,
237
+ func (g Gomega , serviceImport * v1alpha1.ServiceImport ) {
238
+ g .Expect (sortMCSPorts (serviceImport .Spec .Ports )).To (Equal (toMCSPorts (
239
+ append (t .helloService .Spec .Ports , tt .helloService2 .Spec .Ports [1 ]))), reportNonConformant ("" ))
240
+ })
256
241
})
257
242
})
258
243
@@ -268,13 +253,11 @@ func testClusterIPServiceImport() {
268
253
t .awaitServiceExportCondition (& clients [0 ], v1alpha1 .ServiceExportConflict , metav1 .ConditionTrue )
269
254
t .awaitServiceExportCondition (& clients [1 ], v1alpha1 .ServiceExportConflict , metav1 .ConditionTrue )
270
255
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" ))
256
+ t .awaitServiceImport (& clients [0 ], t .helloService .Name , false ,
257
+ func (g Gomega , serviceImport * v1alpha1.ServiceImport ) {
258
+ g .Expect (sortMCSPorts (serviceImport .Spec .Ports )).To (Equal (toMCSPorts (t .helloService .Spec .Ports )),
259
+ reportNonConformant ("The service ports were not resolved correctly" ))
260
+ })
278
261
})
279
262
})
280
263
})
@@ -296,9 +279,7 @@ func testHeadlessServiceImport() {
296
279
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#service-types" )
297
280
298
281
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 )))
282
+ serviceImport := t .awaitServiceImport (& clients [i ], helloServiceName , true , nil )
302
283
303
284
Expect (serviceImport .Spec .Type ).To (Equal (v1alpha1 .Headless ), reportNonConformant (
304
285
fmt .Sprintf ("ServiceImport on cluster %q has type %q" , clients [i ].name , serviceImport .Spec .Type )))
@@ -317,8 +298,7 @@ func testHeadlessServiceImport() {
317
298
Specify ("No clusterset IP should be allocated for a Headless ServiceImport" , Label (RequiredLabel ), func () {
318
299
AddReportEntry (SpecRefReportEntry , "https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api#clustersetip" )
319
300
320
- serviceImport := t .awaitServiceImport (& clients [0 ], t .helloService .Name , nil )
321
- Expect (serviceImport ).NotTo (BeNil (), "ServiceImport was not found" )
301
+ t .awaitServiceImport (& clients [0 ], t .helloService .Name , false , nil )
322
302
323
303
Consistently (func () []string {
324
304
return t .getServiceImport (& clients [0 ], t .helloService .Name ).Spec .IPs
0 commit comments