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
- Variables
- func Run(ctx context.Context, dataDir string, log *slog.Logger, opts Options) error
- func RunWith(ctx context.Context, dataDir string, d *docker.Client, log *slog.Logger, ...) error
- func SpecHash(spec *agentv1.TaskSpec) string
- type LogShipper
- type Options
- type Runner
- func (r *Runner) PrePull(ctx context.Context, image, registryAuth, registryCA string)
- func (r *Runner) RemoveVolumes(ctx context.Context, names []string)
- func (r *Runner) Run(ctx context.Context, spec *agentv1.TaskSpec)
- func (r *Runner) Snapshot(ctx context.Context) []*agentv1.TaskStatus
- func (r *Runner) Stop(ctx context.Context, taskID string, timeout time.Duration, remove bool)
- func (r *Runner) Watch(ctx context.Context)
- type State
- type TaskStats
Constants ¶
const ( HealthStarting = "starting" HealthHealthy = "healthy" HealthUnhealthy = "unhealthy" )
Health states reported in TaskStatus.health.
const ( LabelManaged = "syncloud.managed" LabelTaskID = "syncloud.task_id" LabelSpecHash = "syncloud.spec_hash" LabelSystem = "syncloud.system" )
Container labels set on every SynCloud-managed container.
const TaskNetwork = "syncloud"
TaskNetwork is the Docker network service tasks join (§8).
Variables ¶
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 ¶
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 (*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 (*Runner) PrePull ¶
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 ¶
RemoveVolumes deletes database member volumes (only syncloud-db-*).
func (*Runner) Run ¶
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.
type State ¶
type State struct {
NodeID string `json:"nodeId"`
Name string `json:"name"`
Controller string `json:"controller"`
Gateway string `json:"gateway"`
}
func Join ¶
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 ¶
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 (*TaskStats) Take ¶
func (s *TaskStats) Take() []*agentv1.TaskMetrics
Take returns the queued samples and clears the queue.
Source Files
¶
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). |