Skip to content

feat(agent): run instances on hosts outside kubernetes - #50

Merged
TheMeinerLP merged 10 commits into
mainfrom
feat/v2-agent
Nov 25, 2026
Merged

TheMeinerLP merged 10 commits into
mainfrom
feat/v2-agent

Conversation

@TheMeinerLP

Copy link
Copy Markdown
Contributor

Problem

Grus could only start instances in the cluster or as processes on the controller's own machine. mc01 is a real server outside Kubernetes, and the proxies in the cluster need to reach game servers there.

Approach

A small agent (grus-agent) runs on mc01. It only makes outgoing HTTPS calls to the controller: it announces itself, asks what should run, starts and stops local processes, and reports what it sees. The controller treats the agent's host like any other host behind its router, so pools are placed on mc01 with placement: {driver: agent, host: mc01}.

  • Each agent has its own token (the controller only stores the hash). The token works for that host and for downloading template archives, nothing else.
  • If the agent or the gateway is away, instances keep running and the controller keeps their state; after a controller restart it adopts what the agent still runs, also when the agent reconnects later.
  • Instances started by the process driver no longer inherit the agent's or controller's environment, and get a port from a configurable range, reported as the advertised address.
  • Restarting the agent restarts its instances (documented in deploy/agent/README.md).

Testing

Unit tests for the process driver changes, the remote driver (fake clock, no sleeps), the API auth and routes, controller adoption and the agent. One end-to-end test runs controller and agent in one process and takes an instance from start through Ready to stop; it polls with a deadline because a child process runs concurrently.

…m a range

Children only get PATH, HOME, LANG, LC_ALL, TZ, JAVA_HOME and TMPDIR
from the parent plus the spec env and GRUS_*. A configurable port range,
an advertised address, the {{port}} and ${GRUS_DIR} placeholders and a
java binary override support instances on a shared host.
The driver keeps the desired instances, stop and kill requests and
console lines of one agent host in memory and serves them to the agent
through a long poll. The agent's reports become the observed list; the
list fails once the agent is silent so the reconciler keeps the state.
Adopt no longer fails when an agent host cannot be listed yet. Its
unknown instances are adopted by the reconcile loop as soon as the host
reports, and instances record the real host instead of the router.
Agents register, long-poll their desired state and report what they run
under /v1/agents/{host}. An agent token only works for its own host and
for template archive downloads; hosts are listed under /v1/hosts.
The controller runs a router over its configured driver and the agent
hosts named in GRUS_AGENT_TOKENS. Pools are placed by their effective
placement; an agent host that is not online fails the start with a clear
reason instead of crashing.
The agent registers with the controller, long-polls its desired
instances, runs them with the process driver and reports what it
observes. Instances keep running while the controller is unreachable;
processes left over from an earlier agent run are ended on start.
@TheMeinerLP
TheMeinerLP merged commit e6760f6 into main Nov 25, 2026
7 checks passed
@TheMeinerLP
TheMeinerLP deleted the feat/v2-agent branch November 25, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant