Skip to content

Commit

Permalink
Merge pull request #2340 from keithmattix/mesh-conformance-ipv6
Browse files Browse the repository at this point in the history
Mesh Conformance IPv6 fix
  • Loading branch information
k8s-ci-robot authored Aug 23, 2023
2 parents 4ff1670 + 765116f commit e903291
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions conformance/utils/echo/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"fmt"
"net"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -56,12 +57,12 @@ const (
func (m *MeshPod) MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, exp http.ExpectedResponse, timeoutConfig config.TimeoutConfig) {
t.Helper()

req := makeRequest(exp.Request)

http.AwaitConvergence(t, timeoutConfig.RequiredConsecutiveSuccesses, timeoutConfig.MaxTimeToConsistency, func(elapsed time.Duration) bool {
resp, err := m.request(makeRequest(exp.Request))
req := makeRequest(exp.Request)

resp, err := m.request(req)
if err != nil {
t.Logf("Request failed, not ready yet: %v (after %v)", err.Error(), elapsed)
t.Logf("Request %v failed, not ready yet: %v (after %v)", req, err.Error(), elapsed)
return false
}
t.Logf("Got resp %v", resp)
Expand All @@ -80,7 +81,8 @@ func makeRequest(r http.Request) []string {
if protocol == "" {
protocol = "http"
}
args := []string{"client", fmt.Sprintf("%s://%s%s", protocol, r.Host, r.Path)}
host := calculateHost(r.Host, protocol)
args := []string{"client", fmt.Sprintf("%s://%s%s", protocol, host, r.Path)}
if r.Method != "" {
args = append(args, "--method="+r.Method)
}
Expand Down Expand Up @@ -111,6 +113,32 @@ func compareRequest(exp http.ExpectedResponse, resp Response) error {
return nil
}

// copied from conformance/http to get the ipv6 matching
func calculateHost(reqHost, scheme string) string {
host, port, err := net.SplitHostPort(reqHost)
if err != nil {
return reqHost
}
if strings.ToLower(scheme) == "http" && port == "80" {
return ipv6SafeHost(host)
}
if strings.ToLower(scheme) == "https" && port == "443" {
return ipv6SafeHost(host)
}
return reqHost
}

func ipv6SafeHost(host string) string {
// We assume that host is a literal IPv6 address if host has
// colons.
// Per https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2.
// This is like net.JoinHostPort, but we don't need a port.
if strings.Contains(host, ":") {
return "[" + host + "]"
}
return host
}

func (m *MeshPod) request(args []string) (Response, error) {
container := "echo"

Expand Down

0 comments on commit e903291

Please sign in to comment.