provision

package
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MPL-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package provision provides abstract definitions for Chubo cluster provisioners.

Index

Constants

View Source
const StateFileName = "state.yaml"

StateFileName is the name of the yaml state file.

Variables

This section is empty.

Functions

func GetChuboAPIEndpoints

func GetChuboAPIEndpoints(p Provisioner, req NetworkRequest) []string

GetChuboAPIEndpoints returns the OS API endpoints for a provisioner.

Types

type CNIConfig

type CNIConfig struct {
	BinPath  []string
	ConfDir  string
	CacheDir string

	BundleURL string
}

CNIConfig describes CNI part of NetworkRequest.

type Cluster

type Cluster interface {
	// Provisioner returns name of the provisioner used to build the cluster.
	Provisioner() string
	// StatePath returns path to the state directory of the cluster.
	StatePath() (string, error)
	// Info returns running cluster information.
	Info() ClusterInfo
}

Cluster describes the provisioned Cluster.

type ClusterInfo

type ClusterInfo struct {
	ClusterName string

	Network NetworkInfo
	Nodes   []NodeInfo

	// ExtraNodes are not part of the cluster.
	ExtraNodes []NodeInfo

	// ControlPlaneEndpoint is the external endpoint for the cluster control plane load balancer (if any).
	ControlPlaneEndpoint string
}

ClusterInfo describes the cluster.

type ClusterRequest

type ClusterRequest struct {
	Name string

	Network NetworkRequest
	Nodes   NodeRequests

	// Docker specific parameters.
	Image string

	// Boot options (QEMU).
	KernelPath     string
	InitramfsPath  string
	ISOPath        string
	USBPath        string
	UKIPath        string
	DiskImagePath  string
	IPXEBootScript string

	// Encryption
	KMSEndpoint string

	// Path to chuboctl executable to re-execute itself as needed.
	SelfExecutable string

	// Path to the root of the cluster state directory.
	StateDirectory string

	SiderolinkRequest SiderolinkRequest
}

ClusterRequest is the root object describing cluster to be provisioned.

type ConfigInjectionMethod

type ConfigInjectionMethod int

ConfigInjectionMethod describes how to inject configuration into the node.

const (
	// ConfigInjectionMethodHTTP injects configuration via HTTP.
	ConfigInjectionMethodHTTP ConfigInjectionMethod = iota
	// ConfigInjectionMethodMetalISO injects configuration via Metal ISO.
	ConfigInjectionMethodMetalISO
)

type Disk

type Disk struct {
	// Size in bytes.
	Size uint64
	// Whether to skip preallocating the disk space.
	SkipPreallocate bool
	// Driver for the disk.
	//
	// Supported types: "virtio", "ide", "ahci", "scsi", "nvme", "megaraid", "virtiofs" (special).
	Driver string
	// Block size for the disk, defaults to 512 if not set.
	BlockSize uint
	// Serial number for the disk.
	Serial string
	// Tag for the disk, only used for Virtiofs disks.
	Tag string
}

Disk represents a disk size and name in NodeRequest.

type NetworkInfo

type NetworkInfo struct {
	Name              string
	CIDRs             []netip.Prefix
	GatewayAddrs      []netip.Addr
	MTU               int
	NoMasqueradeCIDRs []netip.Prefix
}

NetworkInfo describes cluster network.

type NetworkRequest

type NetworkRequest struct {
	Name              string
	CIDRs             []netip.Prefix
	NoMasqueradeCIDRs []netip.Prefix
	GatewayAddrs      []netip.Addr
	MTU               int
	Nameservers       []netip.Addr

	LoadBalancerPorts []int

	// CNI-specific parameters.
	CNI CNIConfig

	// DHCP options
	DHCPSkipHostname bool

	// Docker-specific parameters.
	DockerDisableIPv6 bool

	// Network chaos parameters.
	NetworkChaos  bool
	Jitter        time.Duration
	Latency       time.Duration
	PacketLoss    float64
	PacketReorder float64
	PacketCorrupt float64
	Bandwidth     int

	// Airgapped limits VM network access to the provisioning network only (qemu/linux).
	Airgapped             bool
	ImageCachePath        string
	ImageCacheTLSCertFile string
	ImageCacheTLSKeyFile  string
	ImageCachePort        uint16
}

