dns

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dns emulates Cloud DNS (SRS 5.2): the dns.googleapis.com v1 REST control plane (managed zones, record sets, changes; FR-DNS-001/002) and an authoritative DNS data plane on UDP and TCP that answers from the stored zones and forwards other names to the host resolver (FR-DNS-003/004).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNXDomain = errors.New("dns: name does not exist")
	ErrRefused  = errors.New("dns: query refused")
	ErrServFail = errors.New("dns: server failure")
)

Errors returned by Resolve.

Functions

func New

func New(env *emu.Env) emu.Service

New returns the service.

Types

type Service

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

Service is the Cloud DNS service module.

func (*Service) Addr

func (s *Service) Addr() string

Addr returns the data plane's host:port (UDP and TCP).

func (*Service) ApplySeed

func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error

ApplySeed implements emu.Seeder.

func (*Service) CreateZone

func (s *Service) CreateZone(proj string, z *dnsv1.ManagedZone) (*dnsv1.ManagedZone, error)

CreateZone creates a managed zone with its automatic SOA and NS record sets (recorded as change "0", like Cloud DNS). It does not check IAM.

func (*Service) DeleteZone

func (s *Service) DeleteZone(proj, name string) error

DeleteZone deletes an empty zone (only the apex SOA and NS remain); otherwise it fails with containerNotEmpty as Cloud DNS does.

func (*Service) EnvVars

func (s *Service) EnvVars(gateway string, endpoints map[string]string) map[string]string

EnvVars implements emu.EnvVarer. gcloud's dns client has base URL https://dns.googleapis.com/dns/v1/, so the override includes /dns/v1/.

func (*Service) Name

func (s *Service) Name() string

func (*Service) Ready

func (s *Service) Ready() error

Ready reports whether the data plane is listening.

func (*Service) Register

func (s *Service) Register(r emu.Router) error

Register mounts the REST API at /dns/v1/ (root, as the Go client and gcloud address it), under the /dns/ gateway prefix and in host mode.

func (*Service) Reset

func (s *Service) Reset(context.Context) error

Reset drops the in-memory query index; it is rebuilt from the store on the next query.

func (*Service) Resolve

func (s *Service) Resolve(ctx context.Context, name string, qtype uint16) ([]mdns.RR, error)

Resolve answers a query the way the data plane would and returns the answer section. A name that does not exist yields ErrNXDomain; a name outside every zone is forwarded (ErrRefused when forwarding is off). NODATA is an empty slice with a nil error. Other services (GKE CoreDNS, LB) use it to resolve emulated names in-process.

func (*Service) SetAddressMapper

func (s *Service) SetAddressMapper(f func(net.IP) net.IP)

SetAddressMapper installs a function that rewrites A record addresses in answers (UDP/TCP server and Resolve): the load balancer maps forwarding rule IPs to the local listeners that serve them (FR-LB-002, FR-INT-004). f returns nil to leave an address unchanged.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start opens the DNS data plane: TCP via env.Listen("dns") and UDP on the same port number.

func (*Service) Stop

func (s *Service) Stop(ctx context.Context) error

Stop shuts the data plane down.

func (*Service) UpsertRRSet

func (s *Service) UpsertRRSet(proj, zone string, rs *dnsv1.ResourceRecordSet) error

UpsertRRSet creates or replaces an rrset in a zone as one change. It does not check IAM; other services (e.g. the LB registering A records for forwarding rules) may use it.

Jump to

Keyboard shortcuts

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