Skip to content

Fix: API DELETE container skips Proxmox deletion#268

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-api-delete-container
Closed

Fix: API DELETE container skips Proxmox deletion#268
Copilot wants to merge 3 commits intomainfrom
copilot/fix-api-delete-container

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

When deleting a container via the JSON API, only the database record was removed — the Proxmox LXC container was left alive. The isApiRequest branch bypassed all Proxmox cleanup logic that existed in the browser form path.

Changes

  • Include Node association in the API path's container query so the Proxmox API client can be constructed
  • Add Proxmox deletion via api.deleteContainer() with force=true, purge=true before DB destroy
  • Add hostname safety check via api.lxcConfig() — returns 409 JSON on mismatch instead of silently skipping or redirecting
// Before
if (isApiRequest(req)) {
  const container = await Container.findByPk(containerId);
  await container.destroy(); // only DB — Proxmox container left running
  return res.status(204).send();
}

// After
if (isApiRequest(req)) {
  const container = await Container.findOne({
    where: { id: containerId },
    include: [{ model: Node, as: 'node' }]
  });
  // hostname mismatch → 409
  await api.deleteContainer(node.name, container.containerId, true, true);
  await container.destroy();
  return res.status(204).send();
}

Copilot AI changed the title [WIP] Fix API to delete Proxmox container correctly Fix: API DELETE container skips Proxmox deletion Mar 31, 2026
Copilot AI requested a review from runleveldev March 31, 2026 17:28
Copy link
Copy Markdown
Collaborator

@runleveldev runleveldev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this is repetitive with code elsewhere in the router. Minimize repetition rather than minimizing changes.

…dler branches

Agent-Logs-Url: https://github.com/mieweb/opensource-server/sessions/8dc9aa4d-8e25-4825-9a0b-feccd0a524a6

Co-authored-by: runleveldev <44057501+runleveldev@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot this is repetitive with code elsewhere in the router. Minimize repetition rather than minimizing changes.

Refactored in d080fc0. Extracted a deleteContainerFromProxmox(container) helper that owns the Proxmox lxcConfig check + deleteContainer call, then unified the two separate API/non-API branches into a single handler. The branches now only diverge where the response format actually differs (JSON vs redirect).

@runleveldev
Copy link
Copy Markdown
Collaborator

Implemented in #269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Deleting via the API does not remove Proxmox container

2 participants