gcpcompute

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 40 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.

README

Compute Engine

Parity grade: B · SDK cloud.google.com/go/compute@v1.72.0 · last audited 2026-10-26 (cf047c847)

Coverage

Metric Value
PARITY entries audited 1 (1 ok)
Feature families 8 (5 ok, 2 partial, 1 gap)
Known gaps 6
Deferred items 0
Resource leaks unknown
Known gaps
  • Load balancing: service attachments, certificate maps and regional TCP/SSL certificates managed by Certificate Manager are stored without effect; Cloud Armor organization policies and associations and securityPolicies.listPreconfiguredExpressionSets (the rule ids and sensitivities of each WAF expression set are not documented on the pages available, so no honest response exists) are not routed; backend bucket existence is not checked against gcpstorage (lb_backend.go prepBackendBucket; the Compute reference does not say whether insert validates the bucket, so it was not wired).
  • Instance templates: regional-only fields beyond the stored properties are not modelled; regional composite health checks and health check services (regionCompositeHealthChecks, regionHealthCheckServices, regionHealthSources) are not routed.
  • Interconnect: interconnects.getDiagnostics and getMacsecConfig (the latter returns generated CKN/CAK secrets), interconnect attachment groups, interconnect groups, interconnect remote locations (Cross-Cloud Interconnect), PARTNER_PROVIDER attachments and the full interconnect location catalogue are not implemented. Also not routed (404): shared VPC, regional disk async replication and policies, machine image encryption and aggregate reservations. Peering routes are not added to routes.list.
  • Instances: aliasIpv6Ranges and BYOIP subnet prefixes are 400; Local SSD for n4, c3, t2d, t2a, f1 and g1 is 400 because their counts are not modelled and N2D takes one count set for every size; GPUs for accelerator-optimized machine types (A2, A3, G2) are not modelled; instances.update uses a modelled field classification (see Instances.Update).
  • Only 9 image families, 3 persistent disk types and the machine families e2, n1, n2, n2d, n4, c3, t2d and t2a exist (no c2, c4, m-series, accelerator-optimized or shared-core beyond e2, f1 and g1), and every zone offers every machine type; quota limits are emulator defaults that are not enforced.
  • The emulator does not enforce IAM or return permission errors.

More

Documentation

Index

Constants

View Source
const DefaultPort = 8142

DefaultPort is the dedicated Compute Engine REST listener's default TCP port.

View Source
const (
	// HealthEndpointKey is the instance metadata key that points autohealing probes at a real
	// emulator-run endpoint (host:port, loopback IP literal only), e.g. a container's published port.
	HealthEndpointKey = "gopherstack-health-endpoint"
)

Variables

View Source
var ErrNilAppContext = errors.New("gcpcompute: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

View Source
var ErrSnapshotNull = errors.New("gcpcompute: snapshot contains a null record")

ErrSnapshotNull is returned when a snapshot holds a null record.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Reason  string
	Message string
	Status  int
}

APIError is a Google JSON REST error.

func (*APIError) Error

func (e *APIError) Error() string

Error implements error.

type ConfigProvider

type ConfigProvider interface {
	GetGCPComputeSettings() Settings
}

ConfigProvider extracts Compute Engine configuration from the AppContext Config.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	Port int
	// contains filtered or unexported fields
}

Handler serves the Compute Engine v1 REST API on a dedicated listener.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a Handler; callers override Port from Settings.

func (*Handler) Addr

func (h *Handler) Addr() string

Addr returns the bound listener address, or "" before StartWorker.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(c *echo.Context) string

ExtractOperation returns the operation name for metrics.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(c *echo.Context) string

ExtractResource returns the project for metrics.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists the supported operations as collection@scope.verb.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns the Echo handler for all Compute Engine REST requests.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset removes all state.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches: Compute Engine runs on its own listener.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown stops the listener.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker binds the REST listener synchronously so a port conflict is returned to the caller.

type HealthProbe

type HealthProbe struct {
	Type    string
	Address string
	Host    string
	Path    string
	Timeout time.Duration
}

HealthProbe is one health check probe against an instance endpoint.

type HealthProber

type HealthProber interface {
	Probe(ctx context.Context, p HealthProbe) string
}

HealthProber probes an instance endpoint and returns HEALTHY, UNHEALTHY (reachable but not conforming) or TIMEOUT (unreachable).

type InMemoryBackend

type InMemoryBackend struct {
	// contains filtered or unexported fields
}

InMemoryBackend holds all Compute Engine state under one lock.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend on the wall clock.

func (*InMemoryBackend) EachSubnetwork

func (b *InMemoryBackend) EachSubnetwork(project string, fn func(gcpcontainer.SubnetInfo))

EachSubnetwork calls fn for every subnetwork of project in a stable order.

func (*InMemoryBackend) MachineTypeExists

func (b *InMemoryBackend) MachineTypeExists(machineType string) bool

MachineTypeExists reports whether a predefined or custom machine type name is valid.

func (*InMemoryBackend) NetworkExists

func (b *InMemoryBackend) NetworkExists(project, network string) bool

NetworkExists reports whether the VPC network exists in project.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset removes all state.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads backend state from a snapshot.

func (*InMemoryBackend) SecondaryRange

func (b *InMemoryBackend) SecondaryRange(project, region, subnetwork, rangeName string) (string, bool)

SecondaryRange returns the CIDR of a subnetwork's named secondary range.

func (*InMemoryBackend) SetClock

func (b *InMemoryBackend) SetClock(now func() time.Time, sleep func(context.Context, time.Duration))

SetClock replaces the clock and the sleep used by Operations.Wait; tests inject a fake clock here.

func (*InMemoryBackend) SetHealthProber

func (b *InMemoryBackend) SetHealthProber(p HealthProber)

SetHealthProber replaces the autohealing prober; tests inject a fake here.

func (*InMemoryBackend) SetTiming

func (b *InMemoryBackend) SetTiming(t Timing)

SetTiming replaces the operation and instance transition delays.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises the backend state.

func (*InMemoryBackend) SubnetworkExists

func (b *InMemoryBackend) SubnetworkExists(project, region, subnetwork string) bool

SubnetworkExists reports whether the subnetwork exists in the region of project.

func (*InMemoryBackend) TickGroups

func (b *InMemoryBackend) TickGroups(ctx context.Context)

TickGroups advances clock-driven group work: finishes deletions, steps rolling updates and runs the due autohealing probes (outside the lock), repairing members whose health check keeps failing.

func (*InMemoryBackend) TickSchedules

func (b *InMemoryBackend) TickSchedules(ctx context.Context)

TickSchedules runs the resource policies due on the backend clock: instance start and stop schedules and snapshot schedules with their retention. It only changes backend state, so it holds the lock throughout.

type Provider

type Provider struct{}

Provider implements service.Provider for Compute Engine. It serves the compute v1 REST API on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.

func (*Provider) Init

Init creates the backend and handler; the port is bound in StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Settings

type Settings struct {
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 167-byte string literal not displayed */
}

Settings holds service-level configuration, embedded in the root CLI as CLI.GCPCompute.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

type Timing

type Timing struct {
	Pending   time.Duration
	Done      time.Duration
	Provision time.Duration
	Stage     time.Duration
	Stop      time.Duration
}

Timing controls how long operations and instance state transitions take on the backend clock.

func DefaultTiming

func DefaultTiming() Timing

DefaultTiming returns the transition delays used unless a test overrides them.

Jump to

Keyboard shortcuts

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