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

feat(dns): Rewrite dns persistence to allow virtual-outbound to be added #2484

Merged
merged 5 commits into from
Aug 11, 2021
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
2 changes: 1 addition & 1 deletion api/mesh/v1alpha1/dataplane_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var _ = Describe("MultiValueTagSet", func() {

Describe("Keys()", func() {
Describe("HostnameEntries()", func() {
type testCase struct {
value MultiValueTagSet
expected []string
Expand Down
58 changes: 0 additions & 58 deletions pkg/dns/ip.go

This file was deleted.

54 changes: 0 additions & 54 deletions pkg/dns/ip_test.go

This file was deleted.

43 changes: 20 additions & 23 deletions pkg/dns/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import (

type DNSResolver interface {
GetDomain() string
SetVIPs(list vips.List)
GetVIPs() vips.List
SetVIPs(map[vips.HostnameEntry]string)
ForwardLookupFQDN(name string) (string, error)
}

type dnsResolver struct {
sync.RWMutex
domain string
viplist vips.List
viplist map[vips.HostnameEntry]string
}

var _ DNSResolver = &dnsResolver{}
Expand All @@ -35,41 +34,39 @@ func (d *dnsResolver) GetDomain() string {
return d.domain
}

func (s *dnsResolver) SetVIPs(list vips.List) {
func (s *dnsResolver) SetVIPs(list map[vips.HostnameEntry]string) {
s.Lock()
defer s.Unlock()
s.viplist = list
}

func (s *dnsResolver) GetVIPs() vips.List {
s.RLock()
defer s.RUnlock()
return s.viplist
}

func (s *dnsResolver) ForwardLookupFQDN(name string) (string, error) {
s.RLock()
defer s.RUnlock()
domain, err := s.domainFromName(name)
if err != nil {
return "", err
}

if domain != s.domain {
return "", errors.Errorf("domain [%s] not found.", domain)
}
ipFqdn, foundFqdn := s.viplist[vips.NewFqdnEntry(strings.TrimSuffix(name, "."))]

service, err := s.serviceFromName(name)
domain, err := s.domainFromName(name)
if err != nil {
return "", err
}

ip, found := s.viplist[vips.NewServiceEntry(service)]
if !found {
if domain == s.domain {
service, err := s.serviceFromName(name)
if err != nil {
return "", err
}

ip, found := s.viplist[vips.NewServiceEntry(service)]
if found {
return ip, nil
} else if foundFqdn {
return ipFqdn, nil
}
return "", errors.Errorf("service [%s] not found in domain [%s].", service, domain)
} else if foundFqdn {
return ipFqdn, nil
}

return ip, nil
return "", errors.Errorf("domain [%s] not found.", domain)
}

func (s *dnsResolver) domainFromName(name string) (string, error) {
Expand Down
Loading