Merge pull request #13443 from zak905/do_dns_controller_crash_multiple_masters

fix dns controller crashing for DO
This commit is contained in:
Kubernetes Prow Robot 2022-04-01 04:28:48 -07:00 committed by GitHub
commit f9b4ffa4c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 {
rrsetsWithoutDups[recordName] = &resourceRecordSet{
name: recordName, name: recordName,
data: record.Data, data: []string{record.Data},
ttl: record.TTL, ttl: record.TTL,
recordType: rrstype.RrsType(record.Type), 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