machine

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 59 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMachineAPISockPath is the default path to the Unix socket for API requests handled directly by this
	// machine.
	DefaultMachineAPISockPath = "/run/uncloud/machine.sock"
	// DefaultClusterAPISockPath is the default path to the Unix socket for the client-facing API that routes requests
	// across the cluster.
	DefaultClusterAPISockPath = "/run/uncloud/api/uncloud.sock"
	DefaultSockGroup          = "uncloud"
	// DefaultCaddyAdminSockPath is the default path to the Caddy admin socket for validating the generated Caddy
	// reverse proxy configuration.
	DefaultCaddyAdminSockPath = "/run/uncloud/caddy/admin.sock"
	// DefaultCorrosionRunDir is the default runtime directory for the Corrosion service.
	DefaultCorrosionRunDir = "/run/uncloud/corrosion"
)
View Source
const (
	DefaultDataDir = "/var/lib/uncloud"
	StateFileName  = "machine.json"
)
View Source
const DBFileName = "machine.db"
View Source
const (
	TokenPrefix = "mtkn:"
)

Variables

This section is empty.

Functions

func NewDB

func NewDB(path string) (*sqlx.DB, error)

NewDB creates a new connection to machine SQLite database and runs schema migrations if necessary.

func StatePath

func StatePath(dataDir string) string

StatePath returns the path to the machine state file within the given data directory.

Types

type Config

type Config struct {
	// DataDir is the directory where the machine stores its persistent state. Default is /var/lib/uncloud.
	DataDir string
	// MachineAPISockPath is the path to the Unix socket for API requests handled directly by this machine.
	MachineAPISockPath string
	// ClusterAPISockPath is the path to the Unix socket for the client-facing API that routes requests across the
	// cluster.
	ClusterAPISockPath string
	// ClusterAPIListener is an optional pre-bound listener for the client-facing API that routes requests across the
	// cluster. If set, Run takes ownership of it and closes it on shutdown or startup failure.
	ClusterAPIListener net.Listener

	CorrosionDataDir string
	// CorrosionRunDir is the runtime directory for the corrosion service.
	CorrosionRunDir        string
	CorrosionAPIListenAddr netip.AddrPort
	CorrosionAPIAddr       netip.AddrPort
	CorrosionAdminSockPath string
	CorrosionService       corroservice.Service
	// CorrosionUser sets the Linux user for running the corrosion service.
	CorrosionUser string

	// DockerClient manages system and user containers using the local Docker daemon.
	DockerClient *client.Client
	// ContainerdSockPath is the path to the containerd.sock used by Docker.
	ContainerdSockPath string

	// CaddyConfigDir specifies the directory where the machine generates the Caddy reverse proxy configuration file
	// for routing external traffic to service containers across the internal network. Default is DataDir/caddy.
	CaddyConfigDir string
	// DNSUpstreams specifies the upstream DNS servers for the embedded internal DNS server.
	DNSUpstreams []netip.AddrPort
}

func (*Config) SetDefaults

func (c *Config) SetDefaults() (*Config, error)

SetDefaults returns a new Config with default values set where not provided.

type Machine

type Machine struct {
	pb.UnimplementedMachineServer
	// contains filtered or unexported fields
}

func NewMachine

func NewMachine(config *Config) (*Machine, error)

func (*Machine) CheckPrerequisites added in v0.7.0

func (m *Machine) CheckPrerequisites(_ context.Context, _ *emptypb.Empty) (*pb.CheckPrerequisitesResponse, error)

CheckPrerequisites verifies if the machine meets all necessary system requirements to participate in the cluster.

func (*Machine) ContainerdSock added in v0.19.0

func (m *Machine) ContainerdSock() string

ContainerdSock returns the path to the containerd socket used by Docker, auto-discovering it from well-known locations if it's not explicitly configured. Returns an empty string if the socket cannot be detected.

func (*Machine) IP added in v0.7.0

func (m *Machine) IP() netip.Addr

IP returns the machine IPv4 address in the cluster network which is the first address in the machine subnet.

func (*Machine) Info added in v0.20.0

func (m *Machine) Info(ctx context.Context) *pb.MachineInfo

Info returns the machine configuration and runtime details.

func (*Machine) InitCluster

func (m *Machine) InitCluster(ctx context.Context, req *pb.InitClusterRequest) (*pb.InitClusterResponse, error)

InitCluster initialises a new cluster on the local machine with the provided network configuration.

func (*Machine) Initialised

func (m *Machine) Initialised() bool

Initialised returns true if the machine has been configured as a member of a cluster, either by initialising a new cluster on it or joining an existing one.

func (*Machine) Inspect deprecated

func (m *Machine) Inspect(ctx context.Context, _ *emptypb.Empty) (*pb.MachineInfo, error)

Deprecated: use InspectMachine instead.

func (*Machine) InspectMachine added in v0.16.0

func (m *Machine) InspectMachine(ctx context.Context, _ *emptypb.Empty) (*pb.InspectMachineResponse, error)

func (*Machine) InspectService

func (m *Machine) InspectService(
	ctx context.Context, req *pb.InspectServiceRequest,
) (*pb.InspectServiceResponse, error)

