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; zone IAM policies, FR-IAM-003; server and response policies, FR-DNS-006) and an authoritative DNS data plane on UDP and TCP that answers from the stored zones and response policies and forwards other names to the host resolver (FR-DNS-003/004).
Index ¶
- Variables
- func New(env *emu.Env) emu.Service
- type Service
- func (s *Service) Addr() string
- func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error
- func (s *Service) CreateZone(proj string, z *dnsv1.ManagedZone) (*dnsv1.ManagedZone, error)
- func (s *Service) DeleteZone(proj, name string) error
- func (s *Service) EnvVars(gateway string, endpoints map[string]string) map[string]string
- func (s *Service) ExportSeed(ctx context.Context) (any, error)
- func (s *Service) Name() string
- func (s *Service) Operations() []emu.OperationInfo
- func (s *Service) Ready() error
- func (s *Service) Register(r emu.Router) error
- func (s *Service) Reset(context.Context) error
- func (s *Service) Resolve(ctx context.Context, name string, qtype uint16) ([]mdns.RR, error)
- func (s *Service) ResourceCounts() map[string]int
- func (s *Service) SetAddressMapper(f func(ip net.IP, network string) net.IP)
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) Stop(ctx context.Context) error
- func (s *Service) UpsertRRSet(proj, zone string, rs *dnsv1.ResourceRecordSet) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the Cloud DNS service module.
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 ¶
DeleteZone deletes an empty zone (only the apex SOA and NS remain); otherwise it fails with containerNotEmpty as Cloud DNS does.
func (*Service) EnvVars ¶
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) ExportSeed ¶ added in v0.6.0
ExportSeed implements emu.SeedExporter: every managed zone with its record sets. The SOA record (whose serial every change bumps) and an apex NS record the zone was created with are left out, as creating the zone makes them. Routing-policy record sets, TTLs of 0, forwarding, peering, DNSSEC and logging configs, GKE cluster bindings, DNS policies and response policies have no seed form and are not exported.
func (*Service) Operations ¶ added in v0.2.0
func (s *Service) Operations() []emu.OperationInfo
Operations implements emu.OperationLister. A change is an Operation on its managed zone (CONTEXT.md), pending until the configured latency has passed; managedZoneOperations complete at once.
func (*Service) Register ¶
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, and the console's query endpoint on the admin API (admin.go).
func (*Service) Reset ¶
Reset drops the in-memory query index; it is rebuilt from the store on the next query.
func (*Service) Resolve ¶
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) ResourceCounts ¶ added in v0.2.0
ResourceCounts implements emu.ResourceCounter.
func (*Service) SetAddressMapper ¶
SetAddressMapper installs a function that rewrites A record addresses in answers (UDP/TCP server and Resolve) for a client on network ("" outside every VPC): the load balancer maps forwarding rule IPs to the local listeners that serve them for host clients (FR-LB-002, FR-INT-004). f returns nil to leave an address unchanged.
func (*Service) Start ¶
Start opens the DNS data plane: TCP via env.Listen("dns") and UDP on the same port number.
A dynamic port must be free for both protocols. Windows reserves different port ranges for each and hands out ephemeral ports in sequence, so every retry of TCP's pick can land in one UDP-reserved block (#206); without a --port-range, retries try random ephemeral ports instead.
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.