Documentation
¶
Overview ¶
Package lb emulates the Application Load Balancer (SRS 5.8): the compute v1 load-balancing collections (forwarding rules, target HTTP(S) proxies, URL maps, backend services and buckets, health checks, SSL certificates and SSL policies, global and regional; FR-LB-001) served on the compute API, and a real in-process L7 proxy per forwarding rule wired exactly as GCP wires them: forwarding rule → target proxy → URL map → backend service or bucket → NEG endpoints (FR-LB-002..010). Cloud Armor security policies, target TCP, SSL and gRPC proxies and legacy HTTP(S) health checks are recorded: served by the API with no data-plane effect.
The routing engine (FR-LB-003) is the pure package lb/urlmap. Cloud CDN (services/cdn) wraps backends with enableCdn; Certificate Manager and Network Security resources come from the "certs" service (emu.CertManager).
Index ¶
- Variables
- func New(env *emu.Env) emu.Service
- type LogEntry
- type Options
- type Service
- func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error
- func (s *Service) CertificateMapTargets(ctx context.Context, certificateMap string) []certs.GclbTarget
- func (s *Service) CertsResourceUsers(ctx context.Context, name string) []string
- func (s *Service) DeleteLBResource(ctx context.Context, path string) error
- func (s *Service) DialBackend(ctx context.Context, addr string) (net.Conn, 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) ForwardingRuleIPs(ctx context.Context, project string) []string
- func (s *Service) LBResource(ctx context.Context, path string) ([]byte, error)
- func (s *Service) LoopbackAddrs() []string
- func (s *Service) Name() string
- func (s *Service) PushTransport() http.RoundTripper
- func (s *Service) PutLBResource(ctx context.Context, path string, body []byte) ([]byte, error)
- func (s *Service) Ready() error
- func (s *Service) Register(r emu.Router) error
- func (s *Service) Reset(ctx context.Context) error
- func (s *Service) ResetDone()
- func (s *Service) ResourceCounts() map[string]int
- func (s *Service) Restore(ctx context.Context, dir string) error
- func (s *Service) SetOptions(o Options)
- func (s *Service) SignedURLKeys(backend string) map[string][]byte
- func (s *Service) Snapshot(ctx context.Context, dir string) error
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) Stop(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
var Images = map[string]string{
"lb-edge": edgeImage,
}
Images lists the container images the lb service launches (pinned by tag; digests are pinned at release).
Functions ¶
Types ¶
type LogEntry ¶
type LogEntry struct {
InsertID string `json:"insertId"`
LogName string `json:"logName"`
Resource logResource `json:"resource"`
Timestamp string `json:"timestamp"`
Severity string `json:"severity"`
HTTPRequest httpRequest `json:"httpRequest"`
JSONPayload map[string]any `json:"jsonPayload"`
Trace string `json:"trace,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
LogEntry is the Cloud Logging entry of one load-balanced request.
type Options ¶
type Options struct {
// DirectDial makes the proxy dial NEG endpoints directly from the host
// instead of through the relay container (host-reachable test backends).
DirectDial bool
// Edge sends forwarding rules on ports below 1024 to the lb-edge
// container without trying to bind them, so the edge is used even on
// hosts that let unprivileged processes bind those ports. It still
// needs a container runtime.
Edge bool
}
Options tune the data plane (tests).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the lb service module.
func (*Service) CertificateMapTargets ¶
func (s *Service) CertificateMapTargets(ctx context.Context, certificateMap string) []certs.GclbTarget
CertificateMapTargets lists the target HTTPS proxies using a certificate map with their forwarding rule addresses (Certificate Manager gclbTargets).
func (*Service) CertsResourceUsers ¶
CertsResourceUsers returns load balancer resources referencing a Certificate Manager or Network Security resource (certificate maps, server TLS policies, backend authentication configs).
func (*Service) DeleteLBResource ¶ added in v0.6.0
DeleteLBResource implements emu.LoadBalancerResources.
func (*Service) DialBackend ¶
DialBackend connects to a backend endpoint exactly as the proxy does (through the lb-edge relay for GKE pod IPs). Diagnostics and tests use it to reach endpoints the host cannot route to.
func (*Service) EnvVars ¶
EnvVars implements emu.EnvVarer: one GCPEMU_LB_<NAME>=host:port per forwarding rule listener (FR-LB-002).
func (*Service) ExportSeed ¶ added in v0.6.0
ExportSeed implements emu.SeedExporter (FR-CORE-013). The section is a yaml.Node so that its lists keep the seed (dependency) order. SSL certificates are written with their private key inline; managed ones are provisioned again when applied. A forwarding rule's IP is written as the reserved address holding it, and left out when ephemeral. Signed URL keys have no seed entries and are not exported.
func (*Service) ForwardingRuleIPs ¶
ForwardingRuleIPs returns the forwarding rule IPs of a project and their mapped listener IPs (Certificate Manager load balancer authorization).
func (*Service) LBResource ¶ added in v0.6.0
LBResource implements emu.LoadBalancerResources.
func (*Service) LoopbackAddrs ¶ added in v0.6.0
LoopbackAddrs implements emu.LoopbackHolder: the 127.0.0.x addresses forwarding rules map to.
func (*Service) PushTransport ¶
func (s *Service) PushTransport() http.RoundTripper
PushTransport returns an HTTP transport for in-process clients (Pub/Sub push, FR-INT-011) that resolves host names through the emulated Cloud DNS, delivers requests addressed to a forwarding rule (or its mapped listener) straight to the load balancer's listener, and trusts the emulator CA in addition to the system roots, so a push endpoint such as https://app.example.test/push reaches the service behind the load balancer.
func (*Service) PutLBResource ¶ added in v0.6.0
PutLBResource implements emu.LoadBalancerResources.
func (*Service) Register ¶
Register installs the load-balancing collections on the compute API's mux (so selfLinks, operations, filters and paging are uniform with the rest of compute), the resource-in-use checks (FR-CORE-026) and the Web console's listener and routing reports (admin.go).
func (*Service) Reset ¶
Reset stops the managed-certificate and edge route passes in flight, waiting for them (bounded by ctx), so none writes a certificate or creates an edge container or attachment from the state before the Reset after it (#307); they run again from ResetDone. The store is wiped by the core.
func (*Service) ResetDone ¶ added in v0.9.0
func (s *Service) ResetDone()
ResetDone rebuilds the data plane from the reset store, dropping the listeners and backend runtime state from before the Reset (#450), and runs the managed-certificate and edge route loops again.
func (*Service) ResourceCounts ¶ added in v0.2.0
ResourceCounts implements emu.ResourceCounter.
func (*Service) Restore ¶ added in v0.6.0
Restore implements emu.Snapshotter: it rebuilds the data plane from the restored resources.
func (*Service) SetOptions ¶
SetOptions changes data-plane options (call before creating resources).
func (*Service) SignedURLKeys ¶
SignedURLKeys returns the signed URL/cookie keys (name → raw 128-bit key) of a backend service or bucket given by selfLink or path, for Cloud CDN signed request validation (FR-CDN-007).
func (*Service) Snapshot ¶ added in v0.6.0
Snapshot implements emu.Snapshotter: the load balancer's resources are in the store.
Source Files
¶
- accesslog.go
- admin.go
- backend.go
- backends.go
- bucket.go
- cdnpolicy.go
- dataplane.go
- dnsmap.go
- echoagent.go
- edge.go
- edgeagent.go
- frontend.go
- frules.go
- headers.go
- health.go
- healthchecks.go
- internalapi.go
- kinds.go
- l4proxies.go
- lan.go
- lb.go
- lenient.go
- listeners.go
- managedcerts.go
- proxies.go
- proxyproto.go
- published.go
- pushtransport.go
- refs.go
- resource.go
- securitypolicies.go
- seed.go
- sslcerts.go
- sslpolicies.go
- urlmaps.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package urlmap is the load balancer's URL map routing engine (FR-LB-003): a pure library that compiles a compute v1 UrlMap and selects, for a request, the backend (service or bucket), redirect, URL rewrite and header actions exactly as GCP's Application Load Balancers do:
|
Package urlmap is the load balancer's URL map routing engine (FR-LB-003): a pure library that compiles a compute v1 UrlMap and selects, for a request, the backend (service or bucket), redirect, URL rewrite and header actions exactly as GCP's Application Load Balancers do: |