mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #34107 from MrHohn/e2e_sourceip_fix
Automatic merge from submit-queue Fix #31085, include output checking in retry loop Fix #31085. `wget -qO-` might omit the error and `RunHostCmd()` won't be able to catch it sometimes. Verify stdout is not empty within the retry loop to fix. Test passed 1500+ times in a row. @freehan
This commit is contained in:
		@@ -267,7 +267,7 @@ var _ = framework.KubeDescribe("Services", func() {
 | 
				
			|||||||
			Expect(err).NotTo(HaveOccurred())
 | 
								Expect(err).NotTo(HaveOccurred())
 | 
				
			||||||
		}()
 | 
							}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Waiting for service to expose endpoint
 | 
							// Waiting for service to expose endpoint.
 | 
				
			||||||
		validateEndpointsOrFail(c, ns, serviceName, PortsByPodName{serverPodName: {servicePort}})
 | 
							validateEndpointsOrFail(c, ns, serviceName, PortsByPodName{serverPodName: {servicePort}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		By("Retrieve sourceip from a pod on the same node")
 | 
							By("Retrieve sourceip from a pod on the same node")
 | 
				
			||||||
@@ -2332,25 +2332,32 @@ func execSourceipTest(f *framework.Framework, c *client.Client, ns, nodeName, se
 | 
				
			|||||||
	timeout := 2 * time.Minute
 | 
						timeout := 2 * time.Minute
 | 
				
			||||||
	framework.Logf("Waiting up to %v for sourceIp test to be executed", timeout)
 | 
						framework.Logf("Waiting up to %v for sourceIp test to be executed", timeout)
 | 
				
			||||||
	cmd := fmt.Sprintf(`wget -T 30 -qO- %s:%d | grep client_address`, serviceIp, servicePort)
 | 
						cmd := fmt.Sprintf(`wget -T 30 -qO- %s:%d | grep client_address`, serviceIp, servicePort)
 | 
				
			||||||
	// need timeout mechanism because it may takes more times for iptables to be populated
 | 
						// Need timeout mechanism because it may takes more times for iptables to be populated.
 | 
				
			||||||
	for start := time.Now(); time.Since(start) < timeout; time.Sleep(2) {
 | 
						for start := time.Now(); time.Since(start) < timeout; time.Sleep(2) {
 | 
				
			||||||
		stdout, err = framework.RunHostCmd(execPod.Namespace, execPod.Name, cmd)
 | 
							stdout, err = framework.RunHostCmd(execPod.Namespace, execPod.Name, cmd)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			framework.Logf("got err: %v, retry until timeout", err)
 | 
								framework.Logf("got err: %v, retry until timeout", err)
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							// Need to check output because wget -q might omit the error.
 | 
				
			||||||
 | 
							if strings.TrimSpace(stdout) == "" {
 | 
				
			||||||
 | 
								framework.Logf("got empty stdout, retry until timeout")
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		break
 | 
							break
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ExpectNoError(err)
 | 
						ExpectNoError(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// the stdout return from RunHostCmd seems to come with "\n", so TrimSpace is needed
 | 
						// The stdout return from RunHostCmd seems to come with "\n", so TrimSpace is needed.
 | 
				
			||||||
	// desired stdout in this format: client_address=x.x.x.x
 | 
						// Desired stdout in this format: client_address=x.x.x.x
 | 
				
			||||||
	outputs := strings.Split(strings.TrimSpace(stdout), "=")
 | 
						outputs := strings.Split(strings.TrimSpace(stdout), "=")
 | 
				
			||||||
 | 
						sourceIp := ""
 | 
				
			||||||
	if len(outputs) != 2 {
 | 
						if len(outputs) != 2 {
 | 
				
			||||||
		// fail the test if output format is unexpected
 | 
							// Fail the test if output format is unexpected.
 | 
				
			||||||
		framework.Failf("exec pod returned unexpected stdout format: [%v]\n", stdout)
 | 
							framework.Failf("exec pod returned unexpected stdout format: [%v]\n", stdout)
 | 
				
			||||||
		return execPodIp, ""
 | 
						} else {
 | 
				
			||||||
 | 
							sourceIp = outputs[1]
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return execPodIp, outputs[1]
 | 
						return execPodIp, sourceIp
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user