@@ -18,10 +18,12 @@ package network
18
18
19
19
import (
20
20
"fmt"
21
+ "strings"
21
22
"time"
22
23
23
24
v1 "k8s.io/api/core/v1"
24
25
"k8s.io/apimachinery/pkg/util/sets"
26
+ "k8s.io/apimachinery/pkg/util/wait"
25
27
clientset "k8s.io/client-go/kubernetes"
26
28
cloudprovider "k8s.io/cloud-provider"
27
29
"k8s.io/kubernetes/pkg/master/ports"
@@ -160,7 +162,7 @@ var _ = SIGDescribe("Firewall rule", func() {
160
162
161
163
// Send requests from outside of the cluster because internal traffic is whitelisted
162
164
ginkgo .By ("Accessing the external service ip from outside, all non-master nodes should be reached" )
163
- err = framework . TestHitNodesFromOutside (svcExternalIP , firewallTestHTTPPort , e2eservice .LoadBalancerPropagationTimeoutDefault , nodesSet )
165
+ err = testHitNodesFromOutside (svcExternalIP , firewallTestHTTPPort , e2eservice .LoadBalancerPropagationTimeoutDefault , nodesSet )
164
166
framework .ExpectNoError (err )
165
167
166
168
// Check if there are overlapping tags on the firewall that extend beyond just the vms in our cluster
@@ -181,12 +183,12 @@ var _ = SIGDescribe("Firewall rule", func() {
181
183
nodesSet .Insert (nodesNames [0 ])
182
184
gce .SetInstanceTags (cloudConfig , nodesNames [0 ], zone , removedTags )
183
185
// Make sure traffic is recovered before exit
184
- err = framework . TestHitNodesFromOutside (svcExternalIP , firewallTestHTTPPort , e2eservice .LoadBalancerPropagationTimeoutDefault , nodesSet )
186
+ err = testHitNodesFromOutside (svcExternalIP , firewallTestHTTPPort , e2eservice .LoadBalancerPropagationTimeoutDefault , nodesSet )
185
187
framework .ExpectNoError (err )
186
188
}()
187
189
188
190
ginkgo .By ("Accessing serivce through the external ip and examine got no response from the node without tags" )
189
- err = framework . TestHitNodesFromOutsideWithCount (svcExternalIP , firewallTestHTTPPort , e2eservice .LoadBalancerPropagationTimeoutDefault , nodesSet , 15 )
191
+ err = testHitNodesFromOutsideWithCount (svcExternalIP , firewallTestHTTPPort , e2eservice .LoadBalancerPropagationTimeoutDefault , nodesSet , 15 )
190
192
framework .ExpectNoError (err )
191
193
})
192
194
@@ -228,3 +230,46 @@ func assertNotReachableHTTPTimeout(ip string, port int, timeout time.Duration) {
228
230
framework .Failf ("Was unexpectedly able to reach %s:%d" , ip , port )
229
231
}
230
232
}
233
+
234
+ // testHitNodesFromOutside checkes HTTP connectivity from outside.
235
+ func testHitNodesFromOutside (externalIP string , httpPort int32 , timeout time.Duration , expectedHosts sets.String ) error {
236
+ return testHitNodesFromOutsideWithCount (externalIP , httpPort , timeout , expectedHosts , 1 )
237
+ }
238
+
239
+ // testHitNodesFromOutsideWithCount checkes HTTP connectivity from outside with count.
240
+ func testHitNodesFromOutsideWithCount (externalIP string , httpPort int32 , timeout time.Duration , expectedHosts sets.String ,
241
+ countToSucceed int ) error {
242
+ framework .Logf ("Waiting up to %v for satisfying expectedHosts for %v times" , timeout , countToSucceed )
243
+ hittedHosts := sets .NewString ()
244
+ count := 0
245
+ condition := func () (bool , error ) {
246
+ result := framework .PokeHTTP (externalIP , int (httpPort ), "/hostname" , & framework.HTTPPokeParams {Timeout : 1 * time .Second })
247
+ if result .Status != framework .HTTPSuccess {
248
+ return false , nil
249
+ }
250
+
251
+ hittedHost := strings .TrimSpace (string (result .Body ))
252
+ if ! expectedHosts .Has (hittedHost ) {
253
+ framework .Logf ("Error hitting unexpected host: %v, reset counter: %v" , hittedHost , count )
254
+ count = 0
255
+ return false , nil
256
+ }
257
+ if ! hittedHosts .Has (hittedHost ) {
258
+ hittedHosts .Insert (hittedHost )
259
+ framework .Logf ("Missing %+v, got %+v" , expectedHosts .Difference (hittedHosts ), hittedHosts )
260
+ }
261
+ if hittedHosts .Equal (expectedHosts ) {
262
+ count ++
263
+ if count >= countToSucceed {
264
+ return true , nil
265
+ }
266
+ }
267
+ return false , nil
268
+ }
269
+
270
+ if err := wait .Poll (time .Second , timeout , condition ); err != nil {
271
+ return fmt .Errorf ("error waiting for expectedHosts: %v, hittedHosts: %v, count: %v, expected count: %v" ,
272
+ expectedHosts , hittedHosts , count , countToSucceed )
273
+ }
274
+ return nil
275
+ }
0 commit comments