kubernetes

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

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

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

type Option func(*Provider) error

Option configures a Kubernetes provider.

func WithConfig

func WithConfig(cfg Config) Option

WithConfig applies all non-zero fields from a Config struct. This is useful when loading configuration from files or environment variables.

func WithContext

func WithContext(ctx string) Option

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

func WithKubeconfig(path string) Option

WithKubeconfig sets the path to a kubeconfig file. When empty, in-cluster configuration is used.

func WithLabels

func WithLabels(labels map[string]string) Option

WithLabels sets additional labels applied to all managed resources.

func WithNamespace

func WithNamespace(ns string) Option

WithNamespace sets the Kubernetes namespace for all managed resources.

func WithRegion

func WithRegion(region string) Option

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

func New(opts ...Option) (*Provider, error)

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

Deploy pushes a new release by updating the deployment image and ConfigMap.

func (*Provider) Deprovision

func (p *Provider) Deprovision(ctx context.Context, instanceID id.ID) error

Deprovision tears down all resources for an instance.

func (*Provider) Exec

Exec runs a command inside the instance (stub).

func (*Provider) HealthCheck

func (p *Provider) HealthCheck(ctx context.Context) (*provider.HealthStatus, error)

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

Provision creates a Kubernetes Deployment, Service, and ConfigMap for an instance.

func (*Provider) Resources

func (p *Provider) Resources(_ context.Context, _ id.ID) (*provider.ResourceUsage, error)

Resources returns current resource utilization (stub).

func (*Provider) Restart

func (p *Provider) Restart(ctx context.Context, instanceID id.ID) error

Restart performs a rollout restart by updating a pod template annotation.

func (*Provider) Rollback

func (p *Provider) Rollback(_ context.Context, _ id.ID, _ id.ID) error

Rollback reverts to a previous release (no-op: ctrlplane handles release state).

func (*Provider) Scale

func (p *Provider) Scale(ctx context.Context, instanceID id.ID, spec provider.ResourceSpec) error

Scale adjusts the instance's resource allocation.

func (*Provider) Start

func (p *Provider) Start(ctx context.Context, instanceID id.ID) error

Start scales the deployment to at least 1 replica.

func (*Provider) Status

func (p *Provider) Status(ctx context.Context, instanceID id.ID) (*provider.InstanceStatus, error)

Status returns the current runtime status of an instance.

func (*Provider) Stop

func (p *Provider) Stop(ctx context.Context, instanceID id.ID) error

Stop scales the deployment to 0 replicas.

Jump to

Keyboard shortcuts

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