NetworkRequest describes cluster network.

type NodeInfo

type NodeInfo struct {
	ID   string
	UUID uuid.UUID
	Name string
	Type machine.Type

	// Share of CPUs, in 1e-9 fractions
	NanoCPUs int64
	// Memory limit in bytes
	Memory int64
	// Disk (volume) size in bytes, if applicable
	DiskSize uint64

	IPs []netip.Addr

	APIPort     int
	TPMStateDir string
}

NodeInfo describes a node.

type NodeRequest

type NodeRequest struct {
	Name string
	IPs  []netip.Addr
	Type machine.Type

	Quirks quirks.Quirks

	Config                config.Provider
	ConfigInjectionMethod ConfigInjectionMethod

	// Share of CPUs, in 1e-9 fractions
	NanoCPUs int64
	// Memory limit in bytes
	Memory int64
	// Disks (volumes), if applicable (VM only)
	Disks []*Disk
	// Mounts (containers only)
	Mounts []mounttypes.Mount
	// Ports
	Ports []string
	// SkipInjectingConfig disables reading configuration from http server
	SkipInjectingConfig bool
	// DefaultBootOrder overrides default boot order "cn" (disk, then network boot).
	//
	// BootOrder can be forced to be "nc" (PXE boot) via the API in QEMU provisioner.
	DefaultBootOrder string

	// ExtraKernelArgs passes additional kernel args
	// to the initial boot from initramfs and vmlinuz.
	//
	// This doesn't apply to boots from ISO or from the disk image.
	ExtraKernelArgs *procfs.Cmdline

	// SDStubKernelArgs passes additional kernel args via the systemd-stub.
	//
	// This applies to boots from ISO and from the disk image.
	SDStubKernelArgs *procfs.Cmdline

	// UUID allows to specify the UUID of the node (VMs only).
	//
	// If not specified, a random UUID will be generated.
	UUID *uuid.UUID

	// BadRTC resets RTC to well known time in the past (QEMU provisioner).
	BadRTC bool

	// PXE-booted VMs
	PXEBooted        bool
	TFTPServer       string
	IPXEBootFilename string
}

NodeRequest describes a request for a node.

type NodeRequests

type NodeRequests []NodeRequest

NodeRequests is a list of NodeRequest.

func (NodeRequests) ControlPlaneNodes

func (reqs NodeRequests) ControlPlaneNodes() (nodes []NodeRequest)

ControlPlaneNodes returns subset of nodes which are Init/ControlPlane type.

func (NodeRequests) FindInitNode

func (reqs NodeRequests) FindInitNode() (req NodeRequest, err error)

FindInitNode looks up init node, it returns an error if no init node is present or if it's duplicate.

func (NodeRequests) PXENodes

func (reqs NodeRequests) PXENodes() (nodes []NodeRequest)

PXENodes returns subset of nodes which are PXE booted.

func (NodeRequests) WorkerNodes

func (reqs NodeRequests) WorkerNodes() (nodes []NodeRequest)

WorkerNodes returns subset of nodes which are Init/ControlPlane type.

type Option

type Option func(o *Options) error

Option controls Provisioner.

func WithBootlader

func WithBootlader(enabled bool) Option

WithBootlader enables or disables bootloader (bootloader is enabled by default).

func WithChuboClient

func WithChuboClient(client *client.Client) Option

WithChuboClient specifies client to use when accessing a Chubo cluster.

func WithChuboConfig

func WithChuboConfig(chuboConfig *clientconfig.Config) Option

WithChuboConfig specifies chuboconfig to use when accessing a Chubo cluster.

func WithControlPlaneEndpoint

func WithControlPlaneEndpoint(endpoint string) Option

WithControlPlaneEndpoint specifies full external control plane endpoint to use when accessing a provisioned cluster.

func WithDebugShell

func WithDebugShell(enabled bool) Option

