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

fixes auto_join for mDNS provider #25080

Merged
merged 8 commits into from
Jun 10, 2024
13 changes: 12 additions & 1 deletion vault/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"encoding/base64"
"errors"
"fmt"
"net"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -1230,9 +1232,18 @@ func (c *Core) raftLeaderInfo(leaderInfo *raft.LeaderJoinInfo, disco *discover.D
return nil, fmt.Errorf("failed to parse addresses from auto-join metadata: %w", err)
}
for _, ip := range clusterIPs {
if strings.Count(ip, ":") >= 2 && !strings.HasPrefix(ip, "[") {
if count := strings.Count(ip, ":"); count >= 2 && !strings.HasPrefix(ip, "[") {
// An IPv6 address in implicit form, however we need it in explicit form to use in a URL.
ip = fmt.Sprintf("[%s]", ip)
} else if count > 0 && !strings.HasSuffix(ip, "]") {
tmpIp, portStr, err := net.SplitHostPort(ip)
if err == nil {
ip = tmpIp
tmpPort, err := strconv.Atoi(portStr)
if err == nil {
port = uint(tmpPort)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aubrich would you be able to add unit testing for this? it might be interesting to isolate this in a function and unit test the function. this would give us more confidence we're not introducing bugs to the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you suggested I wrote a dedicated function and associated unit tests. I did not write test cases where disco.Addrs gives us something which is not an address.

}
u := fmt.Sprintf("%s://%s:%d", scheme, ip, port)
info := *leaderInfo
Expand Down