Add [master] config section to agent for registration

Heartbeat client now reads master connection settings from the agent
config ([master] section) with env var fallback. Includes address,
ca_cert, token_path, and role fields.

Agent's Run() creates and starts the heartbeat client automatically
when [master] is configured.

Tested on all three nodes: rift (master), svc (edge), orion (worker)
all registered with the master and sending heartbeats every 30s.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-04 13:53:15 -07:00
parent 6351b68ef6
commit 3b08caaa0a
3 changed files with 43 additions and 7 deletions

View File

@@ -131,6 +131,15 @@ func Run(cfg *config.AgentConfig, version string) error {
}
}
// Start heartbeat client (registers with master and sends heartbeats).
hbClient, hbErr := NewHeartbeatClient(*cfg, logger)
if hbErr != nil {
logger.Warn("heartbeat client failed to start", "err", hbErr)
} else if hbClient != nil {
hbClient.Start()
logger.Info("heartbeat client started", "master", cfg.Master.Address)
}
mon.Start()
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
@@ -144,6 +153,9 @@ func Run(cfg *config.AgentConfig, version string) error {
select {
case <-ctx.Done():
logger.Info("shutting down")
if hbClient != nil {
hbClient.Stop()
}
mon.Stop()
server.GracefulStop()
_ = proxy.Close()