Skip to content

Commit

Permalink
istioctl miss to append ipv6 domain when using istioctl pc route (ist…
Browse files Browse the repository at this point in the history
…io#38262)

* istioctl miss to append ipv6 domain when using istioctl pc route

* add test case for describeRouteDomains
  • Loading branch information
zhlsunshine authored Apr 7, 2022
1 parent e35397b commit b53d35d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions istioctl/pkg/writer/envoy/configdump/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func describeRouteDomains(domains []string) string {
for _, d := range domains {
if !strings.Contains(d, ":") {
withoutPort = append(withoutPort, d)
// if the domain contains IPv6, such as [fd00:10:96::7fc7] and [fd00:10:96::7fc7]:8090
} else if strings.Count(d, ":") > 2 {
// if the domain is only a IPv6 address, such as [fd00:10:96::7fc7], append it
if strings.HasSuffix(d, "]") {
withoutPort = append(withoutPort, d)
}
}
}
withoutPort = unexpandDomains(withoutPort)
Expand Down
51 changes: 51 additions & 0 deletions istioctl/pkg/writer/envoy/configdump/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,54 @@
// limitations under the License.

package configdump

import (
"testing"
)

func TestDescribeRouteDomains(t *testing.T) {
tests := []struct {
desc string
domains []string
expected string
}{
{
desc: "test zero domain",
domains: []string{},
expected: "",
},
{
desc: "test only one domain",
domains: []string{"example.com"},
expected: "example.com",
},
{
desc: "test domains with port",
domains: []string{"example.com", "example.com:8080"},
expected: "example.com",
},
{
desc: "test domains with ipv4 addresses",
domains: []string{"example.com", "example.com:8080", "1.2.3.4", "1.2.3.4:8080"},
expected: "example.com, 1.2.3.4",
},
{
desc: "test domains with ipv6 addresses",
domains: []string{"example.com", "example.com:8080", "[fd00:10:96::7fc7]", "[fd00:10:96::7fc7]:8080"},
expected: "example.com, [fd00:10:96::7fc7]",
},
{
desc: "test with more domains",
domains: []string{"example.com", "example.com:8080", "www.example.com", "www.example.com:8080", "[fd00:10:96::7fc7]", "[fd00:10:96::7fc7]:8080"},
expected: "example.com, www.example.com + 1 more...",
},
}

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
if got := describeRouteDomains(tt.domains); got != tt.expected {
t.Errorf("%s: expect %v got %v", tt.desc, tt.expected, got)
}
})
}
}

0 comments on commit b53d35d

Please sign in to comment.