@@ -551,7 +551,7 @@ func newMutableMockOCIDNSClient(zones []dns.ZoneSummary, recordsByZone map[strin
551
551
552
552
for zoneID , records := range recordsByZone {
553
553
for _ , record := range records {
554
- c .records [zoneID ][ociRecordKey (* record .Rtype , * record .Domain )] = record
554
+ c .records [zoneID ][ociRecordKey (* record .Rtype , * record .Domain , * record . Rdata )] = record
555
555
}
556
556
}
557
557
@@ -587,8 +587,12 @@ func (c *mutableMockOCIDNSClient) GetZoneRecords(ctx context.Context, request dn
587
587
return
588
588
}
589
589
590
- func ociRecordKey (rType , domain string ) string {
591
- return rType + "/" + domain
590
+ func ociRecordKey (rType , domain string , ip string ) string {
591
+ rdata := ""
592
+ if rType == "A" { // adds support for multi-targets with same rtype and domain
593
+ rdata = "_" + ip
594
+ }
595
+ return rType + "_" + domain + rdata
592
596
}
593
597
594
598
func (c * mutableMockOCIDNSClient ) PatchZoneRecords (ctx context.Context , request dns.PatchZoneRecordsRequest ) (response dns.PatchZoneRecordsResponse , err error ) {
@@ -609,7 +613,7 @@ func (c *mutableMockOCIDNSClient) PatchZoneRecords(ctx context.Context, request
609
613
})
610
614
611
615
for _ , op := range request .Items {
612
- k := ociRecordKey (* op .Rtype , * op .Domain )
616
+ k := ociRecordKey (* op .Rtype , * op .Domain , * op . Rdata )
613
617
switch op .Operation {
614
618
case dns .RecordOperationOperationAdd :
615
619
records [k ] = dns.Record {
@@ -850,21 +854,26 @@ func TestOCIApplyChanges(t *testing.T) {
850
854
Rtype : common .String (endpoint .RecordTypeA ),
851
855
Ttl : common .Int (ociRecordTTL ),
852
856
}, {
853
- Domain : common .String ("bar .foo.com" ),
857
+ Domain : common .String ("car .foo.com" ),
854
858
Rdata : common .String ("bar.com." ),
855
859
Rtype : common .String (endpoint .RecordTypeCNAME ),
856
860
Ttl : common .Int (ociRecordTTL ),
861
+ }, {
862
+ Domain : common .String ("bar.foo.com" ),
863
+ Rdata : common .String ("baz.com." ),
864
+ Rtype : common .String (endpoint .RecordTypeCNAME ),
865
+ Ttl : common .Int (ociRecordTTL ),
857
866
}},
858
867
},
859
868
changes : & plan.Changes {
860
869
Delete : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
861
870
"foo.foo.com" ,
862
871
endpoint .RecordTypeA ,
863
872
endpoint .TTL (ociRecordTTL ),
864
- "baz.com. " ,
873
+ "127.0.0.1 " ,
865
874
)},
866
875
UpdateOld : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
867
- "bar .foo.com" ,
876
+ "car .foo.com" ,
868
877
endpoint .RecordTypeCNAME ,
869
878
endpoint .TTL (ociRecordTTL ),
870
879
"baz.com." ,
@@ -896,6 +905,65 @@ func TestOCIApplyChanges(t *testing.T) {
896
905
"127.0.0.1" ),
897
906
},
898
907
},
908
+ {
909
+ name : "combine_multi_target" ,
910
+ zones : []dns.ZoneSummary {{
911
+ Id : common .String ("ocid1.dns-zone.oc1..e1e042ef0bfbb5c251b9713fd7bf8959" ),
912
+ Name : common .String ("foo.com" ),
913
+ }},
914
+
915
+ changes : & plan.Changes {
916
+ Create : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
917
+ "foo.foo.com" ,
918
+ endpoint .RecordTypeA ,
919
+ endpoint .TTL (ociRecordTTL ),
920
+ "192.168.1.2" ,
921
+ ), endpoint .NewEndpointWithTTL (
922
+ "foo.foo.com" ,
923
+ endpoint .RecordTypeA ,
924
+ endpoint .TTL (ociRecordTTL ),
925
+ "192.168.2.5" ,
926
+ )},
927
+ },
928
+ expectedEndpoints : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
929
+ "foo.foo.com" ,
930
+ endpoint .RecordTypeA ,
931
+ endpoint .TTL (ociRecordTTL ), "192.168.1.2" , "192.168.2.5" ,
932
+ )},
933
+ },
934
+ {
935
+ name : "remove_from_multi_target" ,
936
+ zones : []dns.ZoneSummary {{
937
+ Id : common .String ("ocid1.dns-zone.oc1..e1e042ef0bfbb5c251b9713fd7bf8959" ),
938
+ Name : common .String ("foo.com" ),
939
+ }},
940
+ records : map [string ][]dns.Record {
941
+ "ocid1.dns-zone.oc1..e1e042ef0bfbb5c251b9713fd7bf8959" : {{
942
+ Domain : common .String ("foo.foo.com" ),
943
+ Rdata : common .String ("192.168.1.2" ),
944
+ Rtype : common .String (endpoint .RecordTypeA ),
945
+ Ttl : common .Int (ociRecordTTL ),
946
+ }, {
947
+ Domain : common .String ("foo.foo.com" ),
948
+ Rdata : common .String ("192.168.2.5" ),
949
+ Rtype : common .String (endpoint .RecordTypeA ),
950
+ Ttl : common .Int (ociRecordTTL ),
951
+ }},
952
+ },
953
+ changes : & plan.Changes {
954
+ Delete : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
955
+ "foo.foo.com" ,
956
+ endpoint .RecordTypeA ,
957
+ endpoint .TTL (ociRecordTTL ),
958
+ "192.168.1.2" ,
959
+ )},
960
+ },
961
+ expectedEndpoints : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
962
+ "foo.foo.com" ,
963
+ endpoint .RecordTypeA ,
964
+ endpoint .TTL (ociRecordTTL ), "192.168.2.5" ,
965
+ )},
966
+ },
899
967
}
900
968
901
969
for _ , tc := range testCases {
0 commit comments