Documentation
¶
Overview ¶
Package hostalias provides an in-process /etc/hosts-style resolver driven by the Manager-pushed ClusterConfig.HostAliases list.
Design rationale:
Worker pods cannot mutate their own Pod spec, so hostAliases delivered at install time via YAML would require a Deployment-level rollout whenever a remote endpoint changes. Instead the Manager broadcasts host-alias entries through the existing sync channel; each Worker process consumes them in memory and overrides DNS lookups for the owning Go/gRPC components (ExtProc DNS cache, CrossClusterForwarder HTTP client).
The Resolver is intentionally tiny: a hostname → IP lookup table plus a net.Dialer DialContext hook. It does not fall back to the system resolver itself — callers decide whether an override miss should trigger net.Lookup or some other behaviour (e.g. ExtProc's dnsCache currently falls back).
Index ¶
- type Resolver
- func (r *Resolver) Bind(store *cluster.Store)
- func (r *Resolver) DialContext(base *net.Dialer) func(ctx context.Context, network, addr string) (net.Conn, error)
- func (r *Resolver) Lookup(host string) (string, bool)
- func (r *Resolver) Set(aliases []corev1.HostAlias)
- func (r *Resolver) Snapshot() map[string]string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver keeps a read-optimised host → IP map that is swapped atomically on every Manager push. It is safe for concurrent use.
func New ¶
func New() *Resolver
New returns an empty Resolver. Attach it to the cluster.Store via Bind so it picks up subsequent snapshots automatically.
func (*Resolver) Bind ¶
Bind subscribes r to store's host-alias updates. Safe to call once at startup; the subscription lives for the duration of the process.
func (*Resolver) DialContext ¶
func (r *Resolver) DialContext(base *net.Dialer) func(ctx context.Context, network, addr string) (net.Conn, error)
DialContext returns a DialContext function suitable for http.Transport or any net.Dialer-consuming client. It substitutes the IP for known hostnames before handing off to the provided base dialer (nil uses a default net.Dialer with standard behaviour).
The substitution preserves the original port, so callers don't need to know which scheme (http/https) is in use.
func (*Resolver) Lookup ¶
Lookup returns the override IP for host and true when an override exists. The second return value is false when there is no override; callers fall back to whatever resolver makes sense for them.