← Back to issue list

`charmcraft clean` does not clean all platforms for charm

View original Github issue

Metadata

Project
charmcraft
Number
#2078
Type
issue
State
open
Author
carlcsaposs-canonical
Labels
Created
Updated
Closed

Current evaluation

charmcraft clean only removes LXC containers for platforms currently listed in charmcraft.yaml, leaving stale containers for removed platforms. Reported with repro steps; linked to issue #1338 in Jan 2025, no further activity.

Suggested action: needs triage

Reason: The issue has a clear reproduction and was acknowledged by a maintainer (sed-i) linking related issue #1338, but no labels, assignee, or resolution have been applied. The clean_instances behavior in craft-application's provider service still cleans per-platform instances, so the bug likely persists. Needs triage to determine if this is intended behavior or a bug to fix.

Impact: 35 Quick Win: 21.0 Staleness: 70 Complexity: 40 Confidence: 75 Support Request: 0

Issue body

### Bug Description Running `charmcraft clean` only cleans LXC containers for platforms in `platforms` ### Expected behavior Running `charmcraft clean` cleans all LXC containers for a charm, regardless of whether they are in `platforms` ### To Reproduce ``` git clone https://github.com/canonical/pgbouncer-operator/ cd pgbouncer-operator git checkout 3c44f02b8474d320c688c22d51773974dd218c02 charmcraft pack -v lxc --project charmcraft ls # Remove ubuntu@20.04:amd64: platform from charmcraft.yaml charmcraft clean -v lxc --project charmcraft ls ``` output of `lxc --project charmcraft ls` before & after clean before ``` +---------------------------------------------------------------+---------+------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +---------------------------------------------------------------+---------+------+------+-----------+-----------+ | base-instance-charmcraft-buildd-base-v7--20d64a5acd5c317c9c8d | STOPPED | | | CONTAINER | 0 | +---------------------------------------------------------------+---------+------+------+-----------+-----------+ | base-instance-charmcraft-buildd-base-v7--910533fdd664bd2cdbe9 | STOPPED | | | CONTAINER | 0 | +---------------------------------------------------------------+---------+------+------+-----------+-----------+ | charmcraft-pgbouncer-ubuntu-2004-amd64-4-4ae2411f5977f7237881 | STOPPED | | | CONTAINER | 0 | +---------------------------------------------------------------+---------+------+------+-----------+-----------+ | charmcraft-pgbouncer-ubuntu-2204-amd64-4-5841bc8b73f9e57f49d3 | STOPPED | | | CONTAINER | 0 | +---------------------------------------------------------------+---------+------+------+-----------+-----------+ ``` after ``` +---------------------------------------------------------------+---------+------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +---------------------------------------------------------------+---------+------+------+-----------+-----------+ | base-instance-charmcraft-buildd-base-v7--20d64a5acd5c317c9c8d | STOPPED | | | CONTAINER | 0 | +---------------------------------------------------------------+---------+------+------+-----------+-----------+ | base-instance-charmcraft-buildd-base-v7--910533fdd664bd2cdbe9 | STOPPED | | | CONTAINER | 0 | +---------------------------------------------------------------+---------+------+------+-----------+-----------+ | charmcraft-pgbouncer-ubuntu-2004-amd64-4-4ae2411f5977f7237881 | STOPPED | | | CONTAINER | 0 | +---------------------------------------------------------------+---------+------+------+-----------+-----------+ ``` ### Environment Ubuntu 22.04 ``` $ snap list Name Version Rev Tracking Publisher Notes charmcraft 3.2.2.post144+gf65ecc0e 5761 latest/edge canonical✓ classic core18 20240920 2846 latest/stable canonical✓ base core20 20240911 2434 latest/stable canonical✓ base core22 20241119 1722 latest/stable canonical✓ base core24 20240920 609 latest/stable canonical✓ base juju 3.6.1 29241 3/stable canonical✓ - lxd 5.0.4-497fe1e 31333 5.0/stable/… canonical✓ - microk8s v1.29.11 7435 1.29-strict/stable canonical✓ - rustup 1.27.1 1471 latest/stable canonical✓ classic snapcraft 8.5.1 13181 latest/stable canonical✓ classic snapd 2.67 23545 latest/stable canonical✓ snapd ``` ### charmcraft.yaml ```yaml # Copyright 2022 Canonical Ltd. # See LICENSE file for licensing details. type: charm platforms: ubuntu@20.04:amd64: ubuntu@20.04:arm64: ubuntu@22.04:amd64: ubuntu@22.04:arm64: # Files implicitly created by charmcraft without a part: # - dispatch (https://github.com/canonical/charmcraft/pull/1898) # - manifest.yaml # (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L259) # Files implicitly copied/"primed" by charmcraft without a part: # - actions.yaml, config.yaml, metadata.yaml # (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L290-L293 # https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L156-L157) parts: # "poetry-deps" part name is a magic constant # https://github.com/canonical/craft-parts/pull/901 poetry-deps: plugin: nil build-packages: - curl override-build: | # Use environment variable instead of `--break-system-packages` to avoid failing on older # versions of pip that do not recognize `--break-system-packages` # `--user` needed (in addition to `--break-system-packages`) for Ubuntu >=24.04 PIP_BREAK_SYSTEM_PACKAGES=true python3 -m pip install --user --upgrade pip==24.3.1 # renovate: charmcraft-pip-latest # Use uv to install poetry so that a newer version of Python can be installed if needed by poetry curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.5.15/uv-installer.sh | sh # renovate: charmcraft-uv-latest # poetry 2.0.0 requires Python >=3.9 if ! "$HOME/.local/bin/uv" python find '>=3.9' then # Use first Python version that is >=3.9 and available in an Ubuntu LTS # (to reduce the number of Python versions we use) "$HOME/.local/bin/uv" python install 3.10.12 # renovate: charmcraft-python-ubuntu-22.04 fi "$HOME/.local/bin/uv" tool install --no-python-downloads --python '>=3.9' poetry==2.0.0 --with poetry-plugin-export==1.8.0 # renovate: charmcraft-poetry-latest ln -sf "$HOME/.local/bin/poetry" /usr/local/bin/poetry # "charm-poetry" part name is arbitrary; use for consistency # Avoid using "charm" part name since that has special meaning to charmcraft charm-poetry: # By default, the `poetry` plugin creates/primes these directories: # - lib, src # (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/parts/plugins/_poetry.py#L76-L78) # - venv # (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/parts/plugins/_poetry.py#L95 # https://github.com/canonical/craft-parts/blob/afb0d652eb330b6aaad4f40fbd6e5357d358de47/craft_parts/plugins/base.py#L270) plugin: poetry source: . after: - poetry-deps poetry-export-extra-args: ['--only', 'main,charm-libs'] build-packages: - libffi-dev # Needed to build Python dependencies with Rust from source - libssl-dev # Needed to build Python dependencies with Rust from source - pkg-config # Needed to build Python dependencies with Rust from source - libpq-dev override-build: | # Workaround for https://github.com/canonical/charmcraft/issues/2068 # rustup used to install rustc and cargo, which are needed to build Python dependencies with Rust from source if [[ "$CRAFT_PLATFORM" == ubuntu@20.04:* || "$CRAFT_PLATFORM" == ubuntu@22.04:* ]] then snap install rustup --classic else apt-get install rustup -y fi # If Ubuntu version < 24.04, rustup was installed from snap instead of from the Ubuntu # archive—which means the rustup version could be updated at any time. Print rustup version # to build log to make changes to the snap's rustup version easier to track rustup --version # rpds-py (Python package) >=0.19.0 requires rustc >=1.76, which is not available in the # Ubuntu 22.04 archive. Install rustc and cargo using rustup instead of the Ubuntu archive rustup set profile minimal rustup default 1.83.0 # renovate: charmcraft-rust-latest craftctl default # Include requirements.txt in *.charm artifact for easier debugging cp requirements.txt "$CRAFT_PART_INSTALL/requirements.txt" # "files" part name is arbitrary; use for consistency files: plugin: dump source: . prime: - LICENSE - templates libpq: build-packages: - libpq-dev plugin: dump source: /usr/lib/ source-type: local prime: - lib/ organize: "*-linux-gnu/libpq.so*": lib/ ``` ### Relevant log output ```shell N/A ```

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.8-27b
Impact: 35
Quick Win: 21.0
Staleness: 70
Complexity: 40
Confidence: 75
Support Request: 0
needs triage charmcraft clean only removes LXC containers for platforms currently listed in charmcraft.yaml, leaving stale containers for removed platforms. Reported with repro steps; linked to issue #1338 in Jan 2025, no further activity.
qwen/qwen3.6-35b-a3b
Staleness: 85
Complexity: 45
Confidence: 85
Support Request: 10
needs triage charmcraft clean fails to remove LXC containers for platforms removed from charmcraft.yaml. Issue is open, unlabelled, and inactive for over 340 days.
qwen3.6-35b-a3b-mtp-q6
Staleness: 90
Complexity: 45
Confidence: 85
Support Request: 10
needs triage charmcraft clean fails to remove LXC containers for platforms removed from charmcraft.yaml. Unlabelled, inactive for over a year, awaiting triage.
qwen3.6-35b-a3b-mtp-q6
Staleness: 75
Complexity: 45
Confidence: 60
Support Request: 10
needs triage charmcraft clean fails to remove LXC containers for platforms removed from charmcraft.yaml. Unlabelled, awaiting maintainer triage after ~10 months of inactivity.
qwen3.6-35b-a3b-mtp-q6
Staleness: 90
Complexity: 40
Confidence: 85
Support Request: 5
needs triage charmcraft clean only removes LXC containers for platforms in charmcraft.yaml, leaving stale containers for removed platforms. Expected to clean all associated containers regardless of config. Open, inactive 304 days, needs triage.

