MCPcopy
hub / github.com/kubernetes/kops / updateRecords

Method updateRecords

dns-controller/pkg/dns/dnscontroller.go:540–591  ·  view source on GitHub ↗
(k recordKey, newRecords []string, ttl int64)

Source from the content-addressed store, hash-verified

538}
539
540func (o *dnsOp) updateRecords(k recordKey, newRecords []string, ttl int64) error {
541 fqdn := EnsureDotSuffix(k.FQDN)
542
543 zone := o.findZone(fqdn)
544 if zone == nil {
545 // TODO: Post event into service / pod
546 return fmt.Errorf("no suitable zone found for %q", fqdn)
547 }
548
549 rrsProvider, ok := zone.ResourceRecordSets()
550 if !ok {
551 return fmt.Errorf("zone does not support resource records %q", zone.Name())
552 }
553
554 var existing dnsprovider.ResourceRecordSet
555
556 // when DNS provider is aws-route53 or google-clouddns
557 rrs, err := o.listRecords(zone)
558 if err != nil {
559 return fmt.Errorf("error querying resource records for zone %q: %v", zone.Name(), err)
560 }
561
562 for _, rr := range rrs {
563 rrName := EnsureDotSuffix(FixWildcards(rr.Name()))
564 if rrName != fqdn {
565 klog.V(8).Infof("Skipping record %q (name != %s)", rrName, fqdn)
566 continue
567 }
568 if string(rr.Type()) != string(k.RecordType) {
569 klog.V(8).Infof("Skipping record %q (type %s != %s)", rrName, rr.Type(), k.RecordType)
570 continue
571 }
572
573 if existing != nil {
574 klog.Warningf("Found multiple matching records: %v and %v", existing, rr)
575 } else {
576 klog.V(8).Infof("Found matching record: %s %s", k.RecordType, rrName)
577 }
578 existing = rr
579 }
580
581 cs, err := o.getChangeset(zone)
582 if err != nil {
583 return err
584 }
585
586 klog.V(2).Infof("Adding DNS changes to batch %s %s", k, newRecords)
587 rr := rrsProvider.New(fqdn, newRecords, ttl, rrstype.RrsType(k.RecordType))
588 cs.Upsert(rr)
589
590 return nil
591}
592
593func (c *DNSController) recordChange() {
594 atomic.AddUint64(&c.changeCount, 1)

Callers 1

runOnceMethod · 0.80

Calls 11

findZoneMethod · 0.95
listRecordsMethod · 0.95
getChangesetMethod · 0.95
RrsTypeTypeAlias · 0.92
EnsureDotSuffixFunction · 0.85
FixWildcardsFunction · 0.85
ResourceRecordSetsMethod · 0.65
NameMethod · 0.65
TypeMethod · 0.65
NewMethod · 0.65
UpsertMethod · 0.65

Tested by

no test coverage detected