Big picture¶
One binary, several jobs¶
rendimiento is a single Go program (cmd/rendimiento) that does four jobs at once. Each job is a set of goroutines inside the same process:
flowchart TB
subgraph proc[rendimiento process]
direction TB
http[HTTP server :8080<br/>REST API · SSE · webhooks · UI]
subgraph mgr[controller-runtime manager]
appc[App controller]
addc[Addon controller]
end
subgraph leader[started once elected]
worker[CI worker<br/>claims runs from the queue]
reno[Renovate scheduler]
sync[Add-on sync from git]
end
ddns[Dynamic DNS loop]
end
browser([Browser]) --> http
github([GitHub]) -- webhooks --> http
http --> pg[(Postgres)]
worker --> pg
worker -- build pods --> k8s[(Kubernetes API)]
worker -- "buildctl (in pods)" --> bk[BuildKit pool]
appc --> k8s
addc -- impersonating rendimiento-addons --> k8s
sync -- reads --> gitops[(p0dxD/gitops)]
ddns --> cf([Cloudflare])
appc --> cf
| Job | Package | What it does |
|---|---|---|
| API and UI | internal/api |
Serves the React UI (embedded in the binary), the JSON API, live updates over Server-Sent Events, GitHub webhooks, login and the GitHub App setup. |
| Orchestration | internal/platform |
Turns webhooks into CI runs, runs into releases, releases into App objects. Onboarding, rollback, delete and disconnect live here. |
| CI | internal/pipeline |
Plans a run as a graph of steps and runs each step as a pod; builds go to the BuildKit pool. |
| App controller | internal/controller |
Reconciles each App into namespaces, Deployments, Services, Ingresses, volumes, CronJobs, DNS records and status. |
| Add-on controller and sync | internal/controller, internal/addon |
Keeps Addon objects in line with p0dxD/gitops/addons/*.yaml and reconciles each into the objects its Helm chart or manifests describe. |
| Built-in add-ons | internal/renovate |
Renovate runs on a schedule. |
| Views | internal/catalog, internal/environment |
The Services page and the Environment page. |
Services from one binary¶
The same image runs as four Deployments, chosen by the ROLE setting, so a failure stays in one service, with its own logs, health and restarts:
Service (ROLE) |
Deployment | What it runs | Only one active, by |
|---|---|---|---|
api |
rendimiento (2 replicas) |
the UI, the API, webhooks, MCP, the public stats | nothing: every replica serves |
control |
rendimiento-control |
the App and Addon controllers, Renovate, the add-on sync, the uptime prober, release verification, the log archive, dynamic DNS | the leader lease |
worker |
rendimiento-worker |
the CI queue: build and test pods, deploys | the queue's lock in Postgres |
agents |
rendimiento-agents |
the agents inside the platform: the diagnostician explains every failed run through the AI gateway | the agents' lock in Postgres |
traces |
rendimiento-traces |
receives every span from the OpenTelemetry Collector and keeps whole requests for the Universe's waterfall | one replica (a request's spans wait in its memory) |
ROLE=all (the default) runs everything in one process, as on a laptop. The services share nothing but Postgres and Kubernetes:
- live events (log lines, step changes) go through Postgres
LISTEN/NOTIFY(events.Bridge), so a run page served byapifollows a build onworker; - requests go the same way, with an answer:
apiaskscontrolto start a Renovate run or for the last add-on sync, and gets an error at once whencontrolis down instead of a hung page; a cancel reaches the worker running the run; a deploy hands the new release's verification tocontrol; - CI runs are queued in Postgres by
apiand claimed byworker.
The control service and the worker serve only /healthz on their HTTP port; the traces service serves only its receiver (TRACES_LISTEN) and needs no Kubernetes or GitHub. Entorno's Platform services check shows each Deployment's ready pods (setting SERVICES).
Why "started once elected"?¶
Some work must happen exactly once in the cluster: scheduling Renovate, syncing add-ons, reconciling. controller-runtime's leader election guarantees that only one control process does it; its lease is long (60 seconds), because on a busy Raspberry Pi control plane short renewals timed out and killed the process. During an update the old pod hands the lease over as it stops. Claiming CI runs is guarded by the queue's lock in Postgres instead, so the worker needs no lease.
How main.go wires it together¶
cmd/rendimiento/main.go is the composition root: the only place that reads configuration and creates concrete implementations. Everything else receives what it needs as struct fields or interfaces. In order, it:
- reads settings from the environment (all of them);
- opens Postgres, runs migrations, requeues runs interrupted by the last restart;
- creates the controller-runtime manager (Kubernetes client, cache, metrics on
:9090); - picks the DNS provider: Cloudflare if a token is set (and starts dynamic DNS for
DNS_TARGET=auto), otherwisedns.Noop; - builds render options (ingress class, issuer, storage class, the GPU profile) and registers the App controller;
- loads the GitHub App credentials into a
github.Holder(empty until setup); - creates the add-on identity client (impersonating
rendimiento-addons), the renderer and syncer, and registers the Addon controller; - creates the platform, the Kubernetes executor (build namespace, BuildKit pool, Railpack, node exclusions) and the CI runner, and the Renovate runner;
- creates the API server with all of the above;
- starts the manager, what its
ROLEruns (the leader-only loops, the CI worker) and the HTTP server, and waits for a signal or an error.
ns := env("NAMESPACE", "rendimiento-system")
dsn := os.Getenv("DATABASE_URL")
if dsn == "" {
return errors.New("DATABASE_URL is required")
}
// ALLOWED_USERS names the first administrators; then people are
// members, managed on the Members page.
users := strings.FieldsFunc(os.Getenv("ALLOWED_USERS"), func(r rune) bool { return r == ',' || r == ' ' })
st, err := store.Open(ctx, dsn)
if err != nil {
return fmt.Errorf("database: %w", err)
}
defer st.Close()
if err := st.Migrate(ctx); err != nil {
return fmt.Errorf("migrate: %w", err)
}
// The settings tested and changed on the Environment page (Keys and
// settings) win over the ConfigMap's: they go into the environment
// before anything reads it. TESTED_SETTINGS=ignore starts with the
// ConfigMap's alone.
entorno, probadosEnUso, err := probados.AlArrancar(ctx, st, os.Getenv, os.Setenv)
if err != nil {
log.Warn("could not read the tested settings; starting with the ConfigMap's", "err", err)
for k, v := range entorno {
_ = os.Setenv(k, v)
}
} else if len(probadosEnUso) > 0 {
log.Info("tested settings changed on the Environment page win over the ConfigMap's", "settings", strings.Join(probadosEnUso, ", "))
}
baseURL := strings.TrimRight(env("BASE_URL", "http://localhost:8080"), "/")
go central.Run(ctx, st, plain)
// The Problems recorder's own warnings are kept in the log.
go problemLog.Run(ctx, st, slog.New(central.Handler(plain.Handler())))
if n, err := st.SeedAdmins(ctx, users); err != nil {
return fmt.Errorf("members: %w", err)
} else if n > 0 {
log.Info("the first administrators come from ALLOWED_USERS; from now on, manage people on the Members page", "admins", n)
}
if ms, err := st.Members(ctx, store.DefaultOrg); err != nil {
return fmt.Errorf("members: %w", err)
} else if len(ms) == 0 {
// The setup page makes the first administrator: whoever proves the
// setup token and authorizes the forja (internal/api/instalar.go).
if os.Getenv("SETUP_TOKEN") == "" {
return errors.New("nobody can sign in: set ALLOWED_USERS to the first administrators (ana on GitHub, [email protected], [email protected]), or SETUP_TOKEN to install from the setup page")
}
log.Info("no administrators yet: whoever installs from the setup page, with the setup token, becomes the first")
}
The packages, in layers¶
Arrows mean "imports". Lower layers never import higher ones, which keeps each package testable on its own.
flowchart TB
cmd[cmd/rendimiento] --> api
api[internal/api] --> platform & controller & catalog & environment & renovate & addon
platform[internal/platform] --> pipeline & destino & controller & generate & store & github & events & render
destino[internal/destino] --> crd & store
controller[internal/controller] --> render & addon & dns
renovate[internal/renovate] --> store & github
catalog[internal/catalog] --> render
environment[internal/environment] --> github & dns
generate[internal/generate] --> detect & templates[templates]
store[internal/store] --> pipeline
addon[internal/addon] --> github & crd
render[internal/render] --> spec
pipeline[internal/pipeline] --> spec
crd[api/v1alpha1] --> spec[internal/spec]
- At the bottom,
internal/spec(therendimiento.yamltypes) and small leaf packages (dns,detect,events,forja) depend on nothing of ours;githubdepends only onforja. api/v1alpha1defines the custom resources (App,Addon), reusing the spec types so anAppcarries exactly whatrendimiento.yamlsays.renderis pure: spec plus images in, Kubernetes objects out. No I/O, which makes it easy to test with golden files.controllerandpipelinedo the I/O against Kubernetes.platformties CI, the store and the forja together.forjais where an app's code lives, and what rendimiento does there: learn of each push (a webhook, verified and read), clone with a short-lived token, say whether a commit passed (a check, also «a person must merge it»), open and merge changes, and sign people in. The platform, the API's webhook and login, and the coding agent speak to it;githubimplements it (theHolder), and so dogitlabandbitbucket(Bitbucket Cloud), each for the connections made on the Environment page. Connecting a forja stays in its own package, since each one does it its own way: GitHub's App manifest, its installations and Renovate's token are GitHub's.destinois where releases run. The platform asks it to create an app, apply a release, run its deploy tasks, report the rollout and remove the app, and for the app's page, what runs for it, its secrets, a restart, and what deleting or disconnecting it would do; the platform does not know how. Kubernetes is the first destination (it writes theAppobject, which the controller deploys);Localruns them on one computer, as containers of its engine behind a proxy at<app>.localhost(see On one computer); a server over SSH and the clouds are planned.apiis the outermost layer.
Everything under internal/ is private to this module (a Go rule): other projects cannot import it. That keeps us free to change it. If parts should become a public library one day, they would move out of internal/.
Where state lives¶
| What | Where | Why there |
|---|---|---|
| What should run for each app (services, jobs, released images) | App objects in Kubernetes |
Controllers watch them; kubectl can see and fix them; the cluster works without the database. |
| App configuration | rendimiento.yaml in each repo |
GitOps: reviewed, versioned, and changes deploy on merge. |
| Add-on definitions | p0dxD/gitops/addons/*.yaml → Addon objects |
Same reasons, for cluster software. |
| CI runs, steps, logs, releases, sessions, add-on settings and runs | Postgres | Relational history, a work queue, large text (logs). |
| Secrets | Kubernetes Secrets (sealed secrets in git for apps that use them) | Never in git in plain text, never in Postgres. |
More in Data and state.
The UI¶
A React + TypeScript single-page app (web/), built with Vite into web/dist and embedded into the Go binary with //go:embed. There is no separate web server: the binary serves the files and falls back to index.html for client-side routes. See API, auth and the UI.