Skip to content

Commit

Permalink
Add a default A record for each VM
Browse files Browse the repository at this point in the history
make vm.namespace.<cluster> resolve to one of the VM-reported IP
addresses. This may make it a bit easier to find the VM even if the user
does not recall its interface names.

Signed-off-by: Dan Kenigsberg <[email protected]>
  • Loading branch information
dankenigsberg committed Aug 8, 2023
1 parent 64799ca commit 66dee13
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/zonemgr/internal/zone-file-cache/zone_file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,29 @@ func buildARecordsArr(name string, namespace string, interfaces []v1.VirtualMach
IPs := iface.IPs
for _, IP := range IPs {
if net.IsIPv4String(IP) {
recordsArr = append(recordsArr, generateARecord(name, namespace, iface.Name, IP))
recordsArr = append(recordsArr, generateIfaceARecord(name, namespace, iface.Name, IP))
defaultIP := IP
break
}
}
}
if defaultIP != nil {
recordsArr = append(recordsArr, generateDefaultARecord(name, namespace, defaultIP))
}
sort.Strings(recordsArr)
return recordsArr
}

func generateARecord(name string, namespace string, ifaceName string, ifaceIP string) string {
func generateIfaceARecord(name string, namespace string, ifaceName string, ifaceIP string) string {
fqdn := fmt.Sprintf("%s.%s.%s", ifaceName, name, namespace)
return fmt.Sprintf("%s IN A %s\n", fqdn, ifaceIP)
}

func generateDefaultARecord(name string, namespace string, ifaceIP string) string {
fqdn := fmt.Sprintf("%s.%s", name, namespace)
return fmt.Sprintf("%s IN A %s\n", fqdn, ifaceIP)
}

func (zoneFileCache ZoneFileCache) generateARecords() string {
aRecords := ""
for _, recordsArr := range zoneFileCache.vmiRecordsMap {
Expand Down

0 comments on commit 66dee13

Please sign in to comment.