Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #5588: Fix antctl traceflow using IPv6 address #5598

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/antctl/raw/traceflow/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ func jsonOutput(r *Response, writer io.Writer) error {
}

func getTFName(prefix string) string {
// prefix may contain IPv6 address. Replace "::" and ":" to make it a valid RFC 1123 subdomain.
prefix = strings.ReplaceAll(prefix, "::", "-")
prefix = strings.ReplaceAll(prefix, ":", "-")
if option.nowait {
return prefix
}
Expand Down
34 changes: 24 additions & 10 deletions pkg/antctl/raw/traceflow/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,18 +525,32 @@ func TestNewTraceflow(t *testing.T) {

func TestGetTFName(t *testing.T) {
tests := []struct {
name string
prefix string
nowait string
name string
prefix string
nowait string
expected string
}{
{
name: "nowait is true",
prefix: "traceflow",
nowait: "1",
name: "nowait is true",
prefix: "default-pod1-to-default-pod2",
nowait: "1",
expected: "default-pod1-to-default-pod2",
},
{
name: "nowait is false",
prefix: "traceflow",
name: "nowait is true and prefix contains IPv6",
prefix: "default-pod1-to-fc00:f853:ccd:e793::2",
nowait: "1",
expected: "default-pod1-to-fc00-f853-ccd-e793-2",
},
{
name: "nowait is false",
prefix: "default-pod1-to-default-pod2",
expected: "default-pod1-to-default-pod2",
},
{
name: "nowait is false and prefix contains IPv6",
prefix: "default-pod1-to-fc00:f853:ccd:e793::2",
expected: "default-pod1-to-fc00-f853-ccd-e793-2",
},
}

Expand All @@ -547,9 +561,9 @@ func TestGetTFName(t *testing.T) {

got := getTFName(tc.prefix)
if tc.nowait != "" {
assert.Equal(t, tc.prefix, got)
assert.Equal(t, tc.expected, got)
} else {
assert.Regexp(t, fmt.Sprintf("^%s-.{8}$", tc.prefix), got)
assert.Regexp(t, fmt.Sprintf("^%s-.{8}$", tc.expected), got)
}
})
}
Expand Down