agent

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 42 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agent is syncloud-agent: it joins a node to the controller and keeps one outbound mTLS gRPC stream open for heartbeats and (later) commands (§6).

Index

Constants

View Source
const (
	HealthStarting  = "starting"
	HealthHealthy   = "healthy"
	HealthUnhealthy = "unhealthy"
)

Health states reported in TaskStatus.health.

View Source
const (
	LabelManaged  = "syncloud.managed"
	LabelTaskID   = "syncloud.task_id"
	LabelSpecHash = "syncloud.spec_hash"
	LabelSystem   = "syncloud.system"
)

Container labels set on every SynCloud-managed container.

View Source
const TaskNetwork = "syncloud"

TaskNetwork is the Docker network service tasks join (§8).

Variables

View Source
var DockerCertsDir = "/etc/docker/certs.d"

DockerCertsDir is where the Docker daemon looks for per-registry CAs; it reads them on every connection, so no restart is needed.

Functions

func Run

func Run(ctx context.Context, dataDir string, log *slog.Logger, opts Options) error

Run keeps the agent connected until ctx ends, reconnecting with backoff.

func RunWith

func RunWith(ctx context.Context, dataDir string, d *docker.Client, log *slog.Logger, opts Options) error

RunWith is Run with an explicit Docker client (tests).

func SpecHash

func SpecHash(spec *agentv1.TaskSpec) string

SpecHash identifies a spec's content; a changed hash means "recreate".

Types

type LogShipper

type LogShipper struct {
	// contains filtered or unexported fields
}

LogShipper follows the output of every managed container and queues it for the controller (§9.2). Positions are saved so a restarted agent resumes where it stopped instead of re-sending or skipping lines.

func NewLogShipper

func NewLogShipper(d *docker.Client, dataDir string, log *slog.Logger) *LogShipper

func (*LogShipper) Run

func (s *LogShipper) Run(ctx context.Context)

Run tails running containers and new ones as they start.

type Options

type Options struct {
	// Network joins the WireGuard mesh (§8). It needs root.
	Network bool
	// AdvertiseAddress is the address peers dial for WireGuard ("" = the
	// address the controller sees).
	AdvertiseAddress string
	// RenewBefore renews the node certificate when less than this is left
	// (default 30 days of the 90-day validity).
	RenewBefore time.Duration
	// NoHostShell refuses node shells (a terminal on the node itself).
	NoHostShell bool
}

Options tune the agent.

type Runner

type Runner struct {

	// NetworkReady reports whether tasks may join TaskNetwork yet (nil: always).
	NetworkReady func() error
	// OnStart is called when a managed container starts (it may need to
	// join security group sets, §8.3).
	OnStart func()
	// contains filtered or unexported fields
}

Runner applies task specs to the local Docker Engine (§6.2 Executor) and reports state changes. Operations on the same task are serialized.

func NewRunner

func NewRunner(d *docker.Client, log *slog.Logger) *Runner

func (*Runner) PrePull

func (r *Runner) PrePull(ctx context.Context, image, registryAuth, registryCA string)

PrePull downloads an image ahead of a deployment unless it is already present or being pulled; failures are only logged (the task's own pull reports them).

func (*Runner) RemoveVolumes

func (r *Runner) RemoveVolumes(ctx context.Context, names []string)

RemoveVolumes deletes database member volumes (only syncloud-db-*).

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, spec *agentv1.TaskSpec)

Run makes the task's container match spec: unchanged and running → nothing; unchanged and stopped → start; changed or missing → (re)create.

func (*Runner) Snapshot

func (r *Runner) Snapshot(ctx context.Context) []*agentv1.TaskStatus

Snapshot reports every managed container, sent in Hello after (re)connecting.

func (*Runner) Stop

func (r *Runner) Stop(ctx context.Context, taskID string, timeout time.Duration, remove bool)

Stop stops (and optionally removes) the task's containers.

func (*Runner) Watch

func (r *Runner) Watch(ctx context.Context)

Watch reports container state changes from Docker events until ctx ends, reconnecting to the event stream if it drops.

type State

type State struct {
	NodeID     string `json:"nodeId"`
	Name       string `json:"name"`
	Controller string `json:"controller"`
	Gateway    string `json:"gateway"`
}

func Join

func Join(ctx context.Context, dataDir, controllerURL, token, name, pin string) (State, error)

Join registers this machine with the controller using a join token. The node key is generated here and never leaves the machine. pin, when set, is the controller certificate's public-key pin (pki.SPKIPin): its certificate is self-signed on private networks.

func SetController

func SetController(dataDir, gateway, controllerURL string) (State, error)

SetController points a joined agent at a controller that moved (restored on a new host): the gateway address and, optionally, the controller URL. The node keeps its identity; the restored CA still trusts it.

type TaskStats

type TaskStats struct {
	// contains filtered or unexported fields
}

TaskStats samples the resource usage of every running task container and queues the samples for the next heartbeat (§9.1).

func NewTaskStats

func NewTaskStats(d *docker.Client, log *slog.Logger) *TaskStats

func (*TaskStats) Run

func (s *TaskStats) Run(ctx context.Context)

func (*TaskStats) Take

func (s *TaskStats) Take() []*agentv1.TaskMetrics

Take returns the queued samples and clears the queue.

Directories

Path Synopsis
Package dnssrv is the agent's DNS server for tasks (§8.1).
Package dnssrv is the agent's DNS server for tasks (§8.1).
Package docker is a minimal Docker Engine API client over the local unix socket: only what the agent needs.
Package docker is a minimal Docker Engine API client over the local unix socket: only what the agent needs.
Package netcfg applies the controller's mesh configuration on a node (§8): the WireGuard interface and peers, routes for container subnets, the Docker network "syncloud" with the node's subnet, and the nftables rules that keep container traffic un-NATed inside the mesh and masqueraded to the internet.
Package netcfg applies the controller's mesh configuration on a node (§8): the WireGuard interface and peers, routes for container subnets, the Docker network "syncloud" with the node's subnet, and the nftables rules that keep container traffic un-NATed inside the mesh and masqueraded to the internet.
Package sysinfo reads node facts and metrics for heartbeats (§6.2).
Package sysinfo reads node facts and metrics for heartbeats (§6.2).

Jump to

Keyboard shortcuts

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