Pilot Metadata Config Patches
A plan to replace fixed config blocks in instance metadata with three generic JSON patches, applied one time at bootstrap. Plan Agreed
The situation
Pilot manages Frappe benches on a host. When a new VM starts from an image, Pilot reads its first settings from instance metadata. Instance metadata is a small key-value service that the cloud makes available inside the VM at 169.254.169.254. Each key is an attribute.
Today Pilot reads three fixed attributes. Each one has its own required keys, its own parser and its own write function.
| Attribute | Content | Written to |
|---|---|---|
pilot-central | Central endpoint, token, JWKS URL and audience | common_config.toml |
pilot-storage | Six fixed S3 keys | bench.toml [s3] |
pilot-telemetry | Endpoint and token | [telemetry] |
To deliver one more setting, a developer must add a key list, a parser, a write function and a docs change. Also, the cloud limits each attribute value to 1 KiB.
Before: one custom code path for each attribute.
The idea
Deliver settings as patches. A patch is a JSON object that names only the keys to change. Central writes one attribute for each config file. Pilot merges each attribute into its file one time, when the host bootstraps.
| Attribute | Target file | Scope |
|---|---|---|
pilot-common-config | common_config.toml | All benches on the host |
pilot-config | bench.toml | One bench |
pilot-common-site-config | sites/common_site_config.json | All sites of one bench (Frappe reads it) |
The value of each attribute is the patch itself. There is no envelope and no version field.
pilot-common-config {"telemetry": {"endpoint": "https://...", "token": "..."}}
pilot-config {"s3": {"bucket": "...", "region": "..."}}
pilot-common-site-config {"max_file_size": 104857600}
After: one merge step. Each attribute has one target file. The Central credential stays structured.
How a patch merges
Pilot uses JSON Merge Patch (RFC 7396). It is a published standard, so Pilot does not invent its own rules. The rules are:
- An object merges into the object at the same key. The merge is recursive.
- A scalar or an array replaces the old value.
nulldeletes the key.
Example. The file has {"s3": {"bucket": "a", "region": "x"}}. The patch is {"s3": {"bucket": "b"}}. The result is {"s3": {"bucket": "b", "region": "x"}}.
A patch changes only the keys that it names. Settings that a user adds, for example mail settings, stay. If Pilot applies the same patch two times, the result does not change. Thus a retry after a partial failure is safe.
When it runs
Pilot reads the config attributes one time, during bootstrap, before it marks the host as bootstrapped. After bootstrap, Pilot does not read them again. pilot setup central --rebootstrap clears the bootstrap flag, so it applies the credential and the patches again.
We examined later updates through metadata (revision numbers, content hashes, polling) and rejected them for now. A host usually gets its settings only one time, and a one-time apply cannot lose an update or revert a user change.
Rules for Central
- Write the config attributes before
pilot-central. Pilot bootstraps whenpilot-centralappears, and it reads the other attributes only at that time. An attribute that arrives later is not applied. - Keep each value under 1 KiB. S3 and telemetry are in different attributes, so each one fits.
Safety rules
- Locks. Each file uses the lock and atomic write that Pilot already uses for that file. A CLI call, an Admin request and a task worker can change the same bench at the same time.
- Validation. Pilot checks the shape of all three patches and rejects unknown TOML keys before it writes a file. A spelling mistake does not disappear silently. Pilot validates the merged config before each write. External URLs get the same checks as before.
- Failure. A bad patch stops the bootstrap with an error. The bootstrap watcher tries again. The host does not show as bootstrapped with a half-applied config.
- Trust. Only the cloud can write instance metadata, and it already delivers credentials. Thus every key is writable. The validation is the limit.
Breaking change
This change is not backward compatible. Pilot no longer reads pilot-storage or pilot-telemetry. Central sends S3 settings in pilot-config and telemetry in pilot-common-config. pilot-central does not change.
Limits
- The bench services can already run when bootstrap applies the patches. A value that a service reads only at start, for example the number of gunicorn workers, has an effect after the next restart. This is the same as the S3 and telemetry behavior before this change.
- Per-site
site_config.jsonis not a target in this version.
Next steps
- Add a raw, validated read-modify-write mode for
common_config.toml, with a schema for unknown keys. - Add the merge code and read the three attributes during bootstrap.
- Remove the
pilot-storageandpilot-telemetrycode. - Add tests: merge rules, each target, unknown keys, user settings that stay, retry after failure.
- Update the configuration docs.