InspectService returns detailed information about a service and its containers stored in the cluster store.

func (*Machine) InspectWireGuardNetwork added in v0.16.0

func (m *Machine) InspectWireGuardNetwork(
	_ context.Context, _ *emptypb.Empty,
) (*pb.InspectWireGuardNetworkResponse, error)

InspectWireGuardNetwork retrieves the current WireGuard network configuration and peer status.

func (*Machine) IsNetworkReady added in v0.10.0

func (m *Machine) IsNetworkReady() bool

IsNetworkReady returns true if the Docker network is ready for containers.

func (*Machine) JoinCluster

func (m *Machine) JoinCluster(_ context.Context, req *pb.JoinClusterRequest) (*emptypb.Empty, error)

JoinCluster configures the local machine to join an existing cluster.

func (*Machine) MachineLogs added in v0.18.0

func (m *Machine) MachineLogs(
	req *pb.LogsRequest, stream grpc.ServerStreamingServer[pb.LogEntry],
) error

MachineLogs streams logs from a system service.

func (*Machine) Reset added in v0.9.0

func (m *Machine) Reset(_ context.Context, _ *pb.ResetRequest) (*emptypb.Empty, error)

Reset restores the machine to a clean state, scheduling a graceful shutdown and removing all cluster-related configuration and resource. The uncloud daemon will restart the machine if managed by systemd.

func (*Machine) Run

func (m *Machine) Run(ctx context.Context) error

func (*Machine) Started

func (m *Machine) Started() <-chan struct{}

Started returns a channel that is closed when the machine and cluster API servers are ready to serve requests.

func (*Machine) Token

func (m *Machine) Token(_ context.Context, _ *emptypb.Empty) (*pb.TokenResponse, error)

Token returns the local machine's token that can be used for adding the machine to a cluster.

func (*Machine) UpdateMachine added in v0.20.0

func (m *Machine) UpdateMachine(ctx context.Context, req *pb.UpdateMachineRequest) (*pb.UpdateMachineResponse, error)

UpdateMachine updates the configuration of this machine in its local state (the source of truth) and syncs the result to the cluster store.

func (*Machine) WaitForNetworkReady added in v0.10.0

func (m *Machine) WaitForNetworkReady(ctx context.Context) error

WaitForNetworkReady waits for the Docker network to be ready for containers. It returns nil when the network is ready or an error if the context is cancelled.

func (*Machine) WaitForStoreVersion added in v0.21.0

func (m *Machine) WaitForStoreVersion(ctx context.Context, req *pb.WaitForStoreVersionRequest) (*emptypb.Empty, error)

type State

type State struct {
	// ID uniquely identifies this machine in the cluster.
	ID string
	// Name provides a human-readable identifier for the machine.
	Name string
	// Network specifies the network configuration for this machine.
	Network *network.Config
	// PublicIP is this machine's advertised public IP for ingress. Zero value if unset.
	PublicIP netip.Addr `json:",omitempty"`
	// MinStoreVersion is the cluster store version this machine must reach before participating.
	// Per-actor vector (Corrosion actor UUID → max processed db_version) captured from an existing
	// member at join time. Cleared once reached.
	MinStoreVersion api.StoreVersion `json:",omitempty"`
	// CorrosionAPIToken authenticates requests to the local Corrosion API.
	CorrosionAPIToken secret.Secret `json:",omitempty"`
	// contains filtered or unexported fields
}

State defines the machine-specific configuration within a cluster. It encapsulates essential identifiers and settings required to establish an overlay network and operate as a member of a cluster.

func ParseState

func ParseState(path string) (*State, error)

ParseState reads and decodes a state from the file at the given path.

func (*State) Encode

func (c *State) Encode() ([]byte, error)

Encode returns the JSON encoded state data.

func (*State) Save

func (c *State) Save() error

Save atomically writes the state data to the file at the configured path.

func (*State) SetPath

func (c *State) SetPath(path string)

SetPath sets the file path the state can be saved to.

type Token

type Token struct {
	PublicKey secret.Secret
	PublicIP  netip.Addr
	Endpoints []netip.AddrPort
}

Token represents the machine's token for joining a cluster.

func NewToken

func NewToken(publicKey secret.Secret, publicIP netip.Addr, endpoints []netip.AddrPort) Token

NewToken creates a new machine token with the given public key and endpoints.

func ParseToken

func ParseToken(s string) (Token, error)

ParseToken decodes a machine token from the given string.

func (Token) String

func (t Token) String() (string, error)

String returns the machine token encoded as a string.

Directories

Path Synopsis
api
Package caddystorage implements the machine-local Caddy storage API.
Package caddystorage implements the machine-local Caddy storage API.
Package corromigrate handles the one-time migration of the on-disk Corrosion store from systemd-managed v0.x to v1.0.0 running in a uncloudd-managed container.
Package corromigrate handles the one-time migration of the on-disk Corrosion store from systemd-managed v0.x to v1.0.0 running in a uncloudd-managed container.
Package osinfo collects the host operating system information.
Package osinfo collects the host operating system information.

Jump to

Keyboard shortcuts

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