Documentation
¶
Index ¶
- Constants
- Variables
- type Compute
- type ConfigProvider
- type EngineConfig
- type EngineConfigProvider
- type Handler
- func (h *Handler) Addr() string
- func (h *Handler) ExtractOperation(*echo.Context) string
- func (h *Handler) ExtractResource(*echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type InMemoryBackend
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) CompleteIPRotation(req *containerpb.CompleteIPRotationRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) CreateCluster(req *containerpb.CreateClusterRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) CreateNodePool(req *containerpb.CreateNodePoolRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) DeleteCluster(req *containerpb.DeleteClusterRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) DeleteNodePool(req *containerpb.DeleteNodePoolRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) EnableEngine(cfg EngineConfig) error
- func (b *InMemoryBackend) EngineToken() string
- func (b *InMemoryBackend) GetCluster(req *containerpb.GetClusterRequest) (*containerpb.Cluster, error)
- func (b *InMemoryBackend) GetNodePool(req *containerpb.GetNodePoolRequest) (*containerpb.NodePool, error)
- func (b *InMemoryBackend) GetOperation(req *containerpb.GetOperationRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) GetServerConfig(req *containerpb.GetServerConfigRequest) (*containerpb.ServerConfig, error)
- func (b *InMemoryBackend) ListClusters(req *containerpb.ListClustersRequest) (*containerpb.ListClustersResponse, error)
- func (b *InMemoryBackend) ListNodePools(req *containerpb.ListNodePoolsRequest) (*containerpb.ListNodePoolsResponse, error)
- func (b *InMemoryBackend) ListOperations(req *containerpb.ListOperationsRequest) (*containerpb.ListOperationsResponse, error)
- func (b *InMemoryBackend) NodePoolSizes(clusterName string) (map[string]int32, error)
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) RollbackNodePoolUpgrade(req *containerpb.RollbackNodePoolUpgradeRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetAddonsConfig(req *containerpb.SetAddonsConfigRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetClock(now func() time.Time)
- func (b *InMemoryBackend) SetCompute(c Compute)
- func (b *InMemoryBackend) SetLabels(req *containerpb.SetLabelsRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetLegacyAbac(req *containerpb.SetLegacyAbacRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetLocations(req *containerpb.SetLocationsRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetLoggingService(req *containerpb.SetLoggingServiceRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetMaintenancePolicy(req *containerpb.SetMaintenancePolicyRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetMasterAuth(req *containerpb.SetMasterAuthRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetMonitoringService(req *containerpb.SetMonitoringServiceRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetNetworkPolicy(req *containerpb.SetNetworkPolicyRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetNodePoolAutoscaling(req *containerpb.SetNodePoolAutoscalingRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetNodePoolManagement(req *containerpb.SetNodePoolManagementRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetNodePoolSize(req *containerpb.SetNodePoolSizeRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) SetTiming(t Timing)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) StartIPRotation(req *containerpb.StartIPRotationRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) UpdateCluster(req *containerpb.UpdateClusterRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) UpdateMaster(req *containerpb.UpdateMasterRequest) (*containerpb.Operation, error)
- func (b *InMemoryBackend) UpdateNodePool(req *containerpb.UpdateNodePoolRequest) (*containerpb.Operation, error)
- type Provider
- type Settings
- type Timing
Constants ¶
const ( EngineStub = "stub" EngineDocker = "docker" )
Engine modes (GKE_ENGINE).
const DefaultPort = 8144
DefaultPort is the dedicated Kubernetes Engine gRPC and REST listener's default TCP port.
Variables ¶
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) ExtractOperation ¶
ExtractOperation is unused: requests never reach the shared router.
func (*Handler) ExtractResource ¶
ExtractResource is unused: requests never reach the shared router.
func (*Handler) GetSupportedOperations ¶
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 ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: Kubernetes Engine runs on its own listener.
func (*Handler) Shutdown ¶
Shutdown stops the listener, forcing a close after a short grace period, then releases engine clusters.
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 ¶
func (b *InMemoryBackend) CompleteIPRotation( req *containerpb.CompleteIPRotationRequest, ) (*containerpb.Operation, error)
CompleteIPRotation finishes a rotation started by StartIPRotation.
func (*InMemoryBackend) CreateCluster ¶
func (b *InMemoryBackend) CreateCluster(req *containerpb.CreateClusterRequest) (*containerpb.Operation, error)
CreateCluster creates a cluster and its node pools and returns the CREATE_CLUSTER operation.
func (*InMemoryBackend) CreateNodePool ¶
func (b *InMemoryBackend) CreateNodePool(req *containerpb.CreateNodePoolRequest) (*containerpb.Operation, error)
CreateNodePool adds a node pool to a cluster.
func (*InMemoryBackend) DeleteCluster ¶
func (b *InMemoryBackend) DeleteCluster(req *containerpb.DeleteClusterRequest) (*containerpb.Operation, error)
DeleteCluster starts deletion and returns the DELETE_CLUSTER operation.
func (*InMemoryBackend) DeleteNodePool ¶
func (b *InMemoryBackend) DeleteNodePool(req *containerpb.DeleteNodePoolRequest) (*containerpb.Operation, error)
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 ¶
func (b *InMemoryBackend) GetCluster(req *containerpb.GetClusterRequest) (*containerpb.Cluster, error)
GetCluster returns one cluster.
func (*InMemoryBackend) GetNodePool ¶
func (b *InMemoryBackend) GetNodePool(req *containerpb.GetNodePoolRequest) (*containerpb.NodePool, error)
GetNodePool returns one node pool.
func (*InMemoryBackend) GetOperation ¶
func (b *InMemoryBackend) GetOperation(req *containerpb.GetOperationRequest) (*containerpb.Operation, error)
GetOperation returns one operation.
func (*InMemoryBackend) GetServerConfig ¶
func (b *InMemoryBackend) GetServerConfig(req *containerpb.GetServerConfigRequest) (*containerpb.ServerConfig, error)
GetServerConfig returns the supported versions and image types for a location.
func (*InMemoryBackend) ListClusters ¶
func (b *InMemoryBackend) ListClusters( req *containerpb.ListClustersRequest, ) (*containerpb.ListClustersResponse, error)
ListClusters lists the clusters of a location, or of every location for "-".
func (*InMemoryBackend) ListNodePools ¶
func (b *InMemoryBackend) ListNodePools( req *containerpb.ListNodePoolsRequest, ) (*containerpb.ListNodePoolsResponse, error)
ListNodePools lists a cluster's node pools.
func (*InMemoryBackend) ListOperations ¶
func (b *InMemoryBackend) ListOperations( req *containerpb.ListOperationsRequest, ) (*containerpb.ListOperationsResponse, error)
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 ¶
func (b *InMemoryBackend) SetAddonsConfig(req *containerpb.SetAddonsConfigRequest) (*containerpb.Operation, error)
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 ¶
func (b *InMemoryBackend) SetLabels(req *containerpb.SetLabelsRequest) (*containerpb.Operation, error)
SetLabels replaces the cluster's resource labels.
func (*InMemoryBackend) SetLegacyAbac ¶
func (b *InMemoryBackend) SetLegacyAbac(req *containerpb.SetLegacyAbacRequest) (*containerpb.Operation, error)
SetLegacyAbac enables or disables legacy ABAC authorization.
func (*InMemoryBackend) SetLocations ¶
func (b *InMemoryBackend) SetLocations(req *containerpb.SetLocationsRequest) (*containerpb.Operation, error)
SetLocations changes the zones the cluster's nodes run in.
func (*InMemoryBackend) SetLoggingService ¶
func (b *InMemoryBackend) SetLoggingService(req *containerpb.SetLoggingServiceRequest) (*containerpb.Operation, error)
SetLoggingService selects the logging backend.
func (*InMemoryBackend) SetMaintenancePolicy ¶
func (b *InMemoryBackend) SetMaintenancePolicy( req *containerpb.SetMaintenancePolicyRequest, ) (*containerpb.Operation, error)
SetMaintenancePolicy replaces the cluster's maintenance policy.
func (*InMemoryBackend) SetMasterAuth ¶
func (b *InMemoryBackend) SetMasterAuth(req *containerpb.SetMasterAuthRequest) (*containerpb.Operation, error)
SetMasterAuth changes the cluster's basic-auth username or password.
func (*InMemoryBackend) SetMonitoringService ¶
func (b *InMemoryBackend) SetMonitoringService( req *containerpb.SetMonitoringServiceRequest, ) (*containerpb.Operation, error)
SetMonitoringService selects the monitoring backend.
func (*InMemoryBackend) SetNetworkPolicy ¶
func (b *InMemoryBackend) SetNetworkPolicy(req *containerpb.SetNetworkPolicyRequest) (*containerpb.Operation, error)
SetNetworkPolicy enables or disables Calico network policy enforcement.
func (*InMemoryBackend) SetNodePoolAutoscaling ¶
func (b *InMemoryBackend) SetNodePoolAutoscaling( req *containerpb.SetNodePoolAutoscalingRequest, ) (*containerpb.Operation, error)
SetNodePoolAutoscaling configures a node pool's autoscaler.
func (*InMemoryBackend) SetNodePoolManagement ¶
func (b *InMemoryBackend) SetNodePoolManagement( req *containerpb.SetNodePoolManagementRequest, ) (*containerpb.Operation, error)
SetNodePoolManagement sets auto-upgrade and auto-repair.
func (*InMemoryBackend) SetNodePoolSize ¶
func (b *InMemoryBackend) SetNodePoolSize(req *containerpb.SetNodePoolSizeRequest) (*containerpb.Operation, error)
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 ¶
func (b *InMemoryBackend) StartIPRotation(req *containerpb.StartIPRotationRequest) (*containerpb.Operation, error)
StartIPRotation begins an IP (and optionally credential) rotation.
func (*InMemoryBackend) UpdateCluster ¶
func (b *InMemoryBackend) UpdateCluster(req *containerpb.UpdateClusterRequest) (*containerpb.Operation, error)
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 ¶
func (b *InMemoryBackend) UpdateMaster(req *containerpb.UpdateMasterRequest) (*containerpb.Operation, error)
UpdateMaster upgrades the cluster's control plane.
func (*InMemoryBackend) UpdateNodePool ¶
func (b *InMemoryBackend) UpdateNodePool(req *containerpb.UpdateNodePoolRequest) (*containerpb.Operation, error)
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 ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
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.