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

Add a default A record for each VM #60

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 10 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,28 @@ 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))
break
}
}
}
sort.Strings(recordsArr)
if len(recordsArr) > 0 {
recordsArr = append(recordsArr, generateDefaultARecord(name, namespace, recordsArr[0]))
}
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
35 changes: 26 additions & 9 deletions pkg/zonemgr/internal/zone-file-cache/zone_file_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ var _ = Describe("cached zone file content maintenance", func() {
nic4IP = "13.14.15.16"
IPv6 = "fe80::74c8:f2ff:fe5f:ff2b"

aRecordFmt = "%s.%s.%s IN A %s\n"
aRecordFmt = "%s.%s.%s IN A %s\n"
defaultARecordFmt = "%s.%s IN A %s\n"

updated = true
notUpdated = false
Expand All @@ -81,6 +82,11 @@ var _ = Describe("cached zone file content maintenance", func() {

aRecord_nic3_vm1_ns2 = fmt.Sprintf(aRecordFmt, nic3Name, vmi1Name, namespace2, nic3IP)
aRecord_nic4_vm1_ns2 = fmt.Sprintf(aRecordFmt, nic4Name, vmi1Name, namespace2, nic4IP)

defARecord_nic1_vm1_ns1 = fmt.Sprintf(defARecordFmt, vmi1Name, namespace1, nic1IP)
defARecord_nic2_vm1_ns1 = fmt.Sprintf(defARecordFmt, vmi1Name, namespace1, nic2IP)
defARecord_nic1_vm2_ns1 = fmt.Sprintf(defARecordFmt, vmi2Name, namespace1, nic1IP)
defARecord_nic3_vm2_ns1 = fmt.Sprintf(defARecordFmt, vmi2Name, namespace1, nic3IP)
)

validateUpdateFunc := func(vmiName, vmiNamespace string, newInterfaces []v1.VirtualMachineInstanceNetworkInterface,
Expand All @@ -102,7 +108,7 @@ var _ = Describe("cached zone file content maintenance", func() {
namespace1,
[]v1.VirtualMachineInstanceNetworkInterface{{IPs: []string{nic1IP}, Name: nic1Name}},
updated,
aRecord_nic1_vm1_ns1,
aRecord_nic1_vm1_ns1+defARecord_nic1_vm1_ns1,
1,
),
Entry("when non existing vmi is deleted",
Expand Down Expand Up @@ -142,8 +148,10 @@ var _ = Describe("cached zone file content maintenance", func() {
updated,
aRecord_nic1_vm1_ns1+
aRecord_nic2_vm1_ns1+
defARecord_nic1_vm1_ns1+
aRecord_nic3_vm2_ns1+
aRecord_nic4_vm2_ns1,
aRecord_nic4_vm2_ns1+
defARecord_nic3_vm2_ns1,
2,
),
Entry("when existing vmi is deleted",
Expand All @@ -160,7 +168,8 @@ var _ = Describe("cached zone file content maintenance", func() {
[]v1.VirtualMachineInstanceNetworkInterface{{IPs: []string{nic1IP}, Name: nic1Name}, {IPs: []string{nic4IP}, Name: nic4Name}},
updated,
aRecord_nic1_vm1_ns1+
aRecord_nic4_vm1_ns1,
aRecord_nic4_vm1_ns1+
defARecord_nic1_vm1_ns1,
2,
),
Entry("when existing vmi is not changed but its interfaces order is changed",
Expand All @@ -169,7 +178,8 @@ var _ = Describe("cached zone file content maintenance", func() {
[]v1.VirtualMachineInstanceNetworkInterface{{IPs: []string{nic2IP}, Name: nic2Name}, {IPs: []string{nic1IP}, Name: nic1Name}},
notUpdated,
aRecord_nic1_vm1_ns1+
aRecord_nic2_vm1_ns1,
aRecord_nic2_vm1_ns1+
defARecord_nic1_vm1_ns1,
1,
),
)
Expand Down Expand Up @@ -197,7 +207,9 @@ var _ = Describe("cached zone file content maintenance", func() {
aRecord_nic1_vm2_ns1+
aRecord_nic2_vm2_ns1+
aRecord_nic3_vm1_ns2+
aRecord_nic4_vm1_ns2,
aRecord_nic4_vm1_ns2+
defARecord_nic2_vm1_ns1+
defARecord_nic1_vm2_ns1,
3,
),
Entry("when existing vmi is deleted",
Expand All @@ -216,8 +228,10 @@ var _ = Describe("cached zone file content maintenance", func() {
updated,
aRecord_nic1_vm1_ns1+
aRecord_nic4_vm1_ns1+
defARecord_nic1_vm1_ns1+
aRecord_nic1_vm2_ns1+
aRecord_nic2_vm2_ns1,
aRecord_nic2_vm2_ns1+
defARecord_nic1_vm2_ns1,
3,
),
Entry("when existing vmi is not changed but its interfaces order is changed",
Expand All @@ -227,8 +241,10 @@ var _ = Describe("cached zone file content maintenance", func() {
notUpdated,
aRecord_nic2_vm1_ns1+
aRecord_nic1_vm1_ns1+
defARecord_nic1_vm1_ns1+
aRecord_nic1_vm2_ns1+
aRecord_nic2_vm2_ns1,
aRecord_nic2_vm2_ns1+
defARecord_nic2_vm2_ns1,
2,
),
)
Expand All @@ -246,7 +262,8 @@ var _ = Describe("cached zone file content maintenance", func() {
[]v1.VirtualMachineInstanceNetworkInterface{{IPs: []string{nic1IP, IPv6}, Name: nic1Name}, {IPs: []string{nic2IP, IPv6}, Name: nic2Name}},
updated,
aRecord_nic1_vm1_ns1+
aRecord_nic2_vm1_ns1,
aRecord_nic2_vm1_ns1+
defARecord_nic1_vm1_ns1,
1,
),
Entry("vmi interfaces contain IPv6 only",
Expand Down
Loading