gke

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 57 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 (Standard mode) 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 are rejected as UNIMPLEMENTED (FR-GKE-012). 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 egress gateway, 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.

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 host's system roots plus the emulator 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.

GKE requires Linux hosts (NFR-PORT-003).

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

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.

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 tears down every cluster's containers and volumes; the store is reset by the instance.

func (*Service) ResourceCounts added in v0.2.0

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

ResourceCounts implements emu.ResourceCounter.

func (*Service) Start

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

Start rejects non-Linux hosts and 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.

Jump to

Keyboard shortcuts

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