WithDebugShell drops into debug shell in initramfs.

func WithDeleteOnErr

func WithDeleteOnErr(v bool) Option

WithDeleteOnErr informs the provisioner to delete cluster state folder on error.

func WithDockerPorts

func WithDockerPorts(ports []string) Option

WithDockerPorts allows docker provisioner to expose ports on workers.

func WithDockerPortsHostIP

func WithDockerPortsHostIP(hostIP string) Option

WithDockerPortsHostIP sets host IP for docker provisioner to expose ports on workers.

func WithExtraUEFISearchPaths

func WithExtraUEFISearchPaths(extraUEFISearchPaths []string) Option

WithExtraUEFISearchPaths configures additional search paths to look for UEFI firmware.

func WithIOMMU

func WithIOMMU(enabled bool) Option

WithIOMMU enables or disables IOMMU.

func WithJSONLogs

func WithJSONLogs(endpoint string) Option

WithJSONLogs specifies endpoint to send logs in JSON format.

func WithKMS

func WithKMS(endpoint string) Option

WithKMS inits KMS server in the provisioner.

func WithLogWriter

func WithLogWriter(w io.Writer) Option

WithLogWriter sets logging destination.

func WithSaveClusterLogsArchivePath

func WithSaveClusterLogsArchivePath(path string) Option

WithSaveClusterLogsArchivePath specifies path to save cluster logs archive on destroy.

func WithSaveSupportArchivePath

func WithSaveSupportArchivePath(path string) Option

WithSaveSupportArchivePath specifies path to save support archive on destroy.

func WithSiderolinkAgent

func WithSiderolinkAgent(v bool) Option

WithSiderolinkAgent enables or disables siderolink agent.

func WithSkipInjectingExtraCmdline

func WithSkipInjectingExtraCmdline(v bool) Option

WithSkipInjectingExtraCmdline prevents injecting extra kernel args into EFI vars.

func WithTPM1_2

func WithTPM1_2(enabled bool) Option

WithTPM1_2 enables or disables TPM1.2 emulation.

func WithTPM2

func WithTPM2(enabled bool) Option

WithTPM2 enables or disables TPM2.0 emulation.

func WithTalosClient

func WithTalosClient(legacyClient *client.Client) Option

WithTalosClient is a legacy alias kept for compatibility.

func WithTalosConfig

func WithTalosConfig(legacyConfig *clientconfig.Config) Option

WithTalosConfig is a legacy alias kept for compatibility.

func WithTargetArch

func WithTargetArch(arch string) Option

WithTargetArch specifies target architecture for the cluster.

func WithUEFI

func WithUEFI(enabled bool) Option

WithUEFI enables or disables UEFI boot on amd64 (default for amd64 is BIOS boot).

type Options

type Options struct {
	LogWriter   io.Writer
	ChuboConfig *clientconfig.Config
	ChuboClient *client.Client
	// TalosConfig is a legacy compatibility alias.
	TalosConfig *clientconfig.Config
	// TalosClient is a legacy compatibility alias.
	TalosClient          *client.Client
	ControlPlaneEndpoint string
	TargetArch           string

	// Enable bootloader by booting from disk image after install.
	BootloaderEnabled bool

	// SkipInjectingExtraCmdline prevents injecting extra kernel args, e.g., console=ttyS0, into the EFI vars. Only applies when UEFI is enabled.
	SkipInjectingExtraCmdline bool

	// Enable UEFI (for amd64), arm64 can only boot UEFI
	UEFIEnabled bool
	// Enable TPM 1.2 emulation using swtpm.
	TPM1_2Enabled bool
	// Enable TPM 2.0 emulation using swtpm.
	TPM2Enabled bool
	// Enable debug shell in the bootloader.
	WithDebugShell bool
	// Enable IOMMU for VMs and add a new PCI root controller and network interface.
	IOMMUEnabled bool
	// Configure additional search paths to look for UEFI firmware.
	ExtraUEFISearchPaths []string

	// Expose ports to worker machines in docker provisioner
	DockerPorts                []string
	DockerPortsHostIP          string
	SaveSupportArchivePath     string
	SaveClusterLogsArchivePath string
	DeleteStateOnErr           bool

	KMSEndpoint      string
	JSONLogsEndpoint string

	SiderolinkEnabled bool
}

