@@ -271,19 +271,80 @@ func makeNamespaceGlobal(ns *corev1.Namespace) {
271
271
expectNoError (err )
272
272
}
273
273
274
- func checkPodIsolation (f1 , f2 * e2e.Framework , nodeType NodeType ) error {
275
- nodes := e2e .GetReadySchedulableNodesOrDie (f1 .ClientSet )
276
- var serverNode , clientNode * corev1.Node
277
- serverNode = & nodes .Items [0 ]
274
+ func makeNamespaceScheduleToAllNodes (f * e2e.Framework ) {
275
+ // to avoid hassles dealing with selector limits, set the namespace label selector to empty
276
+ // to allow targeting all nodes
277
+ for {
278
+ ns , err := f .ClientSet .CoreV1 ().Namespaces ().Get (f .Namespace .Name , metav1.GetOptions {})
279
+ expectNoError (err )
280
+ ns .Annotations ["openshift.io/node-selector" ] = ""
281
+ _ , err = f .ClientSet .CoreV1 ().Namespaces ().Update (ns )
282
+ if err == nil {
283
+ return
284
+ }
285
+ if kapierrs .IsConflict (err ) {
286
+ continue
287
+ }
288
+ expectNoError (err )
289
+ }
290
+ }
291
+
292
+ // findAppropriateNodes tries to find a source and destination for a type of node connectivity
293
+ // test (same node, or different node).
294
+ func findAppropriateNodes (f * e2e.Framework , nodeType NodeType ) (* corev1.Node , * corev1.Node ) {
295
+ nodes := e2e .GetReadySchedulableNodesOrDie (f .ClientSet )
296
+ candidates := nodes .Items
297
+
298
+ if len (candidates ) == 0 {
299
+ e2e .Failf ("Unable to find any candidate nodes for e2e networking tests in \n %#v" , nodes .Items )
300
+ }
301
+
302
+ // in general, avoiding masters is a good thing, so see if we can find nodes that aren't masters
303
+ if len (candidates ) > 1 {
304
+ var withoutMasters []corev1.Node
305
+ // look for anything that has the label value master or infra and try to skip it
306
+ isAllowed := func (node * corev1.Node ) bool {
307
+ for _ , value := range node .Labels {
308
+ if value == "master" || value == "infra" {
309
+ return false
310
+ }
311
+ }
312
+ return true
313
+ }
314
+ for _ , node := range candidates {
315
+ if ! isAllowed (& node ) {
316
+ continue
317
+ }
318
+ withoutMasters = append (withoutMasters , node )
319
+ }
320
+ if len (withoutMasters ) >= 2 {
321
+ candidates = withoutMasters
322
+ }
323
+ }
324
+
325
+ var candidateNames , nodeNames []string
326
+ for _ , node := range candidates {
327
+ candidateNames = append (candidateNames , node .Name )
328
+ }
329
+ for _ , node := range nodes .Items {
330
+ nodeNames = append (nodeNames , node .Name )
331
+ }
332
+
278
333
if nodeType == DIFFERENT_NODE {
279
- if len (nodes . Items ) = = 1 {
280
- e2e .Skipf ("Only one node is available in this environment" )
334
+ if len (candidates ) < = 1 {
335
+ e2e .Skipf ("Only one node is available in this environment (%v out of %v)" , candidateNames , nodeNames )
281
336
}
282
- clientNode = & nodes .Items [1 ]
283
- } else {
284
- clientNode = serverNode
337
+ e2e .Logf ("Using %s and %s for test (%v out of %v)" , candidates [0 ].Name , candidates [1 ].Name , candidateNames , nodeNames )
338
+ return & candidates [0 ], & candidates [1 ]
285
339
}
340
+ e2e .Logf ("Using %s for test (%v out of %v)" , candidates [0 ].Name , candidateNames , nodeNames )
341
+ return & candidates [0 ], & candidates [0 ]
342
+ }
286
343
344
+ func checkPodIsolation (f1 , f2 * e2e.Framework , nodeType NodeType ) error {
345
+ makeNamespaceScheduleToAllNodes (f1 )
346
+ makeNamespaceScheduleToAllNodes (f2 )
347
+ serverNode , clientNode := findAppropriateNodes (f1 , nodeType )
287
348
podName := "isolation-webserver"
288
349
defer f1 .ClientSet .CoreV1 ().Pods (f1 .Namespace .Name ).Delete (podName , nil )
289
350
ip := e2e .LaunchWebserverPod (f1 , podName , serverNode .Name )
@@ -292,18 +353,9 @@ func checkPodIsolation(f1, f2 *e2e.Framework, nodeType NodeType) error {
292
353
}
293
354
294
355
func checkServiceConnectivity (serverFramework , clientFramework * e2e.Framework , nodeType NodeType ) error {
295
- nodes := e2e .GetReadySchedulableNodesOrDie (serverFramework .ClientSet )
296
- var serverNode , clientNode * corev1.Node
297
- serverNode = & nodes .Items [0 ]
298
- if nodeType == DIFFERENT_NODE {
299
- if len (nodes .Items ) == 1 {
300
- e2e .Skipf ("Only one node is available in this environment" )
301
- }
302
- clientNode = & nodes .Items [1 ]
303
- } else {
304
- clientNode = serverNode
305
- }
306
-
356
+ makeNamespaceScheduleToAllNodes (serverFramework )
357
+ makeNamespaceScheduleToAllNodes (clientFramework )
358
+ serverNode , clientNode := findAppropriateNodes (serverFramework , nodeType )
307
359
podName := kapiv1 .SimpleNameGenerator .GenerateName ("service-" )
308
360
defer serverFramework .ClientSet .CoreV1 ().Pods (serverFramework .Namespace .Name ).Delete (podName , nil )
309
361
defer serverFramework .ClientSet .CoreV1 ().Services (serverFramework .Namespace .Name ).Delete (podName , nil )
0 commit comments