dns

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InternalDomain is the cluster internal domain for service discovery. All DNS queries ending with this suffix
	// will be resolved using the internal DNS server.
	InternalDomain = "internal."
	// Port is the standard DNS port.
	Port = 53
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterResolver

type ClusterResolver struct {
	// contains filtered or unexported fields
}

ClusterResolver implements Resolver by tracking containers in the cluster and resolving service names to their IP addresses.

func NewClusterResolver

func NewClusterResolver(store *store.Store) *ClusterResolver

NewClusterResolver creates a new cluster resolver using the cluster store.

func (*ClusterResolver) Resolve

func (r *ClusterResolver) Resolve(serviceName string) []netip.Addr

Resolve returns IP addresses of the service containers.

func (*ClusterResolver) Run

func (r *ClusterResolver) Run(ctx context.Context) error

Run starts watching for container changes and updates DNS records accordingly.

type Resolver

type Resolver interface {
	// Resolve returns a list of IP addresses of the service containers.
	// An empty list is returned if no service is found.
	Resolve(serviceName string) []netip.Addr
}

Resolver is an interface for resolving service names to IP addresses.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an embedded internal DNS server for service discovery and forwarding external queries to upstream DNS servers.

func NewServer

func NewServer(listenAddr netip.Addr, localSubnet netip.Prefix, resolver Resolver, upstreams []netip.AddrPort) (*Server, error)

NewServer creates a new DNS server with the given configuration. If upstreams is nil, nameservers from /etc/resolv.conf will be used. An empty upstreams list means to only resolve internal DNS queries and not forward any external queries.

func (*Server) ListenAddr added in v0.7.1

func (s *Server) ListenAddr() netip.Addr

ListenAddr returns the address the DNS server is listening on.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the DNS server listening on both UDP and TCP ports. The server on TCP is not critical so it won't return an error if it fails to start. The server will run until the context is canceled or an error occurs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL