The operator's controller in TypeScript¶
The operator (operator.md) leaves ansible-operator: its controller, the part that watches
resources, decides, sequences, records and logs, becomes TypeScript on Bun, talking to the Kubernetes API with fetch.
Its actions stay Ansible: the playbooks an admin runs by hand too. Decided on 2026-11-19, after the operations model's
second phase (the operator reads its cluster's repository, moves itself to the ethere it pins); live on dampetra on
2026-11-24, deployed by Flux (operator.md). What follows is the design as written before the
work, with what the work changed (below, and its decisions).
Why¶
ansible-operator runs one playbook per event and nothing else. Everything a controller does around it was written in
Ansible: reading the resource again (operator/_runner.yml), the steps of a reconciliation and its account
(operator/reconcile.yml), the revision of the cluster's configuration, the moves to another ethere
(operator/_upgrade.yml). Program logic in Jinja: unreadable, testable on a test cloud only, its logs a stream of
task lines rather than events. Ansible is right for acting on servers and clouds; it is wrong for a control loop.
A spike, 2026-11-19¶
A real API on the workstation (the aio image's kube-apiserver 1.36.5 and etcd 3.6.15, through the image's
loader; a CA of its own, client certificates), a trial controller under Bun 1.4.2:
@kubernetes/client-node2.0.2, rejected. Its typed models drop the keys they don't know, silently (x-kubernetes-preserve-unknown-fieldsvanished from a CRD); it serializes a Lease'sMicroTimewith 3 decimals, which the API refuses; under Bun, its CA and client certificate (anhttps.Agent) are ignored; its informer stops for good on a network error.dot-i/k8s-operator-node(a layer over it, no release since March 2025) neither.fetchalone, kept. Bun'sfetchtakestls: {ca, cert, key}: the service account and the playbooks' admin certificates alike. Server-side apply sends objects as written. A client, a watch and an informer in 127 lines; the controller around it passed: the API down 40 s, a compaction (the 410, a relist), a second instance taking over the Lease, the API frozen 150 s (a silent watch broken by the inactivity timeout).- Its lessons: a timeout on every request but the watch (frozen, 28 Lease renewals piled up); a leader steps down by itself when it can't renew before its Lease expires (a frozen leader and its successor would both act); the Lease loop never overlaps itself; the watch's inactivity timeout above the bookmarks' interval (about a minute).
- IPv6: Bun 1.4.2 checks an IPv6 literal's certificate with its brackets (
[::1]against the certificate's::1: refused);tls.serverNameset to the address without them fixes it (the cluster's API is an IPv6 anycast address). Bun 1.4.4 checks it right; theserverNamekept (harmless). - Ed25519 (2026-11-21, the first cluster run): Bun before 1.4.4 offered no Ed25519 among its TLS 1.3 signature
algorithms (oven-sh/bun#44618, in 1.4.4): an Ed25519 server key, ethere's PKI's, failed every handshake ("self
signed certificate in certificate chain", "unknown certificate verification error") while a P-256 key passed. Bun
pinned (the shell's
profile.d/20bun.sh, the image'sdev-node/bun-bin: 1.4.5 since); the local API's PKI is Ed25519 since, like the cluster's. - In the image: Bun and a
bun build --compiled executable (81 MB, the runtime inside) run on the operator image's libraries (its glibc,/lib64/ld-linux-x86-64.so.2). - The distribution's Node 22 has no TypeScript: Bun, which
etherectland the tests use already.
The spike's code: poc/operator-ts/ (its kube.ts, the first step's starting point).
What stays, what goes¶
Stays: the custom resources and their schemas; the action playbooks (provisioning/rotate.yml and what it
runs, k8s/configure.yml, k8s/kubeconfig.yml, git/restore.yml, capi/cluster.yml, capi/config.yml,
capi/machine.yml, capi/controlplane.yml), run as an admin runs them; the image (ethere, its Python environment,
the collections, the charts), the controller added; operator/deploy.yml and operator/credentials.yml (the
admin's); the Secret operator-cluster-revision and the moves' semantics (phases 1 and 2).
Goes: ansible-operator (its binary, watches.yaml, operator_watches as its configuration), operator/_runner.yml,
operator/reconcile.yml's sequencing, operator/_upgrade.yml, libexec/cluster-revision.py and
libexec/operator-upgrade.py (their logic in the controller), the filter playbook_summary. libexec/flux_artifact.py
stays for the documentation's server.
Its shape¶
One process: a bundle (bun build --target=bun, its dependencies inside, 270 kB) the image's Bun runs, Bun an
Exherbo package of ethere's (dev-node/bun-bin: the release binary, its SHA256 checked, glibc only; the bundle made
by that same binary; the shell's Bun the same version, a unit test says so). Its sources under operator/ (not
lib/: etherectl's, which acts on the workstation only):
| Module | What it does |
|---|---|
kube.ts |
The API: TLS (the service account, or a kubeconfig's certificates), JSON requests with a timeout, server-side apply, merge patches; the watch (bookmarks, inactivity timeout); the informer (list then watch, its cache, a 410 relists, backoff). |
leader.ts |
A Lease, renewed one renewal at a time; no new reconciliation unless its own last renewal is younger than the Lease's duration (below: Robustness). |
queue.ts |
One entry per resource, never two reconciliations of the same one, a concurrency per kind, retries with backoff, a period per kind (the reconciliation without an event). |
playbook.ts |
An action playbook run as an admin runs it (the environment of the accepted revision, the inventories, the cluster's variables), its events read from a callback of ours (below), its whole output kept in a file. |
revision.ts |
The cluster's configuration: the GitRepository's artifact, the accepted revision in its Secret, extracted per revision (phase 1). |
upgrade.ts |
(Not written: Flux deploys the operator at the ethere the repository pins, operator.md.) |
kinds/*.ts |
Each kind's reconciliation (below). |
log.ts |
One JSON line per event (below). |
main.ts |
The commands: run (the controller), reconcile <kind> <name> [--checkout] (one reconciliation, in the foreground: the tests'; with --checkout, an admin's takeover on its checkout: etherectl operator reconcile). |
What ansible-operator did implicitly, kept: the finalizer's name (<group>/ethere, on EthereMachine: the
resources carrying it would never go otherwise), added before the first run, the playbook run with
ethere_state=absent on deletion, then removed; a failed run run again with backoff; no status of its own
(manageStatus: false today: no status.conditions written, none read; the CAPI conditions the tests read are
CAPI's objects'). Every kind but the templates has the status subresource: metadata.generation moves with the spec
alone.
The health endpoint stays (operator_ports.health); ansible-operator's proxy goes.
Each kind¶
| Kind | Runs again on | Period | At once | What a reconciliation does |
|---|---|---|---|---|
EthereOperations |
spec, deletion | 30 min | 1 | its revision refreshed; a move to another ethere, or: the PKI's repository restored, the admin kubeconfig, each image's rotation (this region, the cloud's others), k8s/configure.yml; its account in status.lastReconcile |
EthereCluster |
spec, annotations | 30 min | 1 | capi/cluster.yml |
EthereConfig |
spec, owners, annotations | 5 min | 4 | capi/config.yml, unless idle |
EthereMachine |
spec, owners, annotations, deletion (a finalizer) | 1 min | 8 | capi/machine.yml (ethere_state=absent before the resource goes), unless idle |
EthereControlPlane |
spec | 1 min | 1 | capi/controlplane.yml |
"Spec" is a new metadata.generation: its own status writes trigger nothing. "Idle" is today's _runner.yml rule,
in TypeScript: an EthereMachine or EthereConfig without a Machine owner, paused, or already provisioned has
nothing to run (a nested playbook costs 10 to 20 s each minute). EthereOperations' sequence is today's
operator/reconcile.yml, each step a playbook, its account the same schema (etherectl operator status unchanged).
The CAPI playbooks keep their decisions for now; moving them to TypeScript (which Machine next, the control plane's one step) is later work, playbook by playbook, Ansible left with what acts on servers and clouds.
The external mode (docs/dev/cluster-api.md): the controller's objects on a management cluster, in a namespace
per cluster (operator_namespace), with its service account; the playbooks reach the cluster it manages by the API's
public name; no Flux of its own there: no revision refreshed (the seeded one), no move. The standalone cluster
(the qemu provider): the playbooks' qemu_host_command as today, nothing of the controller's.
A commit applied at once: the controller watches the GitRepository cluster too (its artifact's revision): a
new one triggers EthereOperations (its revision refreshed, applied) instead of waiting for the 30 minutes' period.
Its Role in Flux's namespace gains list and watch.
Running a playbook¶
ansible-playbook <playbook> in the accepted revision's directory, the environment an admin's shell gives
(ETHERE_CLUSTER_ROOT_DIR, the inventories, SOPS_CONFIG and AWS_CONFIG_FILE when the revision has them), the
cluster's variables (vars.json) and the resource's spec as extra variables: what _runner.yml does today, as code.
Its events through a callback plugin of ours (plugins/callback/ethere_events.py): one JSON line per task result
(play, task, host, ok/changed/failed/skipped, duration, the failure's message) to a file descriptor the
controller reads. The summary comes from them, not from parsing the output (playbook_summary's job today). The
whole output goes to /run/ethere-operator/runs/<reconciliation>/<step>.log; the last runs kept (a few per kind,
a size cap: /run/ethere-operator is the pod's memory), a failed one's tail in the log. A task's no_log holds: its
message reaches neither the events, the log nor the status (a test).
Logs¶
One JSON line per event on stdout:
{"t":"…","event":"reconcile-start","kind":"EthereOperations","name":"dampetra","n":42,"why":"period","revision":"main@sha1:7d55cab"}
{"t":"…","event":"step","n":42,"step":"provisioning/rotate.yml GRA9 ethere-dns-secondary","result":"ok","changed":[],"seconds":12}
{"t":"…","event":"step","n":42,"step":"k8s/configure.yml","result":"ok","changed":["The Gateway","ethere's pages in kube-public"],"seconds":48}
{"t":"…","event":"reconcile-end","n":42,"result":"Succeeded","seconds":62}
and the controller's own: leader, leadership-lost, informer-*, revision-accepted, revision-waiting,
move-*. etherectl operator logs renders them (one line each, failures with their message), --json as they are.
Robustness¶
Every request but the watch has a timeout. The Deployment stays one replica with Recreate: the Lease guards a pod
left behind (its node unreachable, the pod not yet gone), not a scale-out, so its duration is sized against the API's
outages, not a failover's speed: the operator's own playbooks replace control plane servers, during which the API may
be unreachable for minutes. Losing leadership stops new reconciliations, not a running playbook (stopping one in the
middle of a server's replacement would do more harm than the rare overlap with a pod left behind on a partitioned
node, which reaches no API either; the playbooks are idempotent). A playbook stopped (SIGTERM, after the pod's grace
period) is stopped with its whole process group.
Tests¶
- Unit (
bun test, the default tier):kube.ts, the queue, the leader, the idle rule, the revision, the logs, against a fake API (Bun.serve, astests/operator/revision.test.jsdoes) and fake playbooks. - Integration (
tests/operator/, opt-in): the spike's real API (the aio image'skube-apiserverandetcd), the controller run as a process: its scenarios (the API down, a 410, a second instance, the API frozen) and a reconciliation running a real playbook (a trivial one). - Cluster (
tests/cluster/): the suitesoperator,capi,externalandreconcileunchanged, the new controller in the operator's image.
Steps¶
- The core:
kube.ts,leader.ts,queue.ts,log.ts, their unit tests, the integration harness. EthereOperationswithplaybook.ts,revision.ts,upgrade.tsand the callback; the image without ansible-operator; theoperatorandreconcilesuites.- The CAPI kinds; the
capiandexternalsuites. etherectl operator logson the new events; the old code gone (_runner.yml, the Python scripts, the filter).- The rollout, its first automatic move in production (below); the operations model's phase 3 resumes after.
The move from the Ansible operator¶
dampetra's operator (ethere 1cfb32e) moves itself to a ref whose images are published: a Job of the new image,
the old operator's pod (operator/_upgrade.yml), its command <ethere>/.venv/bin/python -I
<ethere>/libexec/operator-upgrade.py. Two ways:
- Automatic (proposed): the TypeScript version keeps a
libexec/operator-upgrade.pyof a few lines that runs itsupgradecommand; the ref committed, its images published, the old operator moves to the new one by itself: the moves' first real run in production. The shim goes in the version after. - By hand: the operator scaled to 0 before
registry/release.yml(otherwise its Job races the admin), thenoperator/deploy.yml.
Either way the new contract is the TypeScript one's from then on: the Job's command one stable path
(<operator_dir>/bin/ethere-operator upgrade), the pod the old operator's.
What the work changed (2026-11-20 to 11-24)¶
- Deployed by Flux, not moved by a Job: ethere's chart
charts/ethere-operator, a cluster's platform (charts/ethere-platform, copied into its repository) releasing it at the pinned ref. Noupgrade.ts; the move from the Ansible operator was by hand (scaled to 0 before the repository pinned the new ref, thenoperator/deploy.yml, then the platform). - Bun an Exherbo package (
dev-node/bun-bin, its archive's SHA256 checked), the controller a bundle it runs, rather thanbun build --compilewith the workstation's Bun (asdf's download, checked by nothing). 1.4.4 at least: Bun before it offered no Ed25519 among its TLS 1.3 signature algorithms (oven-sh/bun#44618), ethere's PKI's keys. Bun from its sources (Zig, its LLVM, its WebKit) maybe later, on the build cluster. - What the cluster runs showed, and the tests now catch before it:
tarandfindmissing from the image (the image's chroot test,tests/images/root/operator.test.js); an owner added must run a kind at once (capi/cluster.yml waits for its Cluster: the EthereCluster sat until its period); a kubeconfig's credential plugin andtls-server-name(the admin's takeover through an edge). - An admin's takeover (
etherectl operator reconcile): the controller on the admin's checkout (CheckoutRevision), its specoperator.yaml's and the admin's-e, not the resource's (the pod's edge). - The integration tier's API: the aio image's chroot (kept), its PKI in Ed25519 like the cluster's.
Open questions¶
- A running playbook not stopped on a lost leadership (above).
- The Lease against the API's outages, measured in production.