lb

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 56 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": edgeImage,
}

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 forces the lb-edge container for forwarding rules on privileged
	// ports even when binding fails for another reason.
	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) 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) EnvVars

func (s *Service) EnvVars(gateway string, endpoints map[string]string) map[string]string

EnvVars implements emu.EnvVarer: one GCPEMU_LB_<NAME>=host:port per forwarding rule listener (FR-LB-002).

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) 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 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) 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) and the resource-in-use checks (FR-CORE-026).

func (*Service) Reset

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

Reset drops the data plane's runtime state; the store is wiped by the core.

func (*Service) ResourceCounts added in v0.2.0

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

ResourceCounts implements emu.ResourceCounter.

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

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