[DigitalOcean]: accept multiple records in dns-controller

This commit is contained in:
zak905 2022-03-29 15:46:46 +02:00
parent d6cdcbf371
commit 6ed094fcd2
1 changed files with 18 additions and 11 deletions

View File

@ -185,20 +185,27 @@ func (r *resourceRecordSets) List() ([]dnsprovider.ResourceRecordSet, error) {
return nil, err return nil, err
} }
var rrset *resourceRecordSet
var rrsets []dnsprovider.ResourceRecordSet var rrsets []dnsprovider.ResourceRecordSet
rrsetsWithoutDups := make(map[string]*resourceRecordSet)
for _, record := range records { for _, record := range records {
// digitalocean API returns the record without the zone // digitalocean API returns the record without the zone
// but the consumers of this interface expect the zone to be included // but the consumers of this interface expect the zone to be included
recordName := dns.EnsureDotSuffix(record.Name) + r.Zone().Name() recordName := dns.EnsureDotSuffix(record.Name) + r.Zone().Name()
rrset = &resourceRecordSet{ if set, ok := rrsetsWithoutDups[recordName]; !ok {
name: recordName, rrsetsWithoutDups[recordName] = &resourceRecordSet{
data: record.Data, name: recordName,
ttl: record.TTL, data: []string{record.Data},
recordType: rrstype.RrsType(record.Type), ttl: record.TTL,
recordType: rrstype.RrsType(record.Type),
}
} else {
set.data = append(set.data, record.Data)
} }
}
rrsets = append(rrsets, rrset) for _, set := range rrsetsWithoutDups {
rrsets = append(rrsets, set)
} }
return rrsets, nil return rrsets, nil
@ -223,13 +230,13 @@ func (r *resourceRecordSets) Get(name string) ([]dnsprovider.ResourceRecordSet,
// New returns an implementation of dnsprovider.ResourceRecordSet // New returns an implementation of dnsprovider.ResourceRecordSet
func (r *resourceRecordSets) New(name string, rrdatas []string, ttl int64, rrstype rrstype.RrsType) dnsprovider.ResourceRecordSet { func (r *resourceRecordSets) New(name string, rrdatas []string, ttl int64, rrstype rrstype.RrsType) dnsprovider.ResourceRecordSet {
if len(rrdatas) > 1 { if len(rrdatas) == 0 {
return nil return nil
} }
return &resourceRecordSet{ return &resourceRecordSet{
name: name, name: name,
data: rrdatas[0], data: rrdatas,
ttl: int(ttl), ttl: int(ttl),
recordType: rrstype, recordType: rrstype,
} }
@ -256,7 +263,7 @@ func (r *resourceRecordSets) Zone() dnsprovider.Zone {
// a single record associated with a zone // a single record associated with a zone
type resourceRecordSet struct { type resourceRecordSet struct {
name string name string
data string data []string
ttl int ttl int
recordType rrstype.RrsType recordType rrstype.RrsType
} }
@ -269,7 +276,7 @@ func (r *resourceRecordSet) Name() string {
// Rrdatas returns a list of data associated with a resource record set // Rrdatas returns a list of data associated with a resource record set
// in DO this is almost always the IP of a record // in DO this is almost always the IP of a record
func (r *resourceRecordSet) Rrdatas() []string { func (r *resourceRecordSet) Rrdatas() []string {
return []string{r.data} return r.data
} }
// Ttl returns the time-to-live of a record // Ttl returns the time-to-live of a record