Add more logging
Fix issue when trying to update with an empty address Fix govet issues Run IPv6 poller
This commit is contained in:
parent
e00c0a285a
commit
00c93beca0
@ -174,7 +174,7 @@ func main() {
|
|||||||
records := []sync.Record{}
|
records := []sync.Record{}
|
||||||
for name, d := range cfg.Domains {
|
for name, d := range cfg.Domains {
|
||||||
if !strings.HasSuffix(name, ".") {
|
if !strings.HasSuffix(name, ".") {
|
||||||
name = name + "."
|
name += "."
|
||||||
}
|
}
|
||||||
records = append(records, constructRecord(name, d)...)
|
records = append(records, constructRecord(name, d)...)
|
||||||
}
|
}
|
||||||
@ -196,6 +196,7 @@ func main() {
|
|||||||
// TODO: Refactor and move this code to it's own package
|
// TODO: Refactor and move this code to it's own package
|
||||||
wg.Go(func() error { return syncer.Run(ctx.Done()) })
|
wg.Go(func() error { return syncer.Run(ctx.Done()) })
|
||||||
wg.Go(func() error { return IP4Poller.Run(ctx.Done()) })
|
wg.Go(func() error { return IP4Poller.Run(ctx.Done()) })
|
||||||
|
wg.Go(func() error { return IP6Poller.Run(ctx.Done()) })
|
||||||
wg.Go(func() error {
|
wg.Go(func() error {
|
||||||
// This goroutine receives IP address polling results
|
// This goroutine receives IP address polling results
|
||||||
// and updates the desired records in the Syncer.
|
// and updates the desired records in the Syncer.
|
||||||
@ -204,6 +205,7 @@ func main() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case ip := <-ip4c:
|
case ip := <-ip4c:
|
||||||
|
log.Printf("Updating IPv4: %v", ip)
|
||||||
for _, r := range records {
|
for _, r := range records {
|
||||||
if r.Record.Type() == "A" {
|
if r.Record.Type() == "A" {
|
||||||
syncer.UpdateRecord(
|
syncer.UpdateRecord(
|
||||||
@ -215,6 +217,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ip := <-ip6c:
|
case ip := <-ip6c:
|
||||||
|
log.Printf("Updating IPv6: %v", ip)
|
||||||
for _, r := range records {
|
for _, r := range records {
|
||||||
if r.Record.Type() == "AAAA" {
|
if r.Record.Type() == "AAAA" {
|
||||||
syncer.UpdateRecord(
|
syncer.UpdateRecord(
|
||||||
@ -272,7 +275,7 @@ func main() {
|
|||||||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
||||||
select {
|
select {
|
||||||
case s := <-signals:
|
case s := <-signals:
|
||||||
log.Printf("Received signal %v, exiting...", s)
|
log.Printf("Received %v signal, exiting...", s)
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
}
|
}
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -74,6 +74,7 @@ func (i *IPAddressPoller) poll() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not obtain IP address: %w", err)
|
return fmt.Errorf("could not obtain IP address: %w", err)
|
||||||
}
|
}
|
||||||
|
log.Printf("Found IP %v", ip)
|
||||||
for _, c := range i.channels {
|
for _, c := range i.channels {
|
||||||
select {
|
select {
|
||||||
case c <- ip.String():
|
case c <- ip.String():
|
||||||
|
@ -89,7 +89,7 @@ func NewSyncer(records []Record, pollInterval, apiTimeout time.Duration) *Syncer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateRecord() updates a managed record so that it can be synced by the
|
// UpdateRecord updates a managed record so that it can be synced by the
|
||||||
// sync loop.
|
// sync loop.
|
||||||
func (s *Syncer) UpdateRecord(dnsName, dnsType string, ttl int64, data []string) error {
|
func (s *Syncer) UpdateRecord(dnsName, dnsType string, ttl int64, data []string) error {
|
||||||
for _, d := range s.domains {
|
for _, d := range s.domains {
|
||||||
@ -109,10 +109,10 @@ func (s *Syncer) UpdateRecord(dnsName, dnsType string, ttl int64, data []string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Domain %s not registered.", dnsName)
|
return fmt.Errorf("domain %s not registered.", dnsName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// needsUpdate() compares the left/local DNSRecord against the right/remote
|
// needsUpdate compares the left/local DNSRecord against the right/remote
|
||||||
// DNSRecord and returns true if the record needs to be updated in the remote
|
// DNSRecord and returns true if the record needs to be updated in the remote
|
||||||
// backend.
|
// backend.
|
||||||
func needsUpdate(l, r backend.DNSRecord) bool {
|
func needsUpdate(l, r backend.DNSRecord) bool {
|
||||||
@ -135,7 +135,7 @@ func needsUpdate(l, r backend.DNSRecord) bool {
|
|||||||
lData := l.Data()
|
lData := l.Data()
|
||||||
rData := r.Data()
|
rData := r.Data()
|
||||||
|
|
||||||
if len(lData) <= 0 {
|
if len(lData) < 1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ func needsUpdate(l, r backend.DNSRecord) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// pollSingle() performs a single refresh of the remote cache value.
|
// pollSingle performs a single refresh of the remote cache value.
|
||||||
func (s *Syncer) pollSingle(d *domainObj) error {
|
func (s *Syncer) pollSingle(d *domainObj) error {
|
||||||
// Update record sets to reconcile
|
// Update record sets to reconcile
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -173,7 +173,7 @@ func (s *Syncer) pollSingle(d *domainObj) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// poll() runs a loop to poll the backend and update the remote cache.
|
// poll runs a loop to poll the backend and update the remote cache.
|
||||||
func (s *Syncer) poll(d *domainObj, stopCh <-chan struct{}) {
|
func (s *Syncer) poll(d *domainObj, stopCh <-chan struct{}) {
|
||||||
// Start by polling the domain to initialize the remote value and local cache
|
// Start by polling the domain to initialize the remote value and local cache
|
||||||
// TODO: Implement some exponential retry backoff logic in case poll interval is long
|
// TODO: Implement some exponential retry backoff logic in case poll interval is long
|
||||||
@ -192,14 +192,14 @@ func (s *Syncer) poll(d *domainObj, stopCh <-chan struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// syncSingle() syncs a single record entry, updating it with
|
// syncSingle syncs a single record entry, updating it with
|
||||||
// the backend server if necessary.
|
// the backend server if necessary.
|
||||||
func (s *Syncer) syncSingle(d *domainObj) error {
|
func (s *Syncer) syncSingle(d *domainObj) error {
|
||||||
d.lock.Lock()
|
d.lock.Lock()
|
||||||
defer d.lock.Unlock()
|
defer d.lock.Unlock()
|
||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if !needsUpdate(d.managed, d.remote) {
|
if !needsUpdate(d.managed, d.remote) || len(d.managed.Data()) < 1 || len(d.managed.Data()) < 1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ func (s *Syncer) syncSingle(d *domainObj) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// sync() runs a loop to sync records with backend providers
|
// sync runs a loop to sync records with backend providers
|
||||||
// when necessary.
|
// when necessary.
|
||||||
func (s *Syncer) sync(d *domainObj, stopCh <-chan struct{}) {
|
func (s *Syncer) sync(d *domainObj, stopCh <-chan struct{}) {
|
||||||
for {
|
for {
|
||||||
@ -246,7 +246,7 @@ func (s *Syncer) sync(d *domainObj, stopCh <-chan struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run() starts the sync and poll loops
|
// Run starts the sync and poll loops
|
||||||
func (s *Syncer) Run(stopCh <-chan struct{}) error {
|
func (s *Syncer) Run(stopCh <-chan struct{}) error {
|
||||||
// Run a sync and poll loop for each domain. Sync and poll loops are
|
// Run a sync and poll loop for each domain. Sync and poll loops are
|
||||||
// separated so that polling and syncing do not block on each other.
|
// separated so that polling and syncing do not block on each other.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user