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

gcpcontainer

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 42 Imported by: 0

README

Kubernetes Engine

Parity grade: B · SDK cloud.google.com/go/container@v1.56.0 · last audited 2026-10-29 (86ab2e0a7)

Coverage

Metric Value
Feature families 5 (4 ok, 1 partial)
Known gaps 5
Deferred items 0
Resource leaks unknown
Known gaps
  • The control plane is metadata: without GKE_ENGINE=docker the endpoint is a documentation-range address with a real but unused CA, and node pools never run nodes (the docker engine runs one k3s node regardless of pool sizes). Instance groups named in instanceGroupUrls are not created in gcpcompute.
  • Unimplemented RPCs: CancelOperation, GetJSONWebKeys, ListUsableSubnetworks, CheckAutopilotCompatibility, FetchClusterUpgradeInfo, FetchNodePoolUpgradeInfo, CompleteNodePoolUpgrade, CompleteControlPlaneUpgrade.
  • Version catalog and region/zone lists are a fixed representative set; Autopilot being regional-only, error message texts and the PreconditionFailure/BadRequest/ResourceInfo detail payloads were chosen without a production reference (only the cluster name rules were checked against Google docs).
  • createSubnetwork is not honoured (no subnet is created in gcpcompute), pod/service ranges of other clusters are only avoided for auto-allocation, and quotas are not modelled.
  • No dashboard page, and the emulator does not enforce IAM or return permission errors.

More

Documentation

Index

Constants

View Source
const (
	EngineStub   = "stub"
	EngineDocker = "docker"
)

Engine modes (GKE_ENGINE).

View Source
const DefaultPort = 8144

DefaultPort is the dedicated Kubernetes Engine gRPC and REST listener's default TCP port.

Variables

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

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

Functions

This section is empty.

Types

type Compute

type Compute interface {
	NetworkExists(project, network string) bool
	SubnetworkExists(project, region, subnetwork string) bool
	SecondaryRange(project, region, subnetwork, rangeName string) (string, bool)
	MachineTypeExists(machineType string) bool
}

Compute resolves the networks and machine types of the Compute Engine emulator, so clusters can be checked against them.

type ConfigProvider

type ConfigProvider interface {
	GetGCPContainerSettings() Settings
}

ConfigProvider extracts Kubernetes Engine configuration from the AppContext Config.

type EngineConfig

type EngineConfig struct {
	Runtime      k3sengine.Runtime
	Ports        *portalloc.Allocator
	Logger       *slog.Logger
	Probe        func(ctx context.Context, addr, token string) ([]byte, error)
	Host         string
	Token        string
	Image        string
	StartTimeout time.Duration
}

EngineConfig configures docker-backed clusters: each CreateCluster starts a single-node k3s container.

type EngineConfigProvider

type EngineConfigProvider interface {
	GetGCPContainerEngine() string
}

EngineConfigProvider exposes the engine mode (stub or docker).

type Handler

type Handler struct {
	Backend *InMemoryBackend

	Port int
	// contains filtered or unexported fields
}

Handler serves the Kubernetes Engine API on a dedicated gRPC and REST 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(*echo.Context) string

ExtractOperation is unused: requests never reach the shared router.

func (*Handler) ExtractResource

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

ExtractResource is unused: requests never reach the shared router.

func (*Handler) GetSupportedOperations

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

GetSupportedOperations lists the supported gRPC methods.

func (*Handler) Handler

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

Handler returns a 404 handler; the real API is on the dedicated port.

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 clears 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: Kubernetes Engine runs on its own listener.

func (*Handler) Shutdown

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

Shutdown stops the listener, forcing a close after a short grace period, then releases engine clusters.

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 dedicated listener synchronously so a port conflict is returned to the caller.

type InMemoryBackend

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

InMemoryBackend holds all Kubernetes Engine state under one lock.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend on the wall clock.

func (*InMemoryBackend) Close

func (b *InMemoryBackend) Close()

Close stops engine goroutines and releases cluster containers.

func (*InMemoryBackend) CompleteIPRotation

CompleteIPRotation finishes a rotation started by StartIPRotation.

func (*InMemoryBackend) CreateCluster

CreateCluster creates a cluster and its node pools and returns the CREATE_CLUSTER operation.

func (*InMemoryBackend) CreateNodePool

CreateNodePool adds a node pool to a cluster.

func (*InMemoryBackend) DeleteCluster

DeleteCluster starts deletion and returns the DELETE_CLUSTER operation.

func (*InMemoryBackend) DeleteNodePool

DeleteNodePool starts deletion of a node pool.

func (*InMemoryBackend) EnableEngine

func (b *InMemoryBackend) EnableEngine(cfg EngineConfig) error

EnableEngine switches the backend to docker mode.

func (*InMemoryBackend) EngineToken

func (b *InMemoryBackend) EngineToken() string

EngineToken is the cluster-admin bearer token of docker-engine clusters; empty without the engine.

func (*InMemoryBackend) GetCluster

GetCluster returns one cluster.

func (*InMemoryBackend) GetNodePool

GetNodePool returns one node pool.

func (*InMemoryBackend) GetOperation

GetOperation returns one operation.

func (*InMemoryBackend) GetServerConfig

GetServerConfig returns the supported versions and image types for a location.

func (*InMemoryBackend) ListClusters

ListClusters lists the clusters of a location, or of every location for "-".

func (*InMemoryBackend) ListNodePools

ListNodePools lists a cluster's node pools.

func (*InMemoryBackend) ListOperations

ListOperations lists the operations of a location, or of every location for "-".

func (*InMemoryBackend) NodePoolSizes

func (b *InMemoryBackend) NodePoolSizes(clusterName string) (map[string]int32, error)

NodePoolSizes reports the current node count per zone of each node pool of a cluster, by pool name. The API itself exposes the count only through the cluster's totals.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset clears all state and tears down engine clusters.

func (*InMemoryBackend) Restore

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

Restore loads a snapshot, replacing all state. Engine clusters are started again from scratch.

func (*InMemoryBackend) RollbackNodePoolUpgrade

func (b *InMemoryBackend) RollbackNodePoolUpgrade(
	req *containerpb.RollbackNodePoolUpgradeRequest,
) (*containerpb.Operation, error)

RollbackNodePoolUpgrade restores the version a node pool had before its last upgrade.

func (*InMemoryBackend) SetAddonsConfig

SetAddonsConfig replaces each addon section named in the request into the cluster.

func (*InMemoryBackend) SetClock

func (b *InMemoryBackend) SetClock(now func() time.Time)

SetClock replaces the clock statuses and operations are derived from; tests inject a fake clock here.

func (*InMemoryBackend) SetCompute

func (b *InMemoryBackend) SetCompute(c Compute)

SetCompute connects clusters to the Compute Engine emulator's networks and machine types; nil disconnects.

func (*InMemoryBackend) SetLabels

SetLabels replaces the cluster's resource labels.

func (*InMemoryBackend) SetLegacyAbac

SetLegacyAbac enables or disables legacy ABAC authorization.

func (*InMemoryBackend) SetLocations

SetLocations changes the zones the cluster's nodes run in.

func (*InMemoryBackend) SetLoggingService

SetLoggingService selects the logging backend.

func (*InMemoryBackend) SetMaintenancePolicy

SetMaintenancePolicy replaces the cluster's maintenance policy.

func (*InMemoryBackend) SetMasterAuth

SetMasterAuth changes the cluster's basic-auth username or password.

func (*InMemoryBackend) SetMonitoringService

SetMonitoringService selects the monitoring backend.

func (*InMemoryBackend) SetNetworkPolicy

SetNetworkPolicy enables or disables Calico network policy enforcement.

func (*InMemoryBackend) SetNodePoolAutoscaling

SetNodePoolAutoscaling configures a node pool's autoscaler.

func (*InMemoryBackend) SetNodePoolManagement

SetNodePoolManagement sets auto-upgrade and auto-repair.

func (*InMemoryBackend) SetNodePoolSize

SetNodePoolSize resizes a node pool.

func (*InMemoryBackend) SetTiming

func (b *InMemoryBackend) SetTiming(t Timing)

SetTiming replaces the operation durations.

func (*InMemoryBackend) Snapshot

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

Snapshot serialises clusters, node pools and operations.

func (*InMemoryBackend) StartIPRotation

StartIPRotation begins an IP (and optionally credential) rotation.

func (*InMemoryBackend) UpdateCluster

UpdateCluster applies the Desired* fields of a ClusterUpdate. Every field with a matching cluster field is copied onto it; fields the emulator cannot honour are rejected rather than ignored.

func (*InMemoryBackend) UpdateMaster

UpdateMaster upgrades the cluster's control plane.

func (*InMemoryBackend) UpdateNodePool

UpdateNodePool changes node pool settings.

type Provider

type Provider struct{}

Provider implements service.Provider for Kubernetes Engine. It serves gRPC and REST 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
	/* 181-byte string literal not displayed */
}

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

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

type Timing

type Timing struct {
	Create time.Duration
	Mutate time.Duration
	Delete time.Duration
}

Timing controls how long operations take on the backend clock.

func DefaultTiming

func DefaultTiming() Timing

DefaultTiming returns the operation durations used unless a test overrides them.

Jump to

Keyboard shortcuts

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