@@ -33,10 +33,7 @@ func Test_E2EPoliciesAndFirewall(t *testing.T) {
33
33
RunSpecs (t , "Services Traffic Policies and Firewall config Suite" , suiteConfig , reporterConfig )
34
34
}
35
35
36
- var (
37
- tc * e2e.TestConfig
38
- nodes []e2e.Node
39
- )
36
+ var tc * e2e.TestConfig
40
37
41
38
var _ = ReportAfterEach (e2e .GenReport )
42
39
@@ -88,16 +85,17 @@ var _ = Describe("Verify Services Traffic policies and firewall config", Ordered
88
85
for _ , pod := range pods {
89
86
if strings .Contains (pod .Name , "test-loadbalancer-ext" ) {
90
87
serverNodeName = pod .Spec .NodeName
91
- break
92
88
}
93
89
}
94
90
return serverNodeName , nil
95
91
}, "25s" , "5s" ).ShouldNot (BeEmpty (), "server pod not found" )
96
92
97
93
var serverNodeIP string
98
- for _ , node := range nodes {
94
+ nodeIPs , err := e2e .GetNodeIPs (tc .KubeconfigFile )
95
+ Expect (err ).NotTo (HaveOccurred (), "failed to get node IPs" )
96
+ for _ , node := range nodeIPs {
99
97
if node .Name == serverNodeName {
100
- serverNodeIP = node .InternalIP
98
+ serverNodeIP = node .IPv4
101
99
}
102
100
}
103
101
@@ -136,19 +134,6 @@ var _ = Describe("Verify Services Traffic policies and firewall config", Ordered
136
134
cmd := "curl -m 5 -s -f http://" + lbSvcExtExternalIPs [0 ] + ":82/ip"
137
135
return e2e .RunCommand (cmd )
138
136
}, "25s" , "5s" ).ShouldNot (ContainSubstring ("10.42" ))
139
-
140
- // Verify connectivity to the other nodeIP does not work because of external traffic policy=local
141
- for _ , externalIP := range lbSvcExternalIPs {
142
- if externalIP == lbSvcExtExternalIPs [0 ] {
143
- // This IP we already test and it shuold work
144
- continue
145
- }
146
- Eventually (func () error {
147
- cmd := "curl -m 5 -s -f http://" + externalIP + ":82/ip"
148
- _ , err := e2e .RunCommand (cmd )
149
- return err
150
- }, "40s" , "5s" ).Should (MatchError (ContainSubstring ("exit status" )))
151
- }
152
137
})
153
138
154
139
// Verifies that the internal traffic policy=local is deployed
@@ -260,29 +245,31 @@ var _ = Describe("Verify Services Traffic policies and firewall config", Ordered
260
245
apiVersion: v1
261
246
kind: Service
262
247
metadata:
263
- name: nginx-loadbalancer-svc-ext-firewall
248
+ name: nginx-loadbalancer-svc-ext-firewall
264
249
spec:
265
- type: LoadBalancer
266
- loadBalancerSourceRanges:
267
- - {{.NodeIP}}/32
268
- ports:
269
- - port: 82
270
- targetPort: 80
271
- protocol: TCP
272
- name: http
273
- selector:
274
- k8s-app: nginx-app-loadbalancer-ext
250
+ type: LoadBalancer
251
+ loadBalancerSourceRanges:
252
+ - {{.NodeIP}}/32
253
+ ports:
254
+ - port: 82
255
+ targetPort: 80
256
+ protocol: TCP
257
+ name: http
258
+ selector:
259
+ k8s-app: nginx-app-loadbalancer-ext
275
260
`
276
261
// Remove the service nginx-loadbalancer-svc-ext
277
- _ , err := e2e .RunCommand ("kubectl delete svc nginx-loadbalancer-svc-ext" )
262
+ _ , err := e2e .RunCommand ("kubectl --kubeconfig=" + tc . KubeconfigFile + " delete svc nginx-loadbalancer-svc-ext" )
278
263
Expect (err ).NotTo (HaveOccurred (), "failed to remove service nginx-loadbalancer-svc-ext" )
279
264
280
265
// Parse and execute the template with the node IP
281
266
tmpl , err := template .New ("service" ).Parse (serviceManifest )
282
267
Expect (err ).NotTo (HaveOccurred ())
283
268
269
+ nodeIPs , err := e2e .GetNodeIPs (tc .KubeconfigFile )
270
+ Expect (err ).NotTo (HaveOccurred ())
284
271
var filledManifest strings.Builder
285
- err = tmpl .Execute (& filledManifest , struct { NodeIP string }{NodeIP : nodes [0 ].InternalIP })
272
+ err = tmpl .Execute (& filledManifest , struct { NodeIP string }{NodeIP : nodeIPs [0 ].IPv4 })
286
273
Expect (err ).NotTo (HaveOccurred ())
287
274
288
275
// Write the filled manifest to a temporary file
@@ -307,29 +294,31 @@ selector:
307
294
308
295
// Verify that only the allowed node can curl. That node should be able to curl both externalIPs (i.e. node.InternalIP)
309
296
It ("Verify firewall is working" , func () {
310
- for _ , node := range nodes {
311
- var sNode , aNode e2e.VagrantNode
312
- for _ , n := range tc .Servers {
313
- if n .String () == nodes [0 ].Name {
314
- sNode = n
315
- }
316
- }
317
- for _ , n := range tc .Agents {
318
- if n .String () == nodes [1 ].Name {
319
- aNode = n
320
- }
321
- }
297
+ nodeIPs , err := e2e .GetNodeIPs (tc .KubeconfigFile )
298
+ Expect (err ).NotTo (HaveOccurred ())
322
299
300
+ var firstNode e2e.VagrantNode
301
+ var secondNode e2e.VagrantNode
302
+ for _ , node := range tc .AllNodes () {
303
+ if node .String () == nodeIPs [0 ].Name {
304
+ firstNode = node
305
+ } else {
306
+ secondNode = node
307
+ }
308
+ }
309
+ fmt .Println ("First node: " , firstNode .String ())
310
+ fmt .Println ("Second node: " , secondNode .String ())
311
+ for _ , ip := range nodeIPs {
323
312
// Verify connectivity from nodes[0] works because we passed its IP to the loadBalancerSourceRanges
324
313
Eventually (func () (string , error ) {
325
- cmd := "curl -m 5 -s -f http://" + node . InternalIP + ":82"
326
- return sNode .RunCmdOnNode (cmd )
314
+ cmd := "curl -m 5 -s -f http:// " + ip . IPv4 + ":82"
315
+ return firstNode .RunCmdOnNode (cmd )
327
316
}, "40s" , "5s" ).Should (ContainSubstring ("Welcome to nginx" ))
328
317
329
318
// Verify connectivity from nodes[1] fails because we did not pass its IP to the loadBalancerSourceRanges
330
319
Eventually (func (g Gomega ) error {
331
- cmd := "curl -m 5 -s -f http:// " + node . InternalIP + ":82"
332
- _ , err := aNode .RunCmdOnNode (cmd )
320
+ cmd := "curl -m 5 -s -f http:// " + ip . IPv4 + ":82"
321
+ _ , err := secondNode .RunCmdOnNode (cmd )
333
322
return err
334
323
}, "40s" , "5s" ).Should (MatchError (ContainSubstring ("exit status" )))
335
324
}
@@ -344,7 +333,7 @@ var _ = AfterEach(func() {
344
333
345
334
var _ = AfterSuite (func () {
346
335
if failed {
347
- AddReportEntry ( "journald-logs" , e2e .TailJournalLogs ( 1000 , tc .AllNodes ()))
336
+ Expect ( e2e .SaveJournalLogs ( tc .AllNodes ())). To ( Succeed ( ))
348
337
} else {
349
338
Expect (e2e .GetCoverageReport (tc .AllNodes ())).To (Succeed ())
350
339
}
0 commit comments