hostalias

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

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

func (r *Resolver) Bind(store *cluster.Store)

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

func (r *Resolver) Lookup(host string) (string, bool)

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.

func (*Resolver) Set

func (r *Resolver) Set(aliases []corev1.HostAlias)

Set replaces the current alias table with the given list. Later entries win on duplicate hostnames so that a single IP-change push is deterministic. Hostnames are matched case-insensitively.

func (*Resolver) Snapshot

func (r *Resolver) Snapshot() map[string]string

Snapshot returns a copy of the current override map for diagnostics/testing.

Jump to

Keyboard shortcuts

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