Skip to content

Commit

Permalink
protokube: support writing AAAA records to /etc/hosts
Browse files Browse the repository at this point in the history
Though we likely want to stop using this code altogether, it is still
used on GCE (for now).  dns-controller will "gossip" AAAA records, and
they are valid (and work) in /etc/hosts.

Co-authored-by: John Gardiner Myers <[email protected]>
  • Loading branch information
justinsb and johngmyers committed Sep 21, 2023
1 parent e95da1a commit d9d9134
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions protokube/pkg/gossip/dns/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,26 @@ func (h *HostsFile) Update(snapshot *DNSViewSnapshot) error {
klog.Warningf("ignoring unexpected lines in /etc/hosts: %v", badLines)
}

hostsToAddr := make(map[string][]string)
zones := snapshot.ListZones()
for _, zone := range zones {
records := snapshot.RecordsForZone(zone)

for _, record := range records {
if record.RrsType != "A" {
switch record.RrsType {
case "A", "AAAA":
hostsToAddr[record.Name] = append(hostsToAddr[record.Name], record.Rrdatas...)

default:
klog.Warningf("skipping record of unhandled type: %v", record)
continue
}

hostMap.ReplaceRecords(record.Name, record.Rrdatas)
}
}

for host, addresses := range hostsToAddr {
hostMap.ReplaceRecords(host, addresses)
}

return hostMap, nil
}

Expand Down

0 comments on commit d9d9134

Please sign in to comment.