Options describes Provisioner parameters.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns default options.

func (Options) EffectiveClient

func (o Options) EffectiveClient() *client.Client

EffectiveClient returns the primary API client with legacy fallback.

func (Options) EffectiveConfig

func (o Options) EffectiveConfig() *clientconfig.Config

EffectiveConfig returns the primary client config with legacy fallback.

type Provisioner

type Provisioner interface {
	Create(context.Context, ClusterRequest, ...Option) (Cluster, error)
	Destroy(context.Context, Cluster, ...Option) error

	Reflect(ctx context.Context, clusterName, stateDirectory string) (Cluster, error)

	GenOptions(NetworkRequest, *config.VersionContract) ([]generate.Option, []bundle.Option)

	GetInClusterControlPlaneEndpoint(req NetworkRequest, controlPlanePort int) string
	GetExternalControlPlaneEndpoint(req NetworkRequest, controlPlanePort int) string
	GetChuboAPIEndpoints(NetworkRequest) []string

	GetFirstInterface() v1alpha1.IfaceSelector
	GetFirstInterfaceName() string

	Close() error

	UserDiskName(index int) string
}

Provisioner is an interface each provisioner should implement.

type SiderolinkBind

type SiderolinkBind struct {
	UUID uuid.UUID
	Addr netip.Addr
}

SiderolinkBind describes a pair of prebinded UUID->Addr for SideroLink agent.

type SiderolinkRequest

type SiderolinkRequest struct {
	WireguardEndpoint string
	APIEndpoint       string
	APICertificate    []byte
	APIKey            []byte
	SinkEndpoint      string
	LogEndpoint       string
	SiderolinkBind    []SiderolinkBind
}

SiderolinkRequest describes a request for SideroLink agent.

func (*SiderolinkRequest) GetAddr

func (sr *SiderolinkRequest) GetAddr(u *uuid.UUID) (netip.Addr, bool)

GetAddr returns the address for the given UUID.

type State

type State struct {
	ProvisionerName string
	BridgeName      string

	ClusterInfo ClusterInfo

	VMCNIConfig *libcni.NetworkConfigList
	// contains filtered or unexported fields
}

State common state representation for vm provisioners.

func NewState

func NewState(statePath, provisionerName, clusterName string) (*State, error)

NewState create new vm provisioner state.

func ReadState

func ReadState(ctx context.Context, clusterName, stateDirectory string) (*State, error)

ReadState reads and parses the state saved to a file.

func (*State) GetRelativePath

func (s *State) GetRelativePath(path string) string

GetRelativePath get file path relative to config folder.

func (*State) GetShmPath

func (s *State) GetShmPath(path string) string

GetShmPath get shm path.

func (*State) Info

func (s *State) Info() ClusterInfo

Info get cluster info.

func (*State) Provisioner

func (s *State) Provisioner() string

Provisioner get provisioner name.

func (*State) Save

func (s *State) Save() error

Save save state to config file.

func (*State) StatePath

func (s *State) StatePath() (string, error)

StatePath get state config file path.

Directories

Path Synopsis
Package access provides methods to access a provisioned Chubo cluster.
Package access provides methods to access a provisioned Chubo cluster.
internal
cniutils
Package cniutils provides helper functions to parse CNI results.
Package cniutils provides helper functions to parse CNI results.
inmemhttp
Package inmemhttp implements temporary HTTP server which is based off memory fs.
Package inmemhttp implements temporary HTTP server which is based off memory fs.
docker
Package docker implements Provisioner via docker.
Package docker implements Provisioner via docker.
vm
Package vm implements common methods for VM provisioners.
Package vm implements common methods for VM provisioners.
vm/internal/ipxe
Package ipxe provides utility to deliver iPXE images and build iPXE scripts.
Package ipxe provides utility to deliver iPXE images and build iPXE scripts.

Jump to

Keyboard shortcuts

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