Merge pull request #54686 from m1093782566/gce-alpha-fail

Automatic merge from submit-queue (batch tested with PRs 54572, 54686). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix service session affinity e2e failure cases

**What this PR does / why we need it**:

Fix service session affinity e2e failure cases - debuging...

**Which issue this PR fixes**:

xref #54571 #54524

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```

/sig network
This commit is contained in:
Kubernetes Submit Queue 2017-10-30 21:45:17 -07:00 committed by GitHub
commit d118e44320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 34 deletions

View File

@ -226,8 +226,8 @@ func (config *NetworkingTestConfig) GetEndpointsFromTestContainer(protocol, targ
// GetEndpointsFromContainer executes a curl via kubectl exec in a test container,
// which might then translate to a tcp or udp request based on the protocol argument
// in the url.
// - tries is the maximum number of curl attempts. If this many attempts pass and
// in the url. It returns all different endpoints from multiple retries.
// - tries is the number of curl attempts. If this many attempts pass and
// we don't see any endpoints, the test fails.
func (config *NetworkingTestConfig) GetEndpointsFromContainer(protocol, containerIP, targetIP string, containerHttpPort, targetPort, tries int) (sets.String, error) {
cmd := fmt.Sprintf("curl -q -s 'http://%s:%d/dial?request=hostName&protocol=%s&host=%s&port=%d&tries=1'",
@ -247,7 +247,7 @@ func (config *NetworkingTestConfig) GetEndpointsFromContainer(protocol, containe
// we confirm unreachability.
Logf("Failed to execute %q: %v, stdout: %q, stderr: %q", cmd, err, stdout, stderr)
} else {
Logf("maxTries: %d, in try: %d, stdout: %v, stderr: %v", tries, i, stdout, stderr)
Logf("Tries: %d, in try: %d, stdout: %v, stderr: %v, command run in: %#v", tries, i, stdout, stderr, config.HostTestContainerPod)
var output map[string][]string
if err := json.Unmarshal([]byte(stdout), &output); err != nil {
Logf("WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v",
@ -261,15 +261,11 @@ func (config *NetworkingTestConfig) GetEndpointsFromContainer(protocol, containe
eps.Insert(trimmed)
}
}
// Return immediately when we successfully fetch endpoints
if len(eps) > 0 {
return eps, nil
}
// TODO: get rid of this delay #36281
time.Sleep(hitEndpointRetryDelay)
}
}
return nil, fmt.Errorf("error getting endpoints:\nTries %d\nCommand %v\n", tries, cmd)
return eps, nil
}
// DialFromNode executes a tcp or udp request based on protocol via kubectl exec

View File

@ -201,7 +201,7 @@ var _ = SIGDescribe("Networking", func() {
config.DialFromNode("udp", config.NodeIP, config.NodeUdpPort, config.MaxTries, config.MaxTries, sets.NewString())
})
It("should function for client IP based session affinity: http", func() {
It("should function for client IP based session affinity: http [Slow]", func() {
config := framework.NewNetworkingTestConfig(f)
By(fmt.Sprintf("dialing(http) %v --> %v:%v (config.clusterIP)", config.TestContainerPod.Name, config.ClusterIP, framework.ClusterHttpPort))
updateSessionAffinity := func(svc *v1.Service) {
@ -212,24 +212,20 @@ var _ = SIGDescribe("Networking", func() {
framework.Failf("Failed to update service session affinity, error: %v", err)
}
// Fetch first endpoints when visiting service
firstEndpoints, err := config.GetEndpointsFromTestContainer("http", config.ClusterIP, framework.ClusterHttpPort, config.MaxTries)
// Check if number of endpoints returned are exactly one.
eps, err := config.GetEndpointsFromTestContainer("http", config.ClusterIP, framework.ClusterHttpPort, framework.SessionAffinityChecks)
if err != nil {
framework.Failf("Unable to get endpoints from test container: %v", err)
framework.Failf("Failed to get endpoints from test container, error: %v", err)
}
// Check if first endpoints are equal to endpoints which are fetched later
for i := 0; i < framework.SessionAffinityChecks; i++ {
eps, err := config.GetEndpointsFromTestContainer("http", config.ClusterIP, framework.ClusterHttpPort, config.MaxTries)
if err != nil {
framework.Failf("Unable to get endpoints from test container: %v", err)
}
if !eps.Equal(firstEndpoints) {
framework.Failf("Expect endpoints: %v, got: %v", firstEndpoints, eps)
if len(eps) == 0 {
framework.Failf("Unexpected no endpoints return")
}
if len(eps) > 1 {
framework.Failf("Unexpected endpoints return: %v, expect 1 endpoints", eps)
}
})
It("should function for client IP based session affinity: udp", func() {
It("should function for client IP based session affinity: udp [Slow]", func() {
config := framework.NewNetworkingTestConfig(f)
By(fmt.Sprintf("dialing(udp) %v --> %v:%v (config.clusterIP)", config.TestContainerPod.Name, config.ClusterIP, framework.ClusterUdpPort))
updateSessionAffinity := func(svc *v1.Service) {
@ -240,20 +236,16 @@ var _ = SIGDescribe("Networking", func() {
framework.Failf("Failed to update service session affinity, error: %v", err)
}
// Fetch first endpoints when visiting service
firstEndpoints, err := config.GetEndpointsFromTestContainer("udp", config.ClusterIP, framework.ClusterUdpPort, config.MaxTries)
// Check if number of endpoints returned are exactly one.
eps, err := config.GetEndpointsFromTestContainer("udp", config.ClusterIP, framework.ClusterUdpPort, framework.SessionAffinityChecks)
if err != nil {
framework.Failf("Unable to get endpoints from test containers: %v", err)
framework.Failf("Failed to get endpoints from test container, error: %v", err)
}
// Check if first endpoints are equal to endpoints which are fetched later
for i := 0; i < framework.SessionAffinityChecks; i++ {
eps, err := config.GetEndpointsFromTestContainer("udp", config.ClusterIP, framework.ClusterUdpPort, config.MaxTries)
if err != nil {
framework.Failf("Unable to get endpoints from test containers: %v", err)
}
if !eps.Equal(firstEndpoints) {
framework.Failf("Expect endpoints: %v, got: %v", firstEndpoints, eps)
if len(eps) == 0 {
framework.Failf("Unexpected no endpoints return")
}
if len(eps) > 1 {
framework.Failf("Unexpected endpoints return: %v, expect 1 endpoints", eps)
}
})
})