$ show kubernetes-sigs/external-dns
This repository is a Kubernetes-native DNS controller that synchronizes DNS records from Kubernetes resources (Services, Ingresses, Nodes, Pods, Gateway API routes, Istio, Traefik, and many more) to external DNS providers (AWS Route53, Cloudflare, Google Cloud DNS, Azure DNS, OVH, and 20+ others). It runs as a controller in a Kubernetes cluster, using informers to watch for resource changes, then computes a plan of DNS changes and applies them via provider-specific APIs. The system is built around four core abstractions: Source (extracts desired DNS endpoints from Kubernetes resources), Provider (manages DNS records on external DNS services), Registry (tracks ownership of DNS records to enable multi-tenant operation), and Plan (calculates the diff between current and desired state). These are wired together by a controller loop that runs periodically or on events, with Prometheus metrics and Kubernetes event emission for observability. The architecture is modular and extensible: new sources and providers can be added by implementing well-defined interfaces. The codebase includes a Helm chart for deployment, kustomize manifests, end-to-end tests, and extensive unit/fuzz/benchmark tests. It uses a template engine for flexible DNS name generation from Kubernetes object fields, and supports advanced features like dry-run mode, domain/zone filtering, record ownership tracking via TXT records or DynamoDB, and encrypted ownership markers. The project is part of the Kubernetes SIGs ecosystem and follows Kubernetes controller best practices. Key entry points include main.go (binary entry), controller/execute.go (controller initialization and loop), source/store.go (source factory), provider/factory/provider.go (provider factory), and registry/factory/registry.go (registry factory). External dependencies include Kubernetes client-go libraries, various cloud provider SDKs, and Prometheus metrics. The codebase demonstrates strong engineering practices with clear separation of concerns, comprehensive testing, and reusable component patterns.
The LLM identified 6 files worth highlighting for reuse:
Core data model for DNS records (Endpoint) with fields for DNSName, RecordType, Targets, TTL, Labels, ProviderSpecific, and SetIdentifier. Includes factory functions (NewEndpointWithTTL, EndpointsForHostname, NewPTREndpoint, NewMXRecord, NewSRVRecord), merge/dedup logic (MergeEndpoints, RemoveDuplicates), and CRD validation constraints. Self-contained and used by every source, provider, registry, and plan module. Demonstrates careful design for DNS record representation with trailing-dot normalization, IP-aware comparison, and reference object tracking.
Template engine for generating DNS names (FQDN, target, FQDN-target) from Kubernetes object fields using a Go-style template language (e.g., {{.Name}}.example.com). Supports functions like isSource, replace, toLower, fromJson, and combine behavior for multiple templates. Reusable pattern for any Kubernetes-to-DNS mapping, with strict retry on first failure and shared template state protection via cloning.
Generic thread-safe TTL cache for zone data, parameterized by type T. Used by Exoscale and Scaleway providers to reduce API calls for zone lists. Implements time-based expiration with configurable TTL, thread-safe reads and writes, and a refresh callback. Clean abstraction that can be extracted and reused in any project needing a simple TTL cache with background refresh.
Generic set implementation with Insert, Delete, Has, List, and Sorted operations. Written in a functional style with immutable semantics. Simple, well-tested, and dependency-free. Demonstrates clean Go generics and can be reused in any Go project needing a basic set data structure.
Instrumented HTTP client with Prometheus metrics, connection pooling via DrainAndClose helper, and configurable timeouts. Used by multiple providers (webhook, RFC2136, etc.) for making HTTP requests to DNS APIs. Provides a reusable pattern for adding observability to HTTP clients without coupling to specific provider logic.
Decorator source wrapper that removes duplicate endpoints and validates record types (SRV, MX, PTR, etc.) before passing to the plan. Part of a composable pipeline (dedup -> NAT64 -> target filter -> post-processor -> PTR) that demonstrates clean wrapper pattern for source transformations. Self-contained and reusable for any source pipeline needing deduplication and validation.