Skip to content

Commit

Permalink
feat(dns): Rewrite dns persistence to allow virtual-outbound to be ad…
Browse files Browse the repository at this point in the history
…ded (#2484)

Currently the persisted state on the vips was very restraining.
With the addition of virtual-outbounds we'll need something more flexible
This migrates the state to a new format that will be extensible.

Signed-off-by: Charly Molter <charly.molter@konghq.com>
  • Loading branch information
lahabana authored Aug 11, 2021
1 parent fbd0831 commit e96348b
Show file tree
Hide file tree
Showing 24 changed files with 917 additions and 1,036 deletions.
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

0 comments on commit e96348b

Please sign in to comment.