Help us shape the future of Go! Take the 2026 Go Developer Survey

gcpcompute

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 33 Imported by: 0

README

Compute Engine

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

Coverage

Metric Value
Feature families 8 (5 ok, 2 partial, 1 gap)
Known gaps 10
Deferred items 0
Resource leaks unknown
Known gaps
  • Load balancing: target pools, target instances, service attachments, legacy HTTP health checks, regional SSL policies, regional TCP/SSL certificates managed by Certificate Manager, certificate maps, security policies, backend service patch fields such as outlier detection are stored without effect, urlMaps.invalidateCache and forwardingRules.patch are not routed, and managed certificates never leave PROVISIONING. No traffic is forwarded and nothing is probed (see BackendServices.GetHealth). Backend bucket existence is not checked against gcpstorage.
  • Instance groups: instance health is never probed (health checks are state only, so autoHealingPolicies are stored and validated but no instance is ever repaired, instanceHealth and lastAttempt stay empty); utilization-based autoscaling has no metric source; updatePolicy pacing (maxSurge, maxUnavailable, minimalAction, replacementMethod), stateful policy, per-instance configs, resize requests, createInstances, applyUpdatesToInstances, start/stop/suspend/resume instances and listErrors are not implemented; instance creation errors fail the whole call instead of surfacing as group errors.
  • Instance templates cannot be created from sourceInstance and do not support regional-only fields beyond the stored properties; GRPC_WITH_TLS health checks and regional composite health checks are not modelled.
  • Regional disks, instantSnapshots, machine images, reservations, resource policies, VPN gateways/tunnels, interconnects, network peerings (addPeering/removePeering), shared VPC, security policies and licenses are not routed (404).
  • Instances: update (PUT), updateNetworkInterface, setScheduling, setServiceAccount, setMinCpuPlatform, setShieldedInstanceConfig, suspend/resume, getSerialPortOutput, getGuestAttributes, bulkInsert, listReferrers and simulateMaintenanceEvent are not implemented; local SSD (SCRATCH) disks, GPUs, IPv6 and alias IP ranges are rejected or stored without effect.
  • System subnet routes (default-route-* per subnetwork) are not generated; only the 0.0.0.0/0 internet route is created with a network. Routes cannot use VPN tunnel, ILB, hub, peering or network next hops.
  • Global INTERNAL addresses (VPC peering ranges), IPv6 addresses and prefix-length reservations are rejected.
  • Error message texts for state conflicts (resourceNotReady on setMachineType/reset/detach), resourceInUseByAnotherResource wording, required-field and validation messages, and the firewall rule for ingress without sources were chosen without a production reference.
  • Only a fixed set of 15 regions, 46 zones, 9 image families, e2/n2/n1-standard machine types and 3 persistent disk types exist; image point releases are pinned, region quotas and Project usage quotas are not modelled, and the status/progress timing is a fixed model.
  • No dashboard page, and 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.

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

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