machine

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMachineSockPath = "/run/uncloud/machine.sock"
	DefaultUncloudSockPath = "/run/uncloud/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"
)
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
	MachineSockPath string
	UncloudSockPath string

	CorrosionDir           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

	// 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) 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) 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

func (m *Machine) Inspect(_ context.Context, _ *emptypb.Empty) (*pb.MachineInfo, 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) 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) 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 is ready to serve requests on the local API server.

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) 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.

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
	// 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 writes the state data to the file at the given 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
pb

Jump to

Keyboard shortcuts

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