Mothership
Version 0.0.1 · Owners: @benallfree
A control plane for a fleet of edges. The mothership is a PocketOne app that records which edges exist and which instances run where. Each edge asks it about a hostname the first time a request names one, follows changes to that hostname on one stream, serves its own instances and forwards requests for the rest to the edge that runs them.
One operator, no users: owners and accounts are the tenants extension (planned), which adds its collections and wraps instance.resolve/v1. Each layer is optional: an edge runs without a mothership, and a mothership without tenants.
Install · Configure · Use · Integrations · Example
Install
Both sides are built into pocketone; pocketone.yaml's mothership section picks one.
- The mothership is a single app with
serve: true. It keeps theedgesandinstancescollections (Schema) and serves instance.watch/v1 to the edges (Server). - An edge is a multisite host with
urlandself. It takes its instances from the mothership (instance.source/v1 and instance.lookup/v1) and the other edges from it.
The module is pocketone.dev/ext/mothership. In your own build: extkit registers mothership.NewSchema() and
mothership.NewServer() on the mothership app (a control plane with its own collections registers only the server,
beside its own instance.resolve/v1); on an edge, client.FromSection(log) returns the client for the config (nil
without a url), a multisite host extension, as examples/pocketone/binary/multi.go
does. The client keeps its answers in the host's cache/v1, so the host provides one (cache.Extension.Host(scope)).
Configure
On the mothership:
mothership:
serve: true
apex: example.com # <name>.example.com routes to each instance
On each edge, with logins from the private .env:
multisite: {}
mothership:
url: http://10.88.0.10:8090
email: $MOTHERSHIP_EMAIL
password: $MOTHERSHIP_PASSWORD
self: lax-1 # this edge's edge_id (or edges.self)
internal_url: http://10.88.0.5:8080
region: lax
max_hosts: 50000 # hostnames the edge keeps answers for (cache bucket mothership.hosts)
url and self are required on an edge. The edge logs in as a superuser of the mothership.
pocketone.yaml reference
mothership:
A community mothership: serve: true makes this app one; url, login and self make a host follow one.
| Key | Type | Default | Description |
|---|---|---|---|
serve |
bool | This app is the mothership: it serves instance.watch/v1 to its edges (and keeps the edges and instances collections). | |
apex |
string | On the mothership: makes |
|
url |
string | On an edge: the mothership's URL. Required there. | |
email |
string | Superuser email this edge logs in with; use a $VAR from the .env. | |
password |
string | Superuser password; use a $VAR from the .env. | |
self |
string | This edge's edge_id, such as lax-1. Default: the edges section's self. Required on an edge. | |
internal_url |
string | Where other edges reach this one. Set: the edge registers itself when the mothership has no record for it. | |
region |
string | Region recorded when the edge registers itself. | |
heartbeat |
duration | How often this edge marks itself online. Default 15s; negative: never. | |
max_hosts |
int | Most hostnames an edge keeps answers for (its cache bucket mothership.hosts). Default 50000. |
Use
You manage the fleet in the mothership's dashboard, in two collections only superusers can read or write:
edges:edge_id(such aslax-1),internal_url,region,status(online,draining,offline) andlast_seen. An edge withinternal_urlset registers itself when it has no record, and marks itself online every 15 s.instances:name(<name>.<apex>routes to it),hosts(extra hostnames),edge(where it runs),power(off answers 409 "instance is powered off"),suspension(non-empty answers 403 with that message),dev,version,secrets,encryption_key,access,limits,plugins(extension settings; the field keeps its old name) andstatus.
A change reaches every edge that has served the hostname within moments, on its stream; there's no polling and no full
copy. To move an instance, change its edge. An instance with no edge isn't served anywhere; a hostname no instance
has answers 404, and the edge hears when one takes it.
Commands and APIs
Generated from the pocketone binary and the contracts this extension provides.
instance.watch/v1
| Operation | CLI | REST | MCP |
|---|---|---|---|
| stream | pocketone remote instance watch stream --edge <value> |
GET /api/_c/instance.watch/v1/stream |
instance_watch_stream |
| watch | pocketone remote instance watch --conn <value> --edge <value> --host <value> |
POST /api/_c/instance.watch/v1/watch |
instance_watch_watch |
| unwatch | pocketone remote instance watch unwatch --conn <value> --host <value> |
POST /api/_c/instance.watch/v1/unwatch |
instance_watch_unwatch |
Integrations
Works with
| Extension | How they fit |
|---|---|
| Multisite | The client is the host's instance source and lookup: which instance a hostname serves, asked on first use. |
| Edge | The client is also an edge source: where the other edges are, so requests for their instances are forwarded. It combines with a fixed edges list. |
| Cache | The client keeps answers in the host's bucket mothership.hosts (required). |
| Docker and Pocker | Run the instances this edge owns, with the version, secrets, limits and extension settings from each record. |
| Tenants (planned) | Adds owners and accounts by wrapping instance.resolve/v1. |
Building on Mothership
- Your own fields and collections.
EnsureCollectionsleaves fields an extension added alone. - Your own answers. Wrap instance.resolve/v1 (
resolvev1.Contract.Wrap) to adjust what a hostname serves (block a suspended owner's instances, add an owner's trusted IPs), or provide your own over your own collections. List the records an answer read in its deps, and report fromTouchesthe names and keys a write changes. - The standing set.
Standing(edge)lists instances an edge must hold without traffic (work addressed to it); they arrive in the stream's hello and whenever the set changes. - Go API.
client.New(client.Config{...})builds an edge client without the config file;Standing(),EdgeRecords()andSelfRecord()read what the stream sent.
Example
There's no example/main.go yet. The stock binary is both sides: examples/pocketone/binary/binary.go
registers the mothership, and its multi-instance mode, examples/pocketone/binary/multi.go,
follows one; examples/pocketone/mothership_test.go runs a mothership and two edges.
How it works
- One stream per edge (
GET /api/_c/instance.watch/v1/stream?edge=<id>). Its hello carries the connection id, every edge and the edge's standing set. - Lookup on a miss. A hostname the edge's cache doesn't hold is watched on the stream; the mothership registers the watch, then resolves, and sends the answer on the stream. Requests for one hostname share one ask.
- Changes. After every committed write, the mothership resolves again each watch whose deps the record touches, and sends only answers that changed. A cached hostname is updated; one the cache dropped is unwatched.
- Stream down. The edge keeps serving what it cached; a miss is answered in the reply, used once and not cached.
- Reconnect. A new stream is a new generation: the cache key carries it, so everything from before is ignored (and cleared). A mothership restart drops every stream, and every edge starts over.
Edges log in as superusers today, so the edge names itself on the stream; a per-edge credential will carry it instead.
Status
Early. Built: the collections, the watch server, the default resolver and the edge client. Not yet: the mothership's own endpoints (placement, moves), instance status reports, per-edge credentials.
License
MIT
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.