provider

package
v6.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package provider defines infrastructure providers for running Kubernetes cluster nodes.

Providers handle infrastructure-level operations:

  • Creating and destroying nodes (Docker containers, cloud VMs, etc.)
  • Starting and stopping nodes
  • Managing provider-specific resources (networks, volumes, port mappings)

This package is separate from the provisioner package which handles distribution-specific operations (bootstrapping K8s, configuring etcd, etc.).

Currently supported providers:

  • Docker: Runs cluster nodes as Docker containers (for Kind, K3d, Talos)

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoNodes is returned when no nodes are found for a cluster.
	ErrNoNodes = errors.New("no nodes found for cluster")

	// ErrProviderUnavailable is returned when the provider is not available.
	ErrProviderUnavailable = errors.New("provider is not available")

	// ErrClusterNotFound is returned when the cluster does not exist in the provider.
	ErrClusterNotFound = errors.New("cluster not found")

	// ErrUnknownLabelScheme is returned when an unknown label scheme is specified.
	ErrUnknownLabelScheme = errors.New("unknown label scheme")

	// ErrSkipAction is a sentinel error indicating no action is needed for the current item.
	// This is used in iteration callbacks to signal that processing should continue
	// to the next item without waiting for any action.
	ErrSkipAction = errors.New("skip action")
)

Common errors for provider operations.

Functions

func CheckNodesExist

func CheckNodesExist(ctx context.Context, lister NodeLister, clusterName string) (bool, error)

CheckNodesExist returns true if the given cluster has at least one node. This is a shared helper for provider implementations that delegate NodesExist to ListNodes.

Types

type AvailableProvider

type AvailableProvider interface {
	NodeLister
	// IsAvailable returns true if the provider is ready for use.
	IsAvailable() bool
}

AvailableProvider is a provider that can report whether it's available.

type ClusterStatus added in v6.3.0

type ClusterStatus struct {
	// Phase is the high-level lifecycle phase (e.g., "running", "RUNNING", "initializing").
	Phase string

	// Ready indicates whether the cluster is considered healthy by the provider.
	Ready bool

	// NodesTotal is the total number of nodes (machines, servers, containers) in the cluster.
	NodesTotal int

	// NodesReady is the number of nodes that are in a healthy/ready state.
	NodesReady int

	// Nodes lists individual node details.
	Nodes []NodeInfo

	// Endpoint is the provider API endpoint URL (populated by cloud providers like Omni).
	Endpoint string
}

ClusterStatus contains the status of a cluster as reported by its infrastructure provider. Providers populate Phase and Ready. NodesTotal, NodesReady, and Nodes are best-effort and may be zero/empty even on success (e.g., when node listing fails independently). Provider-specific fields (e.g., Endpoint) are populated only by providers that support them.

func BuildClusterStatus added in v6.3.0

func BuildClusterStatus(nodes []NodeInfo, readyState string) *ClusterStatus

BuildClusterStatus derives a ClusterStatus from a list of nodes by counting how many are in the given readyState. Returns nil if nodes is empty.

func GetClusterStatusFromLister added in v6.3.0

func GetClusterStatusFromLister(
	ctx context.Context,
	lister NodeLister,
	clusterName string,
	readyState string,
) (*ClusterStatus, error)

GetClusterStatusFromLister lists nodes and derives cluster status using the given readyState. This is a shared helper for providers whose GetClusterStatus implementation only needs ListNodes + BuildClusterStatus.

type MockProvider

type MockProvider struct {
	mock.Mock
}

MockProvider is a mock implementation of the Provider interface for testing.

func NewMockProvider

func NewMockProvider() *MockProvider

NewMockProvider creates a new MockProvider instance.

func (*MockProvider) DeleteNodes

func (m *MockProvider) DeleteNodes(ctx context.Context, clusterName string) error

DeleteNodes mocks deleting nodes for a cluster.

func (*MockProvider) GetClusterStatus added in v6.3.0

func (m *MockProvider) GetClusterStatus(
	ctx context.Context,
	clusterName string,
) (*ClusterStatus, error)

GetClusterStatus mocks getting cluster status.

func (*MockProvider) ListAllClusters

func (m *MockProvider) ListAllClusters(ctx context.Context) ([]string, error)

ListAllClusters mocks listing all clusters.

func (*MockProvider) ListNodes

func (m *MockProvider) ListNodes(ctx context.Context, clusterName string) ([]NodeInfo, error)

ListNodes mocks listing nodes for a cluster.

func (*MockProvider) NodesExist

func (m *MockProvider) NodesExist(ctx context.Context, clusterName string) (bool, error)

NodesExist mocks checking if nodes exist.

func (*MockProvider) StartNodes

func (m *MockProvider) StartNodes(ctx context.Context, clusterName string) error

StartNodes mocks starting nodes for a cluster.

func (*MockProvider) StopNodes

func (m *MockProvider) StopNodes(ctx context.Context, clusterName string) error

StopNodes mocks stopping nodes for a cluster.

type NodeInfo

type NodeInfo struct {
	// Name is the unique identifier of the node (container name, VM ID, etc.)
	Name string

	// ClusterName is the name of the cluster this node belongs to.
	ClusterName string

	// Role is the role of the node (control-plane, worker).
	Role string

	// State is the current state of the node (running, stopped, etc.)
	State string
}

NodeInfo contains information about a node managed by a provider.

func EnsureAvailableAndListNodes

func EnsureAvailableAndListNodes(
	ctx context.Context,
	prov AvailableProvider,
	clusterName string,
) ([]NodeInfo, error)

EnsureAvailableAndListNodes validates provider availability and returns node list. This is a shared helper for provider implementations.

type NodeLister

type NodeLister interface {
	ListNodes(ctx context.Context, clusterName string) ([]NodeInfo, error)
}

NodeLister can list nodes for a cluster. This minimal interface is used by shared helpers to avoid coupling to the full Provider interface.

type Provider

type Provider interface {
	// StartNodes starts the nodes for a cluster.
	// If no nodes exist, returns ErrNoNodes.
	StartNodes(ctx context.Context, clusterName string) error

	// StopNodes stops the nodes for a cluster.
	// If no nodes exist, returns ErrNoNodes.
	StopNodes(ctx context.Context, clusterName string) error

	// ListNodes returns all nodes for a specific cluster.
	ListNodes(ctx context.Context, clusterName string) ([]NodeInfo, error)

	// ListAllClusters returns the names of all clusters managed by this provider.
	ListAllClusters(ctx context.Context) ([]string, error)

	// NodesExist returns true if nodes exist for the given cluster name.
	NodesExist(ctx context.Context, clusterName string) (bool, error)

	// DeleteNodes removes all nodes for a cluster.
	// Note: Most provisioners handle node deletion through their SDK,
	// so this is primarily used for cleanup scenarios.
	DeleteNodes(ctx context.Context, clusterName string) error

	// GetClusterStatus returns the provider-level status of a cluster.
	// Returns nil and no error if the cluster does not exist in the provider.
	GetClusterStatus(ctx context.Context, clusterName string) (*ClusterStatus, error)
}

Provider defines the interface for infrastructure providers. Providers handle node-level operations independent of the Kubernetes distribution.

Directories

Path Synopsis
Package docker provides a Docker-based infrastructure provider.
Package docker provides a Docker-based infrastructure provider.
Package hetzner implements provider.Provider for Hetzner Cloud servers.
Package hetzner implements provider.Provider for Hetzner Cloud servers.
Package omni implements provider.Provider for Sidero Omni managed Talos clusters.
Package omni implements provider.Provider for Sidero Omni managed Talos clusters.

Jump to

Keyboard shortcuts

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