lb

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 64 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 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

Constants

This section is empty.

Variables

View Source
var Images = map[string]string{
	"lb-edge": edgeagent.Image,
}

Images lists the container images the lb service launches (pinned by tag; digests are pinned at release).

Functions

func New

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

New returns the service.

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) ApplySeed

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

ApplySeed implements emu.Seeder.

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

func (s *Service) CertsResourceUsers(ctx context.Context, name string) []string

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

func (s *Service) DeleteLBResource(ctx context.Context, path string) error

DeleteLBResource implements emu.LoadBalancerResources.

func (*Service) DialBackend

func (s *Service) DialBackend(ctx context.Context, addr string) (net.Conn, error)

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) ExportSeed added in v0.6.0

func (s *Service) ExportSeed(ctx context.Context) (any, error)

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

func (s *Service) ForwardingRuleIPs(ctx context.Context, project string) []string

ForwardingRuleIPs returns the forwarding rule IPs of a project and their mapped listener IPs (Certificate Manager load balancer authorization).

func (*Service) LANClaims added in v0.12.0

func (s *Service) LANClaims(owner string) map[string][]string

LANClaims implements emu.LANFrontends.

func (*Service) LANFrontendAddrs added in v0.12.0

func (s *Service) LANFrontendAddrs() []emu.LANFrontendAddrs

LANFrontendAddrs implements emu.LANFrontendLister.

func (*Service) LBResource added in v0.6.0

func (s *Service) LBResource(ctx context.Context, path string) ([]byte, error)

LBResource implements emu.LoadBalancerResources.

func (*Service) LoopbackAddrs added in v0.6.0

func (s *Service) LoopbackAddrs() []string

LoopbackAddrs implements emu.LoopbackHolder: the 127.0.0.x addresses forwarding rules map to.

func (*Service) NEGEndpointHealth added in v0.15.0

func (s *Service) NEGEndpointHealth(ctx context.Context, project, zone, neg, ip string, port int) []emu.NEGBackendHealth

NEGEndpointHealth implements emu.NEGHealth for GKE's NEG readiness gate (ADR 0071): the network endpoint ip:port's state in each backend service with a health check that has the zonal NEG as a backend, by relative name, as getHealth reports it. Every backend service counts, whether or not a forwarding rule routes to it.

func (*Service) Name

func (s *Service) Name() string

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 Instance CA in addition to the Public roots (never another Instance's CA, #1138), 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

func (s *Service) PutLBResource(ctx context.Context, path string, body []byte) ([]byte, error)

PutLBResource implements emu.LoadBalancerResources.

func (*Service) Ready

func (s *Service) Ready() error

Ready: the proxy needs nothing external to start.

func (*Service) Register

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

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) ReissueManagedCerts added in v0.13.0

func (s *Service) ReissueManagedCerts(ctx context.Context)

ReissueManagedCerts runs a managed-certificate pass now, so that a CA rotation issues every ACTIVE certificate again before it returns.

func (*Service) ReservedAddrs added in v0.14.0

func (s *Service) ReservedAddrs() []string

ReservedAddrs implements emu.AddressReserver: the live Edge aliases, so that a container joining the lb network after them, such as a VM relay recreated (ADR 0050), does not take one (#900). The runtime asks while the Edge relay holds e.mu (a join), so this reads only resMu.

func (*Service) Reset

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

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

func (s *Service) ResourceCounts() map[string]int

ResourceCounts implements emu.ResourceCounter.

func (*Service) Restore added in v0.6.0

func (s *Service) Restore(ctx context.Context, dir string) error

Restore implements emu.Snapshotter: it rebuilds the data plane from the restored resources.

func (*Service) SetLANFrontends added in v0.12.0

func (s *Service) SetLANFrontends(owner string, fes []emu.LANFrontend)

SetLANFrontends implements emu.LANFrontends. A frontend registered again unchanged keeps the addresses it holds.

func (*Service) SetOptions

func (s *Service) SetOptions(o Options)

SetOptions changes data-plane options (call before creating resources).

func (*Service) SignedURLKeys

func (s *Service) SignedURLKeys(backend string) map[string][]byte

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

func (s *Service) Snapshot(ctx context.Context, dir string) error

Snapshot implements emu.Snapshotter: the load balancer's resources are in the store.

func (*Service) Start

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

Start brings up listeners for stored forwarding rules and the background loops (health checks, managed certificates, NEG refresh).

func (*Service) Stop

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

Stop closes every listener and stops background work.

func (*Service) WaitConditions added in v0.10.0

func (s *Service) WaitConditions() map[string]emu.WaitCondition

WaitConditions implements emu.WaitConditioner (FR-CI-007).

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:

Jump to

Keyboard shortcuts

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