Repository navigation
feat(api): stop an application - #321
Conversation
An application could not be stopped: its replicas kept running, and kept what they reserve on their node, until it was deployed again. A stop is a deployment whose plan starts nothing. It goes from queued to draining, removes the application's route and every placed replica, and frees their reservation when it succeeds. It needs no image and no free capacity. The application, its releases and its history stay, and deploying or rolling back starts it again. Refs #256 Signed-off-by: samuel mbabhazi <[email protected]>
Refs #256 Signed-off-by: samuel mbabhazi <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
First part of #256 (application lifecycle): stopping an application. Deleting one and the screen follow in their own pull requests.
What changed
An application could not be stopped. Its replicas kept running, and since #313 they also kept what they reserve on their server, so the only way to free room was to deploy something else over them.
DeploymentPlangainsstop; such a deployment goesqueued -> draining -> succeeded. The existingdrainingstage does the work: it removes the application's route on every server that served, then stops and removes every placed replica, whatever its release. Success marks those allocations stopped, which frees their reservation.POST …/applications/{applicationId}/stop(201,deploy.run, session or API token) queues it.application_not_running(409) without a placed replica,deployment_in_progress(409, with the state) while another deployment runs.serving()returns nothing, so any deployment that succeeded can be rolled back to, and deploying starts the application again. The application, its releases and its history stay.20261117090000_deployment_stopaddsdeployments.plan_stop(false for every existing row).stopis a new boolean in every deployment answer;openapi.json, the API client and the route and role matrix are regenerated.RemoveRoute,StopContainerandRemoveContainer, as a normal deployment already sends them for the replicas it replaces.How it was tested
Unit tests written first: the state machine (
queued,draining,succeeded, even when the plan also says build and release), the planner (routes and replicas removed, nothing resolved or placed, with and without domains, a replica that cannot be stopped) and the pipeline worker (reservation freed on success and kept on failure, registry never asked).Integration test with PostgreSQL, the HTTP API and the real pipeline: refusals before anything runs and while a deployment runs, who may stop, the stop to its end, the reservation at zero, the application still there, the audit events, a second stop refused, and a rollback accepted afterwards.
Six mutations, each caught (one needed a tighter assertion first).
On a real agent, starting from the published
v0.1.0-alpha.2(control plane and agent), with one application deployed, then the control plane switched to an image built from this branch:GET …/replicasis emptyapplication_not_runningNo node can run replica 1 of 1 (node12: cpu).The agent stayed at
v0.1.0-alpha.2during all of this, and it applied the limits the new control plane sent (1 CPU, 512 MiB), which fix: give every container a CPU and a memory limit #313 had left untested.Not tested
Security considerations
deploy.run, like deploying and cancelling, and is audited asdeployment.queuedwithplan: stop, then by the pipeline's own events.Found on the way
Prisma writes timestamps as UTC text without an offset, so with a PostgreSQL whose
timezoneis not UTC they are shifted againstnow()and against values written by other clients. The supported installation uses the official image (UTC) and CI too; my local test database did not. I will file it separately.Refs #256
Summary by CodeRabbit