Skip to content

Commit

Permalink
do A lookups after SRV lookups for store discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
mjd95 authored and Martin Dickson committed Mar 8, 2019
1 parent b4d233e commit 659366a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
9 changes: 8 additions & 1 deletion pkg/discovery/dns/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ func (s *dnsSD) Resolve(ctx context.Context, name string, qtype QType) ([]string
if resPort == "" {
resPort = strconv.Itoa(int(rec.Port))
}
res = append(res, appendScheme(scheme, net.JoinHostPort(rec.Target, resPort)))
// Do A lookup for the domain in SRV answer
resIPs, err := s.resolver.LookupIPAddr(ctx, rec.Target)
if err != nil {
return nil, errors.Wrapf(err, "look IP addresses %q", rec.Target)
}
for _, resIP := range resIPs {
res = append(res, appendScheme(scheme, net.JoinHostPort(resIP.String(), resPort)))
}
}
default:
return nil, errors.Errorf("invalid lookup scheme %q", qtype)
Expand Down
18 changes: 13 additions & 5 deletions pkg/discovery/dns/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,33 @@ var (
resolver: &mockHostnameResolver{
resultSRVs: map[string][]*net.SRV{
"_test._tcp.mycompany.com": {
&net.SRV{Target: "192.168.0.1", Port: 8080},
&net.SRV{Target: "192.168.0.2", Port: 8081},
&net.SRV{Target: "alt1.mycompany.com.", Port: 8080},
&net.SRV{Target: "alt2.mycompany.com.", Port: 8081},
},
},
resultIPs: map[string][]net.IPAddr{
"alt1.mycompany.com.": {net.IPAddr{IP: net.ParseIP("192.168.0.1")}},
"alt2.mycompany.com.": {net.IPAddr{IP: net.ParseIP("192.168.0.2")}},
},
},
},
{
testName: "multiple srv records from srv lookup",
testName: "multiple srv records from srv lookup with specified port",
addr: "_test._tcp.mycompany.com:8082",
qtype: SRV,
expectedResult: []string{"192.168.0.1:8082", "192.168.0.2:8082"},
expectedErr: nil,
resolver: &mockHostnameResolver{
resultSRVs: map[string][]*net.SRV{
"_test._tcp.mycompany.com": {
&net.SRV{Target: "192.168.0.1", Port: 8080},
&net.SRV{Target: "192.168.0.2", Port: 8081},
&net.SRV{Target: "alt1.mycompany.com.", Port: 8080},
&net.SRV{Target: "alt2.mycompany.com.", Port: 8081},
},
},
resultIPs: map[string][]net.IPAddr{
"alt1.mycompany.com.": {net.IPAddr{IP: net.ParseIP("192.168.0.1")}},
"alt2.mycompany.com.": {net.IPAddr{IP: net.ParseIP("192.168.0.2")}},
},
},
},
{
Expand Down

0 comments on commit 659366a

Please sign in to comment.