Documentation
¶
Overview ¶
Package gke provides an in-memory mock of GCP Kubernetes Engine (GKE).
Wave 1 covers only the GKE control-plane: Clusters, NodePools, and the long-running Operations they emit. The Kubernetes data-plane API (Deployments, StatefulSets, Pods, Services) is intentionally out of scope and will be wired up in Wave 2 alongside a Kubernetes API server stub.
To reflect that, GetCluster returns a stub Endpoint (https://GKE-DATAPLANE-NOT-IMPLEMENTED.cloudemu.local) and a stub CA certificate so that tooling like `gcloud container clusters get-credentials` can render a kubeconfig — actual API calls against the kubeconfig will fail until Wave 2 lands.
Index ¶
- Constants
- type Cluster
- type CreateClusterInput
- type Mock
- func (m *Mock) CancelOperation(_ context.Context, _, name string) error
- func (m *Mock) CompleteIPRotation(_ context.Context, location, name string) (*Operation, error)
- func (m *Mock) CreateCluster(_ context.Context, input *CreateClusterInput) (*Cluster, *Operation, error)
- func (m *Mock) CreateNodePool(_ context.Context, location, clusterName string, spec *NodePoolSpec) (*NodePool, *Operation, error)
- func (m *Mock) DeleteCluster(_ context.Context, location, name string) (*Operation, error)
- func (m *Mock) DeleteNodePool(_ context.Context, location, clusterName, name string) (*Operation, error)
- func (m *Mock) Endpoint(location, name string) string
- func (m *Mock) GetCluster(_ context.Context, location, name string) (*Cluster, error)
- func (m *Mock) GetNodePool(_ context.Context, location, clusterName, name string) (*NodePool, error)
- func (m *Mock) GetOperation(_ context.Context, _, name string) (*Operation, error)
- func (m *Mock) ListClusters(_ context.Context, location string) ([]Cluster, error)
- func (m *Mock) ListNodePools(_ context.Context, location, clusterName string) ([]NodePool, error)
- func (m *Mock) ListOperations(_ context.Context, location string) ([]Operation, error)
- func (m *Mock) RollbackNodePool(_ context.Context, location, clusterName, name string) (*Operation, error)
- func (m *Mock) SetClusterLogging(_ context.Context, location, name, service string) (*Operation, error)
- func (m *Mock) SetClusterMonitoring(_ context.Context, location, name, service string) (*Operation, error)
- func (m *Mock) SetK8sAPI(api *kubernetes.APIServer)
- func (m *Mock) SetLegacyAbac(_ context.Context, location, name string, enabled bool) (*Operation, error)
- func (m *Mock) SetMaintenancePolicy(_ context.Context, location, name, window string) (*Operation, error)
- func (m *Mock) SetMasterAuth(_ context.Context, location, name, username string) (*Operation, error)
- func (m *Mock) SetMonitoring(mon mondriver.Monitoring)
- func (m *Mock) SetNetworkPolicy(_ context.Context, location, name string, enabled bool) (*Operation, error)
- func (m *Mock) SetNodePoolAutoscaling(_ context.Context, location, clusterName, name string, on bool, ...) (*Operation, error)
- func (m *Mock) SetNodePoolManagement(_ context.Context, location, clusterName, name string, ...) (*Operation, error)
- func (m *Mock) SetNodePoolSize(_ context.Context, location, clusterName, name string, count int64) (*Operation, error)
- func (m *Mock) SetResourceLabels(_ context.Context, location, name string, labels map[string]string) (*Operation, error)
- func (m *Mock) StartIPRotation(_ context.Context, location, name string) (*Operation, error)
- func (m *Mock) UpdateCluster(_ context.Context, location, name string, input UpdateClusterInput) (*Operation, error)
- func (m *Mock) UpdateNodePool(_ context.Context, location, clusterName, name string, ...) (*Operation, error)
- type NodePool
- type NodePoolSpec
- type Operation
- type UpdateClusterInput
- type UpdateNodePoolInput
Constants ¶
const ( StubEndpoint = "GKE-DATAPLANE-NOT-IMPLEMENTED.cloudemu.local" StubCACert = "MIIBkTCB+wIJAOdjUjcyKZUyMA0GCSqGSIb3DQEBBQUAMA0xCzAJBgNVBAYTAlVT" // dummy base64 blob StubMasterVer = "1.30.0-gke.0" )
Stub values used in Cluster responses until the Kubernetes data-plane arrives in Wave 2.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster struct {
Name string
Location string
Description string
Network string
Subnetwork string
InitialNodeCount int64
NodeIPv4CIDRSize int64
ClusterIPv4CIDR string
LoggingService string
MonitoringService string
LegacyAbacEnabled bool
NetworkPolicy bool
MasterUsername string
ResourceLabels map[string]string
MaintenanceWindow string // RFC-3339 daily window encoding; empty = none.
IPRotationActive bool
NodePoolNames []string
Status string
CreatedAt time.Time
}
Cluster is the in-memory representation of a GKE cluster. The shape mirrors only the fields the SDK round-trip cares about; the handler layer maps these to the wire shape google.golang.org/api/container/v1.Cluster expects.
type CreateClusterInput ¶
type CreateClusterInput struct {
Name string
Location string
Description string
Network string
Subnetwork string
InitialNodeCount int64
LoggingService string
MonitoringService string
ResourceLabels map[string]string
NodePools []NodePoolSpec
}
CreateClusterInput captures the subset of CreateCluster we honor.
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
Mock is the in-memory GKE backend.
func (*Mock) CancelOperation ¶
CancelOperation marks a recorded operation as canceled. Real GKE cancels long-running ops; the mock's ops are already DONE so this is a no-op for state purposes — we still record the request returned an OK envelope. The location is part of the SDK URL but operation names are globally unique in the mock, so the parameter is unused — kept for parity with the SDK.
func (*Mock) CompleteIPRotation ¶
CompleteIPRotation implements :completeIpRotation.
func (*Mock) CreateCluster ¶
func (m *Mock) CreateCluster(_ context.Context, input *CreateClusterInput) (*Cluster, *Operation, error)
CreateCluster registers a new cluster and any nested node pools.
func (*Mock) CreateNodePool ¶
func (m *Mock) CreateNodePool( _ context.Context, location, clusterName string, spec *NodePoolSpec, ) (*NodePool, *Operation, error)
CreateNodePool registers a new node pool inside an existing cluster.
func (*Mock) DeleteCluster ¶
DeleteCluster removes a cluster and its node pools.
func (*Mock) DeleteNodePool ¶
func (m *Mock) DeleteNodePool(_ context.Context, location, clusterName, name string) (*Operation, error)
DeleteNodePool removes a node pool.
func (*Mock) Endpoint ¶ added in v1.6.3
Endpoint returns the data-plane URL clients should target for a given cluster. If a Kubernetes APIServer is wired and the cluster has a registered UID, returns "<base>/k8s/<uid>" — the in-memory data plane. Otherwise returns "https://" + StubEndpoint so the Wave-1 sentinel surface stays intact.
func (*Mock) GetCluster ¶
GetCluster returns a single cluster by location+name.
func (*Mock) GetNodePool ¶
func (m *Mock) GetNodePool(_ context.Context, location, clusterName, name string) (*NodePool, error)
GetNodePool returns one node pool.
func (*Mock) GetOperation ¶
GetOperation returns one previously-recorded operation. The location is part of the SDK URL but operation names are globally unique in the mock, so the parameter is unused — kept for parity with the SDK signature.
func (*Mock) ListClusters ¶
ListClusters returns clusters in a location ("-" for all locations).
func (*Mock) ListNodePools ¶
ListNodePools returns all node pools in a cluster.
func (*Mock) ListOperations ¶
ListOperations returns all operations in a location ("-" for all).
func (*Mock) RollbackNodePool ¶
func (m *Mock) RollbackNodePool(_ context.Context, location, clusterName, name string) (*Operation, error)
RollbackNodePool flags an in-progress upgrade as rolled back.
func (*Mock) SetClusterLogging ¶
func (m *Mock) SetClusterLogging(_ context.Context, location, name, service string) (*Operation, error)
SetClusterLogging implements :setLogging (logging-service URI).
func (*Mock) SetClusterMonitoring ¶
func (m *Mock) SetClusterMonitoring(_ context.Context, location, name, service string) (*Operation, error)
SetClusterMonitoring implements :setMonitoring (monitoring-service URI).
func (*Mock) SetK8sAPI ¶ added in v1.6.3
func (m *Mock) SetK8sAPI(api *kubernetes.APIServer)
SetK8sAPI wires a shared in-memory Kubernetes data-plane server. After this is set, CreateCluster registers a fresh ClusterState with api and Endpoint() returns the URL of that state for the given cluster. Pass the same *kubernetes.APIServer as gcpserver.Drivers.K8sAPI when constructing the SDK-compat server, so kubeconfigs land on the right backend.
func (*Mock) SetLegacyAbac ¶
func (m *Mock) SetLegacyAbac(_ context.Context, location, name string, enabled bool) (*Operation, error)
SetLegacyAbac implements :setLegacyAbac.
func (*Mock) SetMaintenancePolicy ¶
func (m *Mock) SetMaintenancePolicy(_ context.Context, location, name, window string) (*Operation, error)
SetMaintenancePolicy implements :setMaintenancePolicy.
func (*Mock) SetMasterAuth ¶
func (m *Mock) SetMasterAuth(_ context.Context, location, name, username string) (*Operation, error)
SetMasterAuth implements :setMasterAuth (basic-auth username/password).
func (*Mock) SetMonitoring ¶
func (m *Mock) SetMonitoring(mon mondriver.Monitoring)
SetMonitoring wires a Cloud Monitoring backend for auto-metric emission.
func (*Mock) SetNetworkPolicy ¶
func (m *Mock) SetNetworkPolicy(_ context.Context, location, name string, enabled bool) (*Operation, error)
SetNetworkPolicy implements :setNetworkPolicy.
func (*Mock) SetNodePoolAutoscaling ¶
func (m *Mock) SetNodePoolAutoscaling( _ context.Context, location, clusterName, name string, on bool, minNodes, maxNodes int64, ) (*Operation, error)
SetNodePoolAutoscaling toggles autoscaling and bounds.
func (*Mock) SetNodePoolManagement ¶
func (m *Mock) SetNodePoolManagement( _ context.Context, location, clusterName, name string, autoUpgrade, autoRepair bool, ) (*Operation, error)
SetNodePoolManagement toggles auto-upgrade and auto-repair.
func (*Mock) SetNodePoolSize ¶
func (m *Mock) SetNodePoolSize( _ context.Context, location, clusterName, name string, count int64, ) (*Operation, error)
SetNodePoolSize resizes a node pool to count nodes.
func (*Mock) SetResourceLabels ¶
func (m *Mock) SetResourceLabels( _ context.Context, location, name string, labels map[string]string, ) (*Operation, error)
SetResourceLabels implements :setResourceLabels.
func (*Mock) StartIPRotation ¶
StartIPRotation implements :startIpRotation.
func (*Mock) UpdateCluster ¶
func (m *Mock) UpdateCluster( _ context.Context, location, name string, input UpdateClusterInput, ) (*Operation, error)
UpdateCluster applies a partial update.
func (*Mock) UpdateNodePool ¶
func (m *Mock) UpdateNodePool( _ context.Context, location, clusterName, name string, input UpdateNodePoolInput, ) (*Operation, error)
UpdateNodePool applies a partial update.
type NodePool ¶
type NodePool struct {
Name string
ClusterName string
Location string
NodeCount int64
MachineType string
DiskSizeGB int64
Version string
AutoscalingMin int64
AutoscalingMax int64
AutoscalingOn bool
AutoUpgrade bool
AutoRepair bool
Status string
UpgradeRolledBack bool
CreatedAt time.Time
}
NodePool is the in-memory representation of a GKE node pool.
type NodePoolSpec ¶
type NodePoolSpec struct {
Name string
InitialNodeCount int64
MachineType string
DiskSizeGB int64
Version string
AutoscalingMin int64
AutoscalingMax int64
AutoscalingOn bool
}
NodePoolSpec captures the node-pool fields we keep when bootstrapping a cluster from a CreateClusterRequest.
type Operation ¶
type Operation struct {
Name string
Location string
OperationType string
Status string
TargetLink string
StartTime time.Time
EndTime time.Time
}
Operation tracks GKE long-running operations. The mock completes every operation immediately (status=DONE) so SDK pollers terminate on the first poll.
type UpdateClusterInput ¶
type UpdateClusterInput struct {
LoggingService string
MonitoringService string
NodeVersion string
MasterVersion string
ResourceLabels map[string]string
}
UpdateClusterInput is the subset of UpdateCluster we honor.
type UpdateNodePoolInput ¶
UpdateNodePoolInput captures the subset of UpdateNodePool we honor.