Units API guide
Labels, user data and list filters
Every unit has three inputs you control.
| Input | Rule | When it can change | The unit reads it at |
|---|---|---|---|
key | 1 to 40 chars, DNS-label shape | never | env ZAROZ_UNIT_KEY, /zaroz/unit.json |
labels | at most 16 pairs; key ^[a-z0-9]([a-z0-9_.-]*[a-z0-9])?$ up to 32 chars; value up to 64 characters; whole map under 2 KiB | any time | /zaroz/unit.json (updated live) |
user_data | any JSON, at most 64 KiB, 32 levels deep; null means none | on create, on start of a stopped unit, on allocate; each replaces the old value whole | /zaroz/user-data.json and GET /user-data on the signal socket |
user_data is not a secret store. The console shows it, every read of the unit returns it, and it is part of the cluster object. Keep secrets in the Workload's environment.
Change labels at any time
PATCH .../units/{key} replaces the whole label map. It works in every policy mode and on running units; the unit sees the change in /zaroz/unit.json within about a second.
curl
Code
TypeScript
Code
Python
Code
Find units by label
GET .../units accepts these filters. They combine with AND.
| Parameter | Meaning |
|---|---|
label=key:value | exact match; repeat it for several (at most 8); a value may contain colons |
origin=policy|code|warm | who created the unit |
key_prefix=plot- | keys starting with the text |
include=user_data | add each unit's user_data (omitted by default to keep the page small; GET .../units/{key} always has it) |
include_gone=true | also units scaled away in the last 30 days, so their logs stay reachable |
curl
Code
TypeScript
Code
Python
Code
Labels are the right place for what a matchmaker needs to choose a unit (mode:2v2, region:eu, owner:ana). user_data is the right place for what the unit itself needs to start (a roster, a job, a world location).
Last modified on
