@@ -541,7 +541,7 @@ func newMutableMockOCIDNSClient(zones []dns.ZoneSummary, recordsByZone map[strin
541
541
542
542
for zoneID , records := range recordsByZone {
543
543
for _ , record := range records {
544
- c .records [zoneID ][ociRecordKey (* record .Rtype , * record .Domain )] = record
544
+ c .records [zoneID ][ociRecordKey (* record .Rtype , * record .Domain , * record . Rdata )] = record
545
545
}
546
546
}
547
547
@@ -577,8 +577,18 @@ func (c *mutableMockOCIDNSClient) GetZoneRecords(ctx context.Context, request dn
577
577
return
578
578
}
579
579
580
- func ociRecordKey (rType , domain string ) string {
581
- return rType + "/" + domain
580
+ func ociRecordKey (rType , domain string , ip string ) string {
581
+ rdata := ""
582
+ if rType == "A" { // adds support for multi-targets with same rtype and domain
583
+ rdata = "_" + ip
584
+ }
585
+ return rType + "_" + domain + rdata
586
+ }
587
+
588
+ func sortEndpointTargets (endpoints []* endpoint.Endpoint ) {
589
+ for _ , ep := range endpoints {
590
+ sort .Strings ([]string (ep .Targets ))
591
+ }
582
592
}
583
593
584
594
func (c * mutableMockOCIDNSClient ) PatchZoneRecords (ctx context.Context , request dns.PatchZoneRecordsRequest ) (response dns.PatchZoneRecordsResponse , err error ) {
@@ -599,7 +609,7 @@ func (c *mutableMockOCIDNSClient) PatchZoneRecords(ctx context.Context, request
599
609
})
600
610
601
611
for _ , op := range request .Items {
602
- k := ociRecordKey (* op .Rtype , * op .Domain )
612
+ k := ociRecordKey (* op .Rtype , * op .Domain , * op . Rdata )
603
613
switch op .Operation {
604
614
case dns .RecordOperationOperationAdd :
605
615
records [k ] = dns.Record {
@@ -702,6 +712,7 @@ func TestMutableMockOCIDNSClient(t *testing.T) {
702
712
}
703
713
704
714
func TestOCIApplyChanges (t * testing.T ) {
715
+
705
716
testCases := []struct {
706
717
name string
707
718
zones []dns.ZoneSummary
@@ -840,21 +851,26 @@ func TestOCIApplyChanges(t *testing.T) {
840
851
Rtype : common .String (endpoint .RecordTypeA ),
841
852
Ttl : common .Int (ociRecordTTL ),
842
853
}, {
843
- Domain : common .String ("bar .foo.com" ),
854
+ Domain : common .String ("car .foo.com" ),
844
855
Rdata : common .String ("bar.com." ),
845
856
Rtype : common .String (endpoint .RecordTypeCNAME ),
846
857
Ttl : common .Int (ociRecordTTL ),
858
+ }, {
859
+ Domain : common .String ("bar.foo.com" ),
860
+ Rdata : common .String ("baz.com." ),
861
+ Rtype : common .String (endpoint .RecordTypeCNAME ),
862
+ Ttl : common .Int (ociRecordTTL ),
847
863
}},
848
864
},
849
865
changes : & plan.Changes {
850
866
Delete : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
851
867
"foo.foo.com" ,
852
868
endpoint .RecordTypeA ,
853
869
endpoint .TTL (ociRecordTTL ),
854
- "baz.com. " ,
870
+ "127.0.0.1 " ,
855
871
)},
856
872
UpdateOld : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
857
- "bar .foo.com" ,
873
+ "car .foo.com" ,
858
874
endpoint .RecordTypeCNAME ,
859
875
endpoint .TTL (ociRecordTTL ),
860
876
"baz.com." ,
@@ -886,6 +902,65 @@ func TestOCIApplyChanges(t *testing.T) {
886
902
"127.0.0.1" ),
887
903
},
888
904
},
905
+ {
906
+ name : "combine_multi_target" ,
907
+ zones : []dns.ZoneSummary {{
908
+ Id : common .String ("ocid1.dns-zone.oc1..e1e042ef0bfbb5c251b9713fd7bf8959" ),
909
+ Name : common .String ("foo.com" ),
910
+ }},
911
+
912
+ changes : & plan.Changes {
913
+ Create : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
914
+ "foo.foo.com" ,
915
+ endpoint .RecordTypeA ,
916
+ endpoint .TTL (ociRecordTTL ),
917
+ "192.168.1.2" ,
918
+ ), endpoint .NewEndpointWithTTL (
919
+ "foo.foo.com" ,
920
+ endpoint .RecordTypeA ,
921
+ endpoint .TTL (ociRecordTTL ),
922
+ "192.168.2.5" ,
923
+ )},
924
+ },
925
+ expectedEndpoints : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
926
+ "foo.foo.com" ,
927
+ endpoint .RecordTypeA ,
928
+ endpoint .TTL (ociRecordTTL ), "192.168.1.2" , "192.168.2.5" ,
929
+ )},
930
+ },
931
+ {
932
+ name : "remove_from_multi_target" ,
933
+ zones : []dns.ZoneSummary {{
934
+ Id : common .String ("ocid1.dns-zone.oc1..e1e042ef0bfbb5c251b9713fd7bf8959" ),
935
+ Name : common .String ("foo.com" ),
936
+ }},
937
+ records : map [string ][]dns.Record {
938
+ "ocid1.dns-zone.oc1..e1e042ef0bfbb5c251b9713fd7bf8959" : {{
939
+ Domain : common .String ("foo.foo.com" ),
940
+ Rdata : common .String ("192.168.1.2" ),
941
+ Rtype : common .String (endpoint .RecordTypeA ),
942
+ Ttl : common .Int (ociRecordTTL ),
943
+ }, {
944
+ Domain : common .String ("foo.foo.com" ),
945
+ Rdata : common .String ("192.168.2.5" ),
946
+ Rtype : common .String (endpoint .RecordTypeA ),
947
+ Ttl : common .Int (ociRecordTTL ),
948
+ }},
949
+ },
950
+ changes : & plan.Changes {
951
+ Delete : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
952
+ "foo.foo.com" ,
953
+ endpoint .RecordTypeA ,
954
+ endpoint .TTL (ociRecordTTL ),
955
+ "192.168.1.2" ,
956
+ )},
957
+ },
958
+ expectedEndpoints : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
959
+ "foo.foo.com" ,
960
+ endpoint .RecordTypeA ,
961
+ endpoint .TTL (ociRecordTTL ), "192.168.2.5" ,
962
+ )},
963
+ },
889
964
}
890
965
891
966
for _ , tc := range testCases {
@@ -904,6 +979,8 @@ func TestOCIApplyChanges(t *testing.T) {
904
979
require .Equal (t , tc .err , err )
905
980
endpoints , err := provider .Records (ctx )
906
981
require .NoError (t , err )
982
+ sortEndpointTargets (endpoints )
983
+ sortEndpointTargets (tc .expectedEndpoints )
907
984
require .ElementsMatch (t , tc .expectedEndpoints , endpoints )
908
985
})
909
986
}
0 commit comments