Update history

No update history recorded yet.

Related work

  • Related To: canonical/charmcraft#1338 (confidence 80%)

    Maintainer sed-i explicitly linked this as related in a comment on 2025-01-28.

Related issues

Issue Project State Summary Similarity
#1338 `charmcraft clean` doesn't clean charmcraft closed Unresolved. LXD instances persist after running the command. Behavior changed but remains broken in charmcraft 3. Deferred to upstream craft-application issue #425 for resolution.
79%
#412 clean: introduce clean command (CRAFT-62) charmcraft merged Merged. Introduces a clean command to remove LXD containers built by Charmcraft and adds a caplog filter fixture for testing. Approved by two reviewers, the update modifies five files with 116 additions and 4 deletions.
70%
#1042 add `charmcraft purge` or `charmcraft cleanall` command to clean all instances charmcraft open Feature request to add a `charmcraft purge` command to clean all LXD build containers and pip caches. Design discussion is active with multiple flag options proposed. Blocked by craft-providers#639.
70%
#2631 Multiple `charmcraft pack` fail on mismatching platforms charmcraft open Charmcraft 4.2.0+ reuses a managed LXD instance from a prior `charmcraft pack` of a different project, causing the second pack to fail with 'Platform not found in the project definition' when platform sets differ. Still reproducible on 4.3.1 per reporter's 2026-08-17 comment; no maintainer response or labels yet.
70%