mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 07:41:27 +00:00
* feat(scheduling): multi-node service placement + remote container lifecycle services.node_id pins a service to a node agent: explicit id, "auto" (least-loaded online node), or "local"/empty for the local Docker host. - DeploymentEngine gains a NodeRunner seam; ReconcileService routes pinned services to the agent's command queue (create_container with image/env/command/ports/volumes/labels/resource limits), tracked in container_instances with deterministic per-replica ids. - Stop/start/restart/delete fan out to the pinned node — no more leaked remote containers on service delete. - Agent create_container is idempotent (rm -f first) and honors restart policy, labels, memory/cpus, published+ephemeral ports, volumes, env. - GET /nodes/options exposes id/name/status to authed users; full agent management stays admin-only. - CLI services create/update --node, MCP node_id docs, OpenAPI node_id/node_name + /nodes/options, service-detail Placement section. Ceilings: remote nodes run registry-pulled images only — git builds, Traefik domains, and remote sleep detection stay local until build-on-node and per-node ingress land. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * feat(scheduling): node cordon/drain + schedulable gate - node_agents.schedulable column; "auto" placement and explicit pins skip cordoned nodes; already-pinned services keep running (reconcile is unaffected — cordon is not eviction). - POST /agents/:id/cordon|uncordon|drain (admin). Drain cordons, removes every service container via the agent queue, and clears the services' pins so they redeploy on the local host. Requires the node online — an offline node can't acknowledge removals. - CLI nodes cordon|uncordon|drain (drain confirm-gated), MCP containr_nodes_cordon|uncordon|drain, OpenAPI paths + schedulable field, node-detail page cordon badge + drain/cordon controls. - Fix: re-registering an agent no longer resets auto_prune. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * feat(scheduling): remote registry pulls + post-run health check - Dispatch payload carries the project owner's registry credentials for the image host; the agent docker-logins for the pull and logs out after, so private images deploy to remote nodes. - Completed command payloads get their registry password scrubbed — secrets don't linger in agent_commands rows. - Agent verifies the container is still running ~1.5s after docker run; crash-loops now fail the deployment with the container's last log lines instead of reporting "running" optimistically. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
151 lines
4.1 KiB
SQL
151 lines
4.1 KiB
SQL
-- name: GetAgentByHostAndIP :one
|
|
SELECT * FROM node_agents
|
|
WHERE hostname = $1 AND ip_address = $2
|
|
LIMIT 1;
|
|
|
|
-- name: GetAgent :one
|
|
SELECT * FROM node_agents WHERE id = $1;
|
|
|
|
-- name: ListAgents :many
|
|
SELECT * FROM node_agents ORDER BY created_at ASC;
|
|
|
|
-- name: CreateAgent :one
|
|
INSERT INTO node_agents (
|
|
id, name, hostname, ip_address, port, status, version,
|
|
capabilities, resources, last_heartbeat, metadata
|
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
|
RETURNING *;
|
|
|
|
-- name: UpdateAgent :one
|
|
UPDATE node_agents SET
|
|
name = $2,
|
|
hostname = $3,
|
|
ip_address = $4,
|
|
port = $5,
|
|
status = $6,
|
|
version = $7,
|
|
capabilities = $8,
|
|
resources = $9,
|
|
last_heartbeat = $10,
|
|
metadata = $11,
|
|
auto_prune = $12,
|
|
schedulable = $13,
|
|
updated_at = NOW()
|
|
WHERE id = $1
|
|
RETURNING *;
|
|
|
|
-- name: UpdateAgentHeartbeat :exec
|
|
UPDATE node_agents SET
|
|
status = $2,
|
|
resources = $3,
|
|
last_heartbeat = $4,
|
|
updated_at = NOW()
|
|
WHERE id = $1;
|
|
|
|
-- name: DeleteAgent :exec
|
|
DELETE FROM node_agents WHERE id = $1;
|
|
|
|
-- name: InsertAgentHeartbeat :exec
|
|
INSERT INTO agent_heartbeats (
|
|
id, node_agent_id, timestamp, status, resources,
|
|
container_count, system_load, uptime, version
|
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
|
|
|
|
-- name: ListAgentHeartbeatsSince :many
|
|
SELECT * FROM agent_heartbeats
|
|
WHERE node_agent_id = $1 AND timestamp >= $2
|
|
ORDER BY timestamp ASC;
|
|
|
|
-- name: ListPendingCommands :many
|
|
SELECT * FROM agent_commands
|
|
WHERE node_agent_id = $1 AND status = 'pending'
|
|
ORDER BY created_at ASC
|
|
LIMIT 25;
|
|
|
|
-- name: ListCommandsForAgent :many
|
|
SELECT * FROM agent_commands
|
|
WHERE node_agent_id = $1
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: GetCommandForAgent :one
|
|
SELECT * FROM agent_commands
|
|
WHERE id = $1 AND node_agent_id = $2;
|
|
|
|
-- name: CreateCommand :one
|
|
INSERT INTO agent_commands (
|
|
id, type, node_agent_id, container_id, payload, status
|
|
) VALUES ($1, $2, $3, $4, $5, 'pending')
|
|
RETURNING *;
|
|
|
|
-- name: CompleteCommand :one
|
|
UPDATE agent_commands SET
|
|
status = $3,
|
|
result = $4,
|
|
error = $5,
|
|
completed_at = NOW(),
|
|
updated_at = NOW()
|
|
WHERE id = $1 AND node_agent_id = $2
|
|
RETURNING *;
|
|
|
|
-- name: ListContainersForAgent :many
|
|
SELECT * FROM container_instances
|
|
WHERE node_agent_id = $1;
|
|
|
|
-- name: GetContainerForAgent :one
|
|
SELECT * FROM container_instances
|
|
WHERE id = $1 AND node_agent_id = $2;
|
|
|
|
-- name: GetContainer :one
|
|
SELECT * FROM container_instances WHERE id = $1;
|
|
|
|
-- name: CreateContainer :one
|
|
INSERT INTO container_instances (
|
|
id, name, image, project_id, service_id, node_agent_id,
|
|
status, resources, ports, environment, volumes, networks,
|
|
restart_policy, health_check
|
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
|
|
RETURNING *;
|
|
|
|
-- name: UpdateContainerStatus :exec
|
|
UPDATE container_instances SET status = $2, updated_at = NOW()
|
|
WHERE id = $1;
|
|
|
|
-- name: GetLastAgentCommandByType :one
|
|
SELECT * FROM agent_commands
|
|
WHERE node_agent_id = $1 AND type = $2
|
|
ORDER BY created_at DESC LIMIT 1;
|
|
|
|
-- name: PickLeastLoadedAgent :one
|
|
SELECT a.id FROM node_agents a
|
|
LEFT JOIN LATERAL (
|
|
SELECT h.container_count FROM agent_heartbeats h
|
|
WHERE h.node_agent_id = a.id
|
|
ORDER BY h.timestamp DESC LIMIT 1
|
|
) h ON true
|
|
WHERE a.status = 'online' AND a.schedulable
|
|
ORDER BY COALESCE(h.container_count, 0) ASC, a.created_at ASC
|
|
LIMIT 1;
|
|
|
|
-- name: SetAgentSchedulable :exec
|
|
UPDATE node_agents SET schedulable = $2, updated_at = NOW() WHERE id = $1;
|
|
|
|
-- name: ClearServiceNodePins :execrows
|
|
UPDATE services SET node_id = NULL, updated_at = NOW() WHERE node_id = $1;
|
|
|
|
-- name: UpsertServiceContainer :exec
|
|
INSERT INTO container_instances (
|
|
id, name, image, project_id, service_id, node_agent_id,
|
|
status, resources, ports, environment, volumes, networks,
|
|
restart_policy, health_check
|
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
|
|
ON CONFLICT (id) DO UPDATE SET
|
|
image = EXCLUDED.image,
|
|
status = EXCLUDED.status,
|
|
updated_at = NOW();
|
|
|
|
-- name: DeleteServiceContainersOnAgent :exec
|
|
DELETE FROM container_instances WHERE node_agent_id = $1 AND service_id = $2;
|
|
|
|
-- name: ScrubCommandPayload :exec
|
|
UPDATE agent_commands SET payload = $2, updated_at = NOW() WHERE id = $1;
|