Skip to content

Commit

Permalink
Fix antctl traceflow using IPv6 address (#5598)
Browse files Browse the repository at this point in the history
Fixes #5541

Signed-off-by: Kumar Atish <[email protected]>
  • Loading branch information
Atish-iaf authored Oct 18, 2023
1 parent 3a25934 commit fce7bc2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
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

0 comments on commit fce7bc2

Please sign in to comment.