@@ -160,12 +160,6 @@ type NetworkingTestConfig struct {
160
160
Namespace string
161
161
}
162
162
163
- // NetexecDialResponse represents the response returned by the `netexec` subcommand of `agnhost`
164
- type NetexecDialResponse struct {
165
- Responses []string `json:"responses"`
166
- Errors []string `json:"errors"`
167
- }
168
-
169
163
// DialFromEndpointContainer executes a curl via kubectl exec in an endpoint container.
170
164
func (config * NetworkingTestConfig ) DialFromEndpointContainer (protocol , targetIP string , targetPort , maxTries , minTries int , expectedEps sets.String ) {
171
165
config .DialFromContainer (protocol , echoHostname , config .EndpointPods [0 ].Status .PodIP , targetIP , EndpointHTTPPort , targetPort , maxTries , minTries , expectedEps )
@@ -218,18 +212,6 @@ func (config *NetworkingTestConfig) EndpointHostnames() sets.String {
218
212
return expectedEps
219
213
}
220
214
221
- func makeCURLDialCommand (ipPort , dialCmd , protocol , targetIP string , targetPort int ) string {
222
- // The current versions of curl included in CentOS and RHEL distros
223
- // misinterpret square brackets around IPv6 as globbing, so use the -g
224
- // argument to disable globbing to handle the IPv6 case.
225
- return fmt .Sprintf ("curl -g -q -s 'http://%s/dial?request=%s&protocol=%s&host=%s&port=%d&tries=1'" ,
226
- ipPort ,
227
- dialCmd ,
228
- protocol ,
229
- targetIP ,
230
- targetPort )
231
- }
232
-
233
215
// DialFromContainer executes a curl via kubectl exec in a test container,
234
216
// which might then translate to a tcp or udp request based on the protocol
235
217
// argument in the url.
@@ -250,19 +232,38 @@ func makeCURLDialCommand(ipPort, dialCmd, protocol, targetIP string, targetPort
250
232
// pod and confirm it doesn't show up as an endpoint.
251
233
func (config * NetworkingTestConfig ) DialFromContainer (protocol , dialCommand , containerIP , targetIP string , containerHTTPPort , targetPort , maxTries , minTries int , expectedResponses sets.String ) {
252
234
ipPort := net .JoinHostPort (containerIP , strconv .Itoa (containerHTTPPort ))
253
- cmd := makeCURLDialCommand (ipPort , dialCommand , protocol , targetIP , targetPort )
235
+ // The current versions of curl included in CentOS and RHEL distros
236
+ // misinterpret square brackets around IPv6 as globbing, so use the -g
237
+ // argument to disable globbing to handle the IPv6 case.
238
+ cmd := fmt .Sprintf ("curl -g -q -s 'http://%s/dial?request=%s&protocol=%s&host=%s&port=%d&tries=1'" ,
239
+ ipPort ,
240
+ dialCommand ,
241
+ protocol ,
242
+ targetIP ,
243
+ targetPort )
254
244
255
245
responses := sets .NewString ()
256
246
257
247
for i := 0 ; i < maxTries ; i ++ {
258
- resp , err := config .GetResponseFromContainer ( protocol , dialCommand , containerIP , targetIP , containerHTTPPort , targetPort )
248
+ stdout , stderr , err := config .f . ExecShellInPodWithFullOutput ( config . TestContainerPod . Name , cmd )
259
249
if err != nil {
260
- continue
261
- }
262
- for _ , response := range resp .Responses {
263
- trimmed := strings .TrimSpace (response )
264
- if trimmed != "" {
265
- responses .Insert (trimmed )
250
+ // A failure to kubectl exec counts as a try, not a hard fail.
251
+ // Also note that we will keep failing for maxTries in tests where
252
+ // we confirm unreachability.
253
+ framework .Logf ("Failed to execute %q: %v, stdout: %q, stderr %q" , cmd , err , stdout , stderr )
254
+ } else {
255
+ var output map [string ][]string
256
+ if err := json .Unmarshal ([]byte (stdout ), & output ); err != nil {
257
+ framework .Logf ("WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v" ,
258
+ cmd , config .HostTestContainerPod .Name , stdout , err )
259
+ continue
260
+ }
261
+
262
+ for _ , response := range output ["responses" ] {
263
+ trimmed := strings .TrimSpace (response )
264
+ if trimmed != "" {
265
+ responses .Insert (trimmed )
266
+ }
266
267
}
267
268
}
268
269
framework .Logf ("Waiting for responses: %v" , expectedResponses .Difference (responses ))
@@ -313,14 +314,14 @@ func (config *NetworkingTestConfig) GetEndpointsFromContainer(protocol, containe
313
314
framework .Logf ("Failed to execute %q: %v, stdout: %q, stderr: %q" , cmd , err , stdout , stderr )
314
315
} else {
315
316
framework .Logf ("Tries: %d, in try: %d, stdout: %v, stderr: %v, command run in: %#v" , tries , i , stdout , stderr , config .HostTestContainerPod )
316
- var output NetexecDialResponse
317
+ var output map [ string ][] string
317
318
if err := json .Unmarshal ([]byte (stdout ), & output ); err != nil {
318
319
framework .Logf ("WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v" ,
319
320
cmd , config .HostTestContainerPod .Name , stdout , err )
320
321
continue
321
322
}
322
323
323
- for _ , hostName := range output . Responses {
324
+ for _ , hostName := range output [ "responses" ] {
324
325
trimmed := strings .TrimSpace (hostName )
325
326
if trimmed != "" {
326
327
eps .Insert (trimmed )
@@ -333,34 +334,6 @@ func (config *NetworkingTestConfig) GetEndpointsFromContainer(protocol, containe
333
334
return eps , nil
334
335
}
335
336
336
- // GetResponseFromContainer executes a curl via kubectl exec in a container.
337
- func (config * NetworkingTestConfig ) GetResponseFromContainer (protocol , dialCommand , containerIP , targetIP string , containerHTTPPort , targetPort int ) (NetexecDialResponse , error ) {
338
- ipPort := net .JoinHostPort (containerIP , strconv .Itoa (containerHTTPPort ))
339
- cmd := makeCURLDialCommand (ipPort , dialCommand , protocol , targetIP , targetPort )
340
-
341
- stdout , stderr , err := config .f .ExecShellInPodWithFullOutput (config .TestContainerPod .Name , cmd )
342
- if err != nil {
343
- // A failure to kubectl exec counts as a try, not a hard fail.
344
- // Also note that we will keep failing for maxTries in tests where
345
- // we confirm unreachability.
346
- framework .Logf ("Failed to execute %q: %v, stdout: %q, stderr: %q" , cmd , err , stdout , stderr )
347
- return NetexecDialResponse {}, err
348
- }
349
-
350
- var output NetexecDialResponse
351
- if err := json .Unmarshal ([]byte (stdout ), & output ); err != nil {
352
- framework .Logf ("WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v" ,
353
- cmd , config .HostTestContainerPod .Name , stdout , err )
354
- return NetexecDialResponse {}, err
355
- }
356
- return output , nil
357
- }
358
-
359
- // GetResponseFromTestContainer executes a curl via kubectl exec in a test container.
360
- func (config * NetworkingTestConfig ) GetResponseFromTestContainer (protocol , dialCommand , targetIP string , targetPort int ) (NetexecDialResponse , error ) {
361
- return config .GetResponseFromContainer (protocol , dialCommand , config .TestContainerPod .Status .PodIP , targetIP , testContainerHTTPPort , targetPort )
362
- }
363
-
364
337
// DialFromNode executes a tcp or udp request based on protocol via kubectl exec
365
338
// in a test container running with host networking.
366
339
// - minTries is the minimum number of curl attempts required before declaring
0 commit comments