kubernetes/kops · error

error initializing DNS cache: %v

Error message

error initializing DNS cache: %v

What it means

NewDNSController initializes the DNS cache via newDNSCache. Any failure there — most commonly a provider not supporting zones (see dnscache.go:45) — is wrapped with 'error initializing DNS cache' and returned, aborting controller construction in main.

Source

Thrown at dns-controller/pkg/dns/dnscontroller.go:94

	// mutex protected the following mutable state
	mutex sync.Mutex

	// Ready is set if the populating controller has performed an initial synchronization of records
	Ready bool

	// Records is the map of actual records for this scope
	Records map[string][]Record
}

// DNSControllerScope is a Scope
var _ Scope = &DNSControllerScope{}

// NewDNSController creates a DnsController
func NewDNSController(dnsProviders []dnsprovider.Interface, zoneRules *ZoneRules, updateInterval int) (*DNSController, error) {
	dnsCache, err := newDNSCache(dnsProviders)
	if err != nil {
		return nil, fmt.Errorf("error initializing DNS cache: %v", err)
	}

	c := &DNSController{
		scopes:         make(map[string]*DNSControllerScope),
		zoneRules:      zoneRules,
		dnsCache:       dnsCache,
		updateInterval: time.Duration(updateInterval) * time.Second,
	}

	return c, nil
}

// Run starts the DnsController.
func (c *DNSController) Run() {
	klog.Infof("starting DNS controller")

	stopCh := c.StopChannel()
	go c.runWatcher(stopCh)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check the wrapped inner error; if it reads 'DNS provider does not support zones', switch --dns to a zone-capable provider.
  2. Verify the providers slice passed to NewDNSController contains only valid, initialized dnsprovider.Interface values.
  3. Confirm provider configuration (flags/env) so provider.Zones() returns a working zones provider.

Example fix

// before
NewDNSController([]dnsprovider.Interface{unsupported}, zoneRules, 5)
// after
providers, err := dnsprovider.GetDnsProviders(flags.DNS)
if err != nil { klog.Fatalf("dns provider: %v", err) }
NewDNSController(providers, zoneRules, 5)
Defensive patterns

Strategy: validation

Validate before calling

for i, p := range dnsProviders {
	if p == nil {
		return fmt.Errorf("dns provider at index %d is nil", i)
	}
	if _, ok := p.Zones(); !ok {
		return fmt.Errorf("dns provider at index %d (%T) does not support zones", i, p)
	}
}

Type guard

func allProvidersSupportZones(providers []dnsprovider.Interface) bool {
	for _, p := range providers {
		if p == nil { return false }
		if _, ok := p.Zones(); !ok { return false }
	}
	return len(providers) > 0
}

Try / catch

c, err := dns.NewDNSController(providers, zoneRules, interval)
if err != nil {
	klog.Fatalf("initializing DNS controller: %v", err) // read wrapped cause
}

Prevention

When it happens

Trigger: Calling NewDNSController with providers where at least one Zones() call fails (returns ok=false) or newDNSCache otherwise errors during construction.

Common situations: dns-controller started with a --dns provider lacking zone support; a nil provider slipped into the providers slice; misconfigured provider initialization producing a non-functional interface.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/701ac70216ea74e0. Report an issue: GitHub.