@@ -18,7 +18,6 @@ package network
18
18
19
19
import (
20
20
"context"
21
- "encoding/hex"
22
21
"fmt"
23
22
"math"
24
23
"net"
@@ -35,6 +34,7 @@ import (
35
34
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
36
35
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
37
36
imageutils "k8s.io/kubernetes/test/utils/image"
37
+ netutils "k8s.io/utils/net"
38
38
39
39
"github.com/onsi/ginkgo"
40
40
"github.com/onsi/gomega"
@@ -81,8 +81,6 @@ var _ = SIGDescribe("Network", func() {
81
81
}
82
82
83
83
// Create a pod to check the conntrack entries on the host node
84
- // It mounts the host /proc/net folder to be able to access
85
- // the nf_conntrack file with the host conntrack entries
86
84
privileged := true
87
85
88
86
hostExecPod := & v1.Pod {
@@ -97,43 +95,17 @@ var _ = SIGDescribe("Network", func() {
97
95
Containers : []v1.Container {
98
96
{
99
97
Name : "e2e-net-exec" ,
100
- Image : kubeProxyE2eImage ,
98
+ Image : imageutils . GetE2EImage ( imageutils . DebianIptables ) ,
101
99
ImagePullPolicy : v1 .PullIfNotPresent ,
102
- Args : []string {"pause" },
103
- VolumeMounts : []v1.VolumeMount {
104
- {
105
- Name : "proc-net" ,
106
- MountPath : "/rootfs/proc/net" ,
107
- ReadOnly : true ,
108
- },
109
- },
100
+ Command : []string {"sleep" , "600" },
110
101
SecurityContext : & v1.SecurityContext {
111
102
Privileged : & privileged ,
112
103
},
113
104
},
114
105
},
115
- Volumes : []v1.Volume {
116
- {
117
- Name : "proc-net" ,
118
- VolumeSource : v1.VolumeSource {
119
- HostPath : & v1.HostPathVolumeSource {
120
- Path : "/proc/net" ,
121
- },
122
- },
123
- },
124
- },
125
106
},
126
107
}
127
108
fr .PodClient ().CreateSync (hostExecPod )
128
- defer fr .PodClient ().DeleteSync (hostExecPod .Name , metav1.DeleteOptions {}, framework .DefaultPodDeletionTimeout )
129
-
130
- // Some distributions (Ubuntu 16.04 etc.) don't support the proc file.
131
- _ , err = framework .RunHostCmd (fr .Namespace .Name , "e2e-net-exec" ,
132
- "ls /rootfs/proc/net/nf_conntrack" )
133
- if err != nil && strings .Contains (err .Error (), "No such file or directory" ) {
134
- e2eskipper .Skipf ("The node %s does not support /proc/net/nf_conntrack" , clientNodeInfo .name )
135
- }
136
- framework .ExpectNoError (err )
137
109
138
110
// Create the client and server pods
139
111
clientPodSpec := & v1.Pod {
@@ -202,7 +174,6 @@ var _ = SIGDescribe("Network", func() {
202
174
serverNodeInfo .nodeIP ,
203
175
kubeProxyE2eImage ))
204
176
fr .PodClient ().CreateSync (serverPodSpec )
205
- defer fr .PodClient ().DeleteSync (serverPodSpec .Name , metav1.DeleteOptions {}, framework .DefaultPodDeletionTimeout )
206
177
207
178
// The server should be listening before spawning the client pod
208
179
if readyErr := e2epod .WaitForPodsReady (fr .ClientSet , fr .Namespace .Name , serverPodSpec .Name , 0 ); readyErr != nil {
@@ -215,22 +186,25 @@ var _ = SIGDescribe("Network", func() {
215
186
clientNodeInfo .nodeIP ,
216
187
kubeProxyE2eImage ))
217
188
fr .PodClient ().CreateSync (clientPodSpec )
218
- defer fr .PodClient ().DeleteSync (clientPodSpec .Name , metav1.DeleteOptions {}, framework .DefaultPodDeletionTimeout )
219
189
220
- ginkgo .By ("Checking /proc/net/nf_conntrack for the timeout" )
190
+ ginkgo .By ("Checking conntrack entries for the timeout" )
221
191
// These must be synchronized from the default values set in
222
192
// pkg/apis/../defaults.go ConntrackTCPCloseWaitTimeout. The
223
193
// current defaults are hidden in the initialization code.
224
194
const epsilonSeconds = 60
225
195
const expectedTimeoutSeconds = 60 * 60
226
196
// the conntrack file uses the IPv6 expanded format
227
- ip := fullIPv6 (net .ParseIP (serverNodeInfo .nodeIP ))
197
+ ip := serverNodeInfo .nodeIP
198
+ ipFamily := "ipv4"
199
+ if netutils .IsIPv6String (ip ) {
200
+ ipFamily = "ipv6"
201
+ }
228
202
// Obtain the corresponding conntrack entry on the host checking
229
203
// the nf_conntrack file from the pod e2e-net-exec.
230
204
// It retries in a loop if the entry is not found.
231
- cmd := fmt .Sprintf ("cat /rootfs/proc/net/nf_conntrack " +
232
- "| grep -m 1 'CLOSE_WAIT.*dst=%v.* dport=%v' " ,
233
- ip , testDaemonTCPPort )
205
+ cmd := fmt .Sprintf ("conntrack -L -f %s -d %v " +
206
+ "| grep -m 1 'CLOSE_WAIT.*dport=%v' " ,
207
+ ipFamily , ip , testDaemonTCPPort )
234
208
if err := wait .PollImmediate (1 * time .Second , postFinTimeoutSeconds , func () (bool , error ) {
235
209
result , err := framework .RunHostCmd (fr .Namespace .Name , "e2e-net-exec" , cmd )
236
210
// retry if we can't obtain the conntrack entry
@@ -239,15 +213,14 @@ var _ = SIGDescribe("Network", func() {
239
213
return false , nil
240
214
}
241
215
framework .Logf ("conntrack entry for node %v and port %v: %v" , serverNodeInfo .nodeIP , testDaemonTCPPort , result )
242
- // Timeout in seconds is available as the fifth column of
243
- // the matched entry in /proc/net/nf_conntrack.
216
+ // Timeout in seconds is available as the third column of the matched entry
244
217
line := strings .Fields (result )
245
- if len (line ) < 5 {
218
+ if len (line ) < 3 {
246
219
return false , fmt .Errorf ("conntrack entry does not have a timeout field: %v" , line )
247
220
}
248
- timeoutSeconds , err := strconv .Atoi (line [4 ])
221
+ timeoutSeconds , err := strconv .Atoi (line [2 ])
249
222
if err != nil {
250
- return false , fmt .Errorf ("failed to convert matched timeout %s to integer: %v" , line [4 ], err )
223
+ return false , fmt .Errorf ("failed to convert matched timeout %s to integer: %v" , line [2 ], err )
251
224
}
252
225
if math .Abs (float64 (timeoutSeconds - expectedTimeoutSeconds )) < epsilonSeconds {
253
226
return true , nil
@@ -372,22 +345,3 @@ var _ = SIGDescribe("Network", func() {
372
345
}
373
346
})
374
347
})
375
-
376
- // fullIPv6 returns a string with the IP representation
377
- // if IPv6 it returns the expanded address format
378
- // credit https://stackoverflow.com/a/52003106/4532704
379
- func fullIPv6 (ip net.IP ) string {
380
- if ip .To4 () == nil {
381
- dst := make ([]byte , hex .EncodedLen (len (ip )))
382
- _ = hex .Encode (dst , ip )
383
- return string (dst [0 :4 ]) + ":" +
384
- string (dst [4 :8 ]) + ":" +
385
- string (dst [8 :12 ]) + ":" +
386
- string (dst [12 :16 ]) + ":" +
387
- string (dst [16 :20 ]) + ":" +
388
- string (dst [20 :24 ]) + ":" +
389
- string (dst [24 :28 ]) + ":" +
390
- string (dst [28 :])
391
- }
392
- return ip .String ()
393
- }
0 commit comments