Documentation
¶
Overview ¶
Package kubernetes implements a Kubernetes-based infrastructure provider for the ctrlplane. It maps ctrlplane instances to Kubernetes Deployments, Services, and ConfigMaps, providing full lifecycle management including provisioning, deployment, scaling, log streaming, and command execution.
Index ¶
- type Config
- type Option
- type Provider
- func (p *Provider) Capabilities() []provider.Capability
- func (p *Provider) Deploy(ctx context.Context, req provider.DeployRequest) (*provider.DeployResult, error)
- func (p *Provider) Deprovision(ctx context.Context, instanceID id.ID) error
- func (p *Provider) Exec(_ context.Context, _ id.ID, _ provider.ExecRequest) (*provider.ExecResult, error)
- func (p *Provider) HealthCheck(ctx context.Context) (*provider.HealthStatus, error)
- func (p *Provider) Info() provider.ProviderInfo
- func (p *Provider) Logs(ctx context.Context, instanceID id.ID, opts provider.LogOptions) (io.ReadCloser, error)
- func (p *Provider) Provision(ctx context.Context, req provider.ProvisionRequest) (*provider.ProvisionResult, error)
- func (p *Provider) Resources(_ context.Context, _ id.ID) (*provider.ResourceUsage, error)
- func (p *Provider) Restart(ctx context.Context, instanceID id.ID) error
- func (p *Provider) Rollback(_ context.Context, _ id.ID, _ id.ID) error
- func (p *Provider) Scale(ctx context.Context, instanceID id.ID, spec provider.ResourceSpec) error
- func (p *Provider) Start(ctx context.Context, instanceID id.ID) error
- func (p *Provider) Status(ctx context.Context, instanceID id.ID) (*provider.InstanceStatus, error)
- func (p *Provider) Stop(ctx context.Context, instanceID id.ID) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Kubeconfig is the path to a kubeconfig file.
// When empty, the provider tries in-cluster config first, then falls back
// to the default kubeconfig loading rules (KUBECONFIG env, ~/.kube/config).
Kubeconfig string `env:"CP_K8S_KUBECONFIG" json:"kubeconfig,omitempty"`
// Context is the kubeconfig context to use.
// When empty, the current context is used.
Context string `env:"CP_K8S_CONTEXT" json:"context,omitempty"`
// Namespace is the Kubernetes namespace for all managed resources.
Namespace string `default:"default" env:"CP_K8S_NAMESPACE" json:"namespace"`
// Region is the region label reported in provider info.
Region string `default:"local" env:"CP_K8S_REGION" json:"region"`
// InCluster forces in-cluster configuration only, skipping the local
// kubeconfig fallback. Use this in production to prevent accidentally
// picking up a developer's local kubeconfig.
InCluster bool `env:"CP_K8S_IN_CLUSTER" json:"in_cluster,omitempty"`
// Labels are additional labels applied to all managed resources.
Labels map[string]string `json:"labels,omitempty"`
}
Config holds configuration for the Kubernetes provider.
type Option ¶
Option configures a Kubernetes provider.
func WithConfig ¶
WithConfig applies all non-zero fields from a Config struct. This is useful when loading configuration from files or environment variables.
func WithContext ¶
WithContext sets the kubeconfig context to use.
func WithInCluster ¶
func WithInCluster() Option
WithInCluster forces in-cluster configuration only, skipping the local kubeconfig fallback. Use this in production to prevent accidentally picking up a developer's local kubeconfig.
func WithKubeconfig ¶
WithKubeconfig sets the path to a kubeconfig file. When empty, in-cluster configuration is used.
func WithLabels ¶
WithLabels sets additional labels applied to all managed resources.
func WithNamespace ¶
WithNamespace sets the Kubernetes namespace for all managed resources.
func WithRegion ¶
WithRegion sets the region label reported in provider info.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is a Kubernetes-based infrastructure provider.
func New ¶
New creates a new Kubernetes provider with the given options. Without any options, sane defaults are used (namespace: "default", region: "local"). Configuration is resolved in order: explicit kubeconfig path, in-cluster config, then default kubeconfig loading rules (KUBECONFIG env, ~/.kube/config).
func (*Provider) Capabilities ¶
func (p *Provider) Capabilities() []provider.Capability
Capabilities returns the set of features this provider supports.
func (*Provider) Deploy ¶
func (p *Provider) Deploy(ctx context.Context, req provider.DeployRequest) (*provider.DeployResult, error)
Deploy pushes a new release by updating the deployment image and ConfigMap.
func (*Provider) Deprovision ¶
Deprovision tears down all resources for an instance.
func (*Provider) Exec ¶
func (p *Provider) Exec(_ context.Context, _ id.ID, _ provider.ExecRequest) (*provider.ExecResult, error)
Exec runs a command inside the instance (stub).
func (*Provider) HealthCheck ¶
HealthCheck tests connectivity to the Kubernetes API server.
func (*Provider) Info ¶
func (p *Provider) Info() provider.ProviderInfo
Info returns metadata about this provider.
func (*Provider) Logs ¶
func (p *Provider) Logs(ctx context.Context, instanceID id.ID, opts provider.LogOptions) (io.ReadCloser, error)
Logs streams logs for the instance.
func (*Provider) Provision ¶
func (p *Provider) Provision(ctx context.Context, req provider.ProvisionRequest) (*provider.ProvisionResult, error)
Provision creates a Kubernetes Deployment, Service, and ConfigMap for an instance.
func (*Provider) Restart ¶
Restart performs a rollout restart by updating a pod template annotation.
func (*Provider) Rollback ¶
Rollback reverts to a previous release (no-op: ctrlplane handles release state).