Skip to content

fix(charm): remove unmanaged tmate containers before restarting the workload - #59

Merged
cbartz merged 2 commits into
mainfrom
fix/remove-unmanaged-tmate-containers
Oct 8, 2026
Merged

cbartz merged 2 commits into
mainfrom
fix/remove-unmanaged-tmate-containers

Conversation

@cbartz

@cbartz cbartz commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Applicable spec: ISD-6336 (follow-up to #58)

Overview

Before (re)starting the workload, remove every container running a ghcr.io/canonical/tmate-ssh-server image, not only the one named in the service unit. Unrelated containers are left alone.

Rationale

Upgrading a 3-unit deployment to the #58 revision left two units in error: a tmate 0.1.1 container started outside the charm (Docker-generated name, up for 4 months) held port 10022, so the new 1.1 container could not bind and ensure_daemon_running timed out. The charm only removed the container named in its unit, which no longer existed. Manually removing the stray container fixed both units immediately.

Juju Events Changes

None. install, update-status and upgrade-charm all go through ensure_daemon_running, so all of them now clear stray tmate containers before restarting.

Module Changes

tmate: new IMAGE_REPOSITORY constant; _pull_image_and_remove_containers lists containers and force-removes those whose image belongs to that repository (any tag or digest), after pulling the image. Unit tests cover unmanaged, digest-pinned and unrelated containers, and listing/removal failures; test_upgrade now starts an unnamed 0.1.1 container on the baseline unit before refreshing. Docs and changelog updated.

Library Changes

None.

Checklist

AI-generated message.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The cleanup behavior is correctly implemented and tested; the remaining diagnostic-message ambiguity is non-blocking.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Removes stray tmate containers before workload restarts to prevent port conflicts during upgrades and recovery.

Changes:

  • Detects and removes containers using any tag or digest from the tmate image repository.
  • Adds unit and integration coverage for cleanup and failure paths.
  • Updates architecture, upgrade, and changelog documentation.
File Description
src/​tmate.py Implements repository-wide tmate container cleanup.
tests/​unit/​test_tmate.py Tests matching, removal, ordering, and failures.
tests/​integration/​test_upgrade.py Verifies unmanaged-container cleanup during refresh.
docs/​reference/​charm-architecture.md Documents restart cleanup behavior.
docs/​how-to/​upgrade.md Updates upgrade expectations.
docs/​changelog.md Records the user-facing fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/tmate.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused implementation matches the stated behavior and includes comprehensive failure-path and integration coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Unused entries in .trivyignore

Image: ghcr.io/canonical/tmate-ssh-server:a0edf8f27d99ca10ec2b3cafa43ffe32feaea597-_1.1_amd64

The following CVEs are in .trivyignore but not ignored by Trivy anymore:

@cbartz
cbartz marked this pull request as ready for review October 7, 2026 13:38
@cbartz
cbartz requested a review from a team as a code owner October 7, 2026 13:38

@florentianayuwono florentianayuwono left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@cbartz
cbartz merged commit 7632487 into main Oct 8, 2026
20 checks passed
@cbartz
cbartz deleted the fix/remove-unmanaged-tmate-containers branch October 8, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants