gke

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 94 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 gke emulates Google Kubernetes Engine (SRS 5.7): the container.googleapis.com v1 API over gRPC and REST on the gateway, backed by real k3s clusters running in the host's container runtime.

Control plane

Clusters and node pools are created, read, listed, updated, resized, upgraded and deleted through container Operations (the container API's own Operation resource, not google.longrunning). Autopilot clusters (FR-GKE-012, autopilot.go) are regional, get the settings GKE sets on them, and report one GKE-managed node pool that the node pools API refuses to change; its nodes are added and removed for the cluster's pods (FR-GKE-015, autoscale.go). REST (gcloud, OpenTofu) is served by transcoding the google.api.http rules of the generated descriptors onto the gRPC implementation, including the legacy projects/P/zones/Z/... paths.

Data plane

Each cluster runs one k3s server container (control plane only) and one privileged k3s agent container per node. Containers live on the cluster's VPC subnetwork (realised by compute's emu.VPC), on the instance's services network (to reach the emulator) and, unless the nodes are private, on the external network for egress. Private nodes' default route points at the VPC's NAT egress proxy, so they reach the internet only through Cloud NAT (FR-GKE-007, FR-INT-009). State lives in labelled volumes, so clusters survive emulator restarts with --data-dir. NetworkPolicy objects are enforced, by k3s's kube-router controller, only with Dataplane V2 or the networkPolicy setting, as on GKE (FR-GKE-011).

Every node runs the "gke-node" agent (the gcpemu binary) as its entrypoint. It serves the GKE metadata server on 169.254.169.254 (Workload Identity, FR-GKE-005), relays DNS to the emulated Cloud DNS (FR-INT-005), proxies Artifact Registry pulls with the node service account's token (FR-INT-006) and then runs the k3s agent.

Real hostnames in pods (FR-INT-007)

Unmodified client libraries in pods reach emulated services by their real hostnames with no endpoint configuration:

  • DNS: the node relay (CoreDNS's upstream) answers every hostname the gateway mounts (storage.googleapis.com, pubsub.googleapis.com, sqladmin.googleapis.com, ...) and LOCATION-docker.pkg.dev with 169.254.169.254; other names resolve through the emulated Cloud DNS.
  • TLS: the node relays 169.254.169.254:443 to the emulator's Google frontend (internal/frontend), which terminates TLS with a certificate from the instance CA and passes HTTP/1.1, HTTP/2 and gRPC through to the gateway with Host / :authority intact.
  • Trust: nodes add the CA to their system bundle, and a mutating admission webhook served by the emulator (cainject.go) mounts a bundle of the Public roots plus the Instance CA into every pod at /etc/ssl/certs/ca-certificates.crt and sets SSL_CERT_FILE, except in kube-system and in namespaces or pods labelled gcpemu.dev/inject=disabled.

The API server authenticates bearer tokens through a TokenReview webhook served by the emulator (emulator IAM tokens, FR-GKE-004) and authorizes with Node,RBAC,Webhook where the webhook grants requests the caller's IAM roles (container.admin/developer/viewer) allow.

VM runtimes

On a VM runtime (ADR 0005) the host cannot reach the cluster networks. The emulator then dials the API server and nodes through the VM relay, serves the API server on 127.0.0.1 and reports that as the cluster's endpoints, and serves LoadBalancer Services on host loopback addresses (lbservices.go) in place of k3s's servicelb.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

New returns the service.

Types

type PodRoute

type PodRoute struct {
	Cluster    string // projects/P/locations/L/clusters/C
	Node       string
	CIDR       string
	Via        string
	Subnetwork string
}

PodRoute tells a peer data plane (the M3 load balancer) how to reach a node's pods: pod addresses in CIDR are routed via the node address Via on the VPC subnetwork Subnetwork ("projects/P/regions/R/subnetworks/S", realised by compute's emu.VPC). NEG endpoints (FR-GKE-008) are pod IPs, so a proxy container attached to that subnetwork needs `ip route add CIDR via Via` for each route to reach them.

type Service

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

Service is the GKE service module.

func (*Service) ApplySeed

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

ApplySeed creates the seeded clusters that do not exist yet.

