Skip to content

Commit

Permalink
Merge pull request #4721 from r-vasquez/fix-test-container-v2
Browse files Browse the repository at this point in the history
rpk: avoid duplicates in container port pool
  • Loading branch information
twmb committed May 16, 2022
2 parents 92d99d2 + 762153c commit afb2bd7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/go/rpk/pkg/net/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ func getFreePort() (uint, error) {
}

func GetFreePortPool(n int) ([]uint, error) {
var ports []uint
for i := 0; i < n; i++ {
m := make(map[uint]struct{})
for len(m) != n {
p, err := getFreePort()
if err != nil {
return nil, err
}
ports = append(ports, p)
m[p] = struct{}{}
}
var ports []uint
for port := range m {
ports = append(ports, port)
}
return ports, nil
}

0 comments on commit afb2bd7

Please sign in to comment.