Browse Source

zones: add ResolvePublicAddresses() ScanOption to prevent early LookupIP calls

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/5/head
Alejandro Mery 10 months ago
parent
commit
0989dec5e8
  1. 8
      pkg/zones/machine_scan.go
  2. 17
      pkg/zones/options.go
  3. 4
      pkg/zones/scan.go

8
pkg/zones/machine_scan.go

@ -52,12 +52,16 @@ func (m *Machine) setID() error {
return nil
}
func (m *Machine) scan() error {
func (m *Machine) scan(opts *ScanOptions) error {
for i := 0; i < RingsCount; i++ {
if err := m.tryApplyWireguardConfig(i); err != nil {
return err
}
}
return m.updatePublicAddresses()
if !opts.DontResolvePublicAddresses {
return m.updatePublicAddresses()
}
return nil
}

17
pkg/zones/options.go

@ -12,7 +12,22 @@ import (
type ScanOption func(*Zones, *ScanOptions) error
// ScanOptions contains flags used by the initial scan
type ScanOptions struct{}
type ScanOptions struct {
// DontResolvePublicAddresses indicates we shouldn't
// pre-populate Machine.PublicAddresses during the
// initial scan
DontResolvePublicAddresses bool
}
// ResolvePublicAddresses instructs the scanner to use
// the DNS resolver to get PublicAddresses of nodes.
// Default is true
func ResolvePublicAddresses(resolve bool) ScanOption {
return func(m *Zones, opt *ScanOptions) error {
opt.DontResolvePublicAddresses = !resolve
return nil
}
}
// WithLookuper specifies what resolver.Lookuper to use to
// find public addresses

4
pkg/zones/scan.go

@ -46,10 +46,10 @@ func (m *Zones) scanDirectory(_ *ScanOptions) error {
return nil
}
func (m *Zones) scanMachines(_ *ScanOptions) error {
func (m *Zones) scanMachines(opts *ScanOptions) error {
var err error
m.ForEachMachine(func(p *Machine) bool {
err = p.scan()
err = p.scan(opts)
return err != nil
})
return err

Loading…
Cancel
Save