func (*Service) ClockAdvanced added in v0.15.0

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

ClockAdvanced implements emu.ClockObserver: it runs image GC on every running cluster's nodes, so a Deterministic Instance collects images on `gcpemu time advance` (ADR 0073).

func (*Service) EnvVars

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

EnvVars implements emu.EnvVarer (FR-CORE-004): gcloud's container endpoint override and the kubeconfig the emulator maintains. The Instance derives the LoadBalancer Services' GCPEMU_GKE_* variables from their endpoints (package lbenv).

func (*Service) ExportSeed added in v0.6.0

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

ExportSeed writes the clusters back as the "gke" section (FR-CORE-013), ordered by project, location and name, with the fields that differ from what the seed defaults to: the current master version, network, private nodes, Workload Identity, telemetry (managed Prometheus against the Cluster mode's default, system metrics and the managed OpenTelemetry scope) and each node pool's size, machine type, labels and service account. An Autopilot cluster exports its Cluster mode and NET_ADMIN setting in place of Workload Identity and node pools, which GKE sets. Kubernetes objects are data plane and are not exported, nor is anything else the seed file cannot declare (release channel, node pool versions, autoscaling, taints, per-pool private nodes...). A pool resized to zero nodes comes back with one, as the seed creates every pool with at least one node, and a cluster without node pools gets the default pool.

func (*Service) Info added in v0.15.0

func (s *Service) Info() any

Info implements emu.Informer.

func (*Service) LoopbackAddrs added in v0.6.0

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

LoopbackAddrs implements emu.LoopbackHolder: the 127.0.0.x addresses LoadBalancer Services and Services served to host clients hold. It takes only loopMu, which is never held while calling another Service, and reads the store, so peers may call it holding their own locks.

func (*Service) Name

func (s *Service) Name() string

func (*Service) Operations added in v0.2.0

func (s *Service) Operations() []emu.OperationInfo

Operations implements emu.OperationLister.

func (*Service) PodRoutes

func (s *Service) PodRoutes(ctx context.Context) []PodRoute

PodRoutes returns the pod routes of every running cluster.

func (*Service) Ready

func (s *Service) Ready() error

Ready reports readiness of the API; clusters report their own status, except that a DEGRADED cluster, whose Cluster server kept exiting (ADR 0045), makes the Service not ready.

func (*Service) Register

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

Register installs the container v1 gRPC service and its REST mapping.

func (*Service) Reset

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

Reset cancels the background work started before it and waits for it (bounded by ctx), so none of it touches a runtime object afterwards (#293). It then tears down every cluster's containers and volumes and drops the staged datastores; the store is reset by the instance. Work started after Reset runs on a fresh background context, unless the service is stopped.

func (*Service) ResetDone added in v0.15.0

func (s *Service) ResetDone()

ResetDone implements emu.ResetFinisher: once the Store is reset too, the Instance has no GKE nodes, so GKE overcommit is estimated afresh (#1070).

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: Reset tore the data planes down and cleared the staged datastores; each saved datastore is staged and the restored clusters are brought up again in the background, reporting RECONCILING until they are back.

func (*Service) RoutePublic added in v0.6.0

func (s *Service) RoutePublic(ctx context.Context, from string, r emu.PublicRoutes) error

RoutePublic implements emu.PublicRouter: nodes with external IPs hold the Public routes of each sender: the load balancer's forwarding rule addresses via the Edge relay, so pods reach load balancers by their public address with the node's address as the client, as on GCP (#187), and compute's External address pools and the reserved external addresses outside them unreachable (ADR 0059). Private nodes reach them through Cloud NAT instead (compute).

func (*Service) Snapshot added in v0.6.0

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

Snapshot implements emu.Snapshotter. Clusters that are not RUNNING (provisioning, reconciling, stopping or failed) are skipped and restore with a fresh data plane.

func (*Service) Start

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

Start brings persisted clusters back up in the background (FR-CORE-031).

func (*Service) Stop

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

Stop cancels background work. Containers are removed by the instance.

func (*Service) WaitConditions added in v0.10.0

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

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

Jump to

Keyboard shortcuts

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