Documentation
¶
Overview ¶
Package kubernetes - Simple DNS cache
Package kubernetes - Kubernetes API client ¶
Package kubernetes - Common constants for Kubernetes middleware ¶
Package kubernetes provides a Kubernetes DNS middleware for SDNS ¶
Package kubernetes - Service registry ¶
Package kubernetes - DNS resolver ¶
Package kubernetes - DNS types
Index ¶
- Constants
- func FormatPodIP(ip net.IP) string
- func FormatReverseIP(ip net.IP) string
- func GetMessageID(wire []byte) uint16
- func ParsePodIP(podPart string) net.IP
- func ParseReverseIP(labels []string) (net.IP, bool)
- func UpdateMessageID(wire []byte, msgID uint16)
- type Cache
- type Client
- type ClientProfile
- type ClientProfiles
- type DayPattern
- type DependencyInfo
- type Endpoint
- type HourPattern
- type Kubernetes
- type NamespaceCorrelation
- type NamespaceInfo
- type ObjectRef
- type Pod
- type Port
- type PredictedService
- type PrefetchStrategy
- type QueryRecord
- type Registry
- func (r *Registry) AddPod(pod *Pod) error
- func (r *Registry) AddService(svc *Service) error
- func (r *Registry) DeletePod(name, namespace string) error
- func (r *Registry) DeleteService(name, namespace string) error
- func (r *Registry) GetEndpoints(service, namespace string) []Endpoint
- func (r *Registry) GetPodByIP(ip string) *Pod
- func (r *Registry) GetPodByName(name, namespace string) *Pod
- func (r *Registry) GetPods(namespace string) []*Pod
- func (r *Registry) GetService(name, namespace string) *Service
- func (r *Registry) GetServiceByIP(ip []byte) *Service
- func (r *Registry) SetEndpoints(service, namespace string, endpoints []Endpoint) error
- func (r *Registry) Stats() map[string]int
- type Resolver
- type Response
- type RingBuffer
- type Service
- type ServiceDependencyGraph
- type ServiceNode
- type ShardedRegistry
- func (r *ShardedRegistry) AddPod(pod *Pod)
- func (r *ShardedRegistry) AddService(svc *Service)
- func (r *ShardedRegistry) GetEndpoints(service, namespace string) []Endpoint
- func (r *ShardedRegistry) GetStats() map[string]int64
- func (r *ShardedRegistry) ResolveQuery(qname string, qtype uint16) ([]dns.RR, bool)
- func (r *ShardedRegistry) SetEndpoints(service, namespace string, endpoints []Endpoint)
- func (r *ShardedRegistry) SetTTLs(service, pod, srv, ptr uint32)
- type SmartPredictor
- type TimeBasedPatterns
- type WeightedService
- type ZeroAllocCache
- func (c *ZeroAllocCache) Clear()
- func (c *ZeroAllocCache) Get(qname string, qtype uint16, msgID ...uint16) any
- func (c *ZeroAllocCache) GetEntry(qname string, qtype uint16) []byte
- func (c *ZeroAllocCache) Stats() map[string]any
- func (c *ZeroAllocCache) Store(qname string, qtype uint16, data any, ttl ...uint32)
- func (c *ZeroAllocCache) StoreWire(qname string, qtype uint16, wire []byte, ttl uint32)
Constants ¶
const ( // Cache sizes and limits CacheMaxEntries = 10000 // Maximum number of entries in zero-alloc cache CacheIndexSize = 16384 // Must be power of 2 for fast modulo CacheLockStripes = 256 // Number of lock stripes for sharding CacheMaxWireSize = 4096 // Maximum wire format DNS message size (EDNS0 support) CacheLinearProbeSize = 16 // Maximum linear probe attempts for collision handling // Cache cleanup and expiry CacheCleanupInterval = 10 * time.Second CacheDefaultTTL = 30 // Default TTL in seconds )
Cache configuration constants
const ( RegistryServiceShards = 256 // Number of shards for services RegistryPodShards = 256 // Number of shards for pods )
Sharding constants for registry
const ( PredictorBufferSize = 1024 // Size of circular buffer for recent queries PredictorMaxPredictions = 10 // Maximum predictions in pool PredictorMaxResults = 5 // Maximum predictions to return PredictorThresholdDiv = 10 // Threshold divisor (>10% probability) PredictorTrainInterval = 30 * time.Second )
Predictor constants
const ( IPv4AddressSize = 4 // Size of IPv4 address in bytes IPv6AddressSize = 16 // Size of IPv6 address in bytes )
Network constants
const ( DNSTypeA = 1 // A record type DNSTypeAAAA = 28 // AAAA record type )
DNS query type constants (for ML predictor)
const ( FNVOffsetBasis = 14695981039346656037 // FNV-1a offset basis FNVPrime = 1099511628211 // FNV-1a prime HashMultiplier = 31 // Simple hash multiplier )
Hash constants
const ( SRVPriority = 0 // Default SRV priority SRVWeight = 100 // Default SRV weight for single entry SRVWeight1 = 1 // Alternative SRV weight )
SRV record constants
const ( IPv4LastOctetIndex = 3 // Index of last octet in IPv4 address IPv6LastByteIndex = 15 // Index of last byte in IPv6 address )
IP byte positions
const ( WireMessageIDOffset = 0 // Offset of message ID in DNS wire format WireMessageIDSize = 2 // Size of message ID in bytes )
Wire format constants
const ( BenchmarkServiceStart = 1 // Starting index for benchmark services NetworkOctet10 = 10 // First octet for test IPs (10.x.x.x) NetworkOctet96 = 96 // Second octet for test IPs (10.96.x.x) NetworkOctet244 = 244 // Third octet for test pod IPs (10.244.x.x) IPv6TestPrefix = 0xfe80 // IPv6 test prefix (fe80::) )
Benchmark and test constants
const ( PortHTTPS = 443 // HTTPS port PortDNS = 53 // DNS port )
Port numbers for test services
const ( DefaultServiceTTL = uint32(30) DefaultPodTTL = uint32(30) DefaultSRVTTL = uint32(30) DefaultPTRTTL = uint32(30) )
DNS TTL values (configurable)
const (
ClientStopTimeout = 5 * time.Second // Timeout for client stop operation
)
Client timeout constants
const (
DemoServiceCount = 10 // Number of demo services to create
)
Service population constants (for demo/test data)
const (
PercentageMultiplier = 100
)
Registry statistics percentage calculation
const (
StatsLogInterval = 30 * time.Second // Interval for logging statistics
)
Performance monitoring constants
Variables ¶
This section is empty.
Functions ¶
func FormatPodIP ¶
FormatPodIP formats an IP for pod DNS name IPv4: 10.244.1.1 -> 10-244-1-1 IPv6: 2001:db8::1 -> 2001-db8--1
func FormatReverseIP ¶
FormatReverseIP formats an IP for reverse DNS IPv4: 10.96.0.1 -> 1.0.96.10.in-addr.arpa IPv6: 2001:db8::1 -> 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa
func GetMessageID ¶
GetMessageID extracts message ID from wire format
func ParsePodIP ¶
ParsePodIP parses both IPv4 and IPv6 pod query formats IPv4: 10-244-1-1.namespace.pod.cluster.local IPv6: 2001-db8--1.namespace.pod.cluster.local or
2001-0db8-0000-0000-0000-0000-0000-0001.namespace.pod.cluster.local
func ParseReverseIP ¶
ParseReverseIP parses both IPv4 and IPv6 reverse queries IPv4: 1.0.96.10.in-addr.arpa -> 10.96.0.1 IPv6: 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa
func UpdateMessageID ¶
UpdateMessageID updates the message ID in wire format data This modifies the data in-place with zero allocations
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores DNS responses.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client connects to Kubernetes API.
type ClientProfile ¶
type ClientProfile struct {
// contains filtered or unexported fields
}
type ClientProfiles ¶
type ClientProfiles struct {
// contains filtered or unexported fields
}
ClientProfiles tracks per-client query patterns
type DayPattern ¶
type DayPattern struct {
// contains filtered or unexported fields
}
type DependencyInfo ¶
type DependencyInfo struct {
// contains filtered or unexported fields
}
type Endpoint ¶
type Endpoint struct {
Addresses []string // Dual-stack: [IPv4, IPv6] addresses
Hostname string // Optional hostname
Ready bool // Is endpoint ready
TargetRef *ObjectRef // Reference to pod
}
Endpoint represents a service endpoint
type HourPattern ¶
type HourPattern struct {
// contains filtered or unexported fields
}
type Kubernetes ¶
type Kubernetes struct {
// contains filtered or unexported fields
}
Kubernetes middleware for DNS resolution
func (*Kubernetes) ServeDNS ¶
func (k *Kubernetes) ServeDNS(ctx context.Context, ch *middleware.Chain)
ServeDNS handles DNS queries
type NamespaceCorrelation ¶
type NamespaceCorrelation struct {
// contains filtered or unexported fields
}
NamespaceCorrelation tracks services queried together in same namespace
type NamespaceInfo ¶
type NamespaceInfo struct {
// contains filtered or unexported fields
}
type Pod ¶
type Pod struct {
Name string
Namespace string
IPs []string // Dual-stack: [IPv4, IPv6] addresses
Hostname string // Pod hostname
Subdomain string // For StatefulSet DNS
}
Pod represents a Kubernetes pod
type PredictedService ¶
type PredictedService struct {
Service string
Confidence float64
Reason string // Why this was predicted (for debugging)
}
PredictedService represents a predicted service with confidence
type PrefetchStrategy ¶
type PrefetchStrategy struct {
// contains filtered or unexported fields
}
PrefetchStrategy defines common prefetch patterns for Kubernetes services
func NewPrefetchStrategy ¶
func NewPrefetchStrategy() *PrefetchStrategy
NewPrefetchStrategy creates a new prefetch strategy with common patterns
func (*PrefetchStrategy) GetPrefetchPriority ¶
func (ps *PrefetchStrategy) GetPrefetchPriority(service string, confidence float64) float64
GetPrefetchPriority returns priority (0-1) for prefetching a service
func (*PrefetchStrategy) GetRelatedServices ¶
func (ps *PrefetchStrategy) GetRelatedServices(service, namespace string) []string
GetRelatedServices returns services likely to be queried together
func (*PrefetchStrategy) ShouldPrefetchType ¶
func (ps *PrefetchStrategy) ShouldPrefetchType(currentType uint16, service string) []uint16
ShouldPrefetchType determines if a record type should be prefetched
type QueryRecord ¶
type QueryRecord struct {
// contains filtered or unexported fields
}
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores Kubernetes resources
func (*Registry) AddService ¶
AddService adds or updates a service
func (*Registry) DeleteService ¶
DeleteService removes a service
func (*Registry) GetEndpoints ¶
GetEndpoints retrieves endpoints for a service
func (*Registry) GetPodByIP ¶
GetPodByIP retrieves a pod by IP
func (*Registry) GetPodByName ¶
GetPodByName retrieves a pod by name
func (*Registry) GetPods ¶
Stats returns registry statistics GetPods returns all pods in a namespace
func (*Registry) GetService ¶
GetService retrieves a service
func (*Registry) GetServiceByIP ¶
GetServiceByIP finds service by ClusterIP (supports dual-stack)
func (*Registry) SetEndpoints ¶
SetEndpoints sets endpoints for a service
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver handles DNS resolution for Kubernetes resources
func NewResolver ¶
NewResolver creates a new resolver
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer for efficient recent query tracking
func NewRingBuffer ¶
func NewRingBuffer(size int) *RingBuffer
func (*RingBuffer) Add ¶
func (rb *RingBuffer) Add(record QueryRecord)
func (*RingBuffer) GetRecent ¶
func (rb *RingBuffer) GetRecent(n int) []QueryRecord
type Service ¶
type Service struct {
Name string
Namespace string
Type string // ClusterIP, NodePort, LoadBalancer, ExternalName
ClusterIPs [][]byte // Dual-stack: [IPv4, IPv6] addresses
IPFamilies []string // ["IPv4", "IPv6"] or ["IPv6", "IPv4"]
ExternalName string // For ExternalName type
Headless bool // True if ClusterIP is None
Ports []Port
}
Service represents a Kubernetes service
type ServiceDependencyGraph ¶
type ServiceDependencyGraph struct {
// contains filtered or unexported fields
}
ServiceDependencyGraph tracks which services are queried together
type ServiceNode ¶
type ServiceNode struct {
// contains filtered or unexported fields
}
type ShardedRegistry ¶
type ShardedRegistry struct {
// contains filtered or unexported fields
}
ShardedRegistry - Lock-free sharded registry for massive concurrency
func NewShardedRegistry ¶
func NewShardedRegistry() *ShardedRegistry
NewShardedRegistry creates the beast
func (*ShardedRegistry) AddPod ¶
func (r *ShardedRegistry) AddPod(pod *Pod)
AddPod adds or updates a pod
func (*ShardedRegistry) AddService ¶
func (r *ShardedRegistry) AddService(svc *Service)
AddService adds or updates a service
func (*ShardedRegistry) GetEndpoints ¶
func (r *ShardedRegistry) GetEndpoints(service, namespace string) []Endpoint
GetEndpoints gets endpoints for a service
func (*ShardedRegistry) GetStats ¶
func (r *ShardedRegistry) GetStats() map[string]int64
GetStats returns registry statistics
func (*ShardedRegistry) ResolveQuery ¶
ResolveQuery resolves DNS query with minimal locking
func (*ShardedRegistry) SetEndpoints ¶
func (r *ShardedRegistry) SetEndpoints(service, namespace string, endpoints []Endpoint)
SetEndpoints sets endpoints for a service
func (*ShardedRegistry) SetTTLs ¶
func (r *ShardedRegistry) SetTTLs(service, pod, srv, ptr uint32)
SetTTLs sets custom TTL values
type SmartPredictor ¶
type SmartPredictor struct {
// contains filtered or unexported fields
}
SmartPredictor uses intelligent pattern recognition for Kubernetes DNS
func NewSmartPredictor ¶
func NewSmartPredictor() *SmartPredictor
NewSmartPredictor creates an intelligent predictor
func (*SmartPredictor) Predict ¶
func (sp *SmartPredictor) Predict(clientIP, currentService string) []PredictedService
Predict returns services likely to be queried next
func (*SmartPredictor) Record ¶
func (sp *SmartPredictor) Record(clientIP, service string, qtype uint16)
Record records a query and updates patterns
func (*SmartPredictor) Stats ¶
func (sp *SmartPredictor) Stats() map[string]any
Stats returns predictor statistics
type TimeBasedPatterns ¶
type TimeBasedPatterns struct {
// contains filtered or unexported fields
}
TimeBasedPatterns recognizes temporal patterns
type WeightedService ¶
type WeightedService struct {
// contains filtered or unexported fields
}
type ZeroAllocCache ¶
type ZeroAllocCache struct {
// contains filtered or unexported fields
}
ZeroAllocCache - TRUE zero-allocation DNS cache This implementation achieves zero allocations by: 1. Pre-allocating all memory at initialization 2. Storing DNS messages in wire format only 3. Using fixed-size buffers and entries 4. Returning direct references to cached data
func NewZeroAllocCache ¶
func NewZeroAllocCache() *ZeroAllocCache
NewZeroAllocCache creates a truly zero-allocation cache All memory is allocated upfront
func (*ZeroAllocCache) Get ¶
func (c *ZeroAllocCache) Get(qname string, qtype uint16, msgID ...uint16) any
Get returns the cached DNS message (compatibility method for tests) This method DOES allocate as it needs to unpack the wire format
func (*ZeroAllocCache) GetEntry ¶
func (c *ZeroAllocCache) GetEntry(qname string, qtype uint16) []byte
GetEntry returns a direct pointer to the wire format data This achieves TRUE zero allocation by returning the actual buffer IMPORTANT: Caller MUST NOT modify the returned data!
func (*ZeroAllocCache) Stats ¶
func (c *ZeroAllocCache) Stats() map[string]any
Stats returns cache statistics