feat(cleanup): enable Docker cleanup for all backends and simplify code#13670
feat(cleanup): enable Docker cleanup for all backends and simplify code#13670
Conversation
|
@copilot but if the backend is AWS or Azure, the docker cleanup isn't gonna happen at all, also the scan of all of the builders is disabled recently, can you review this part again ? |
You're absolutely right - I need to correct my analysis. Issue 1: Docker cleanup doesn't run for AWS/Azure backends
If backend is "aws" or "azure", Docker resources are NOT cleaned up. This is a problem because tests on AWS/Azure backends may still create local Docker containers (e.g., for stress tools, monitoring). Issue 2: Builder scanning disabled in Jenkins My documentation incorrectly stated these features work in all cases. I'll update the analysis and fix the documentation to reflect the actual behavior. |
|
@copilot also update all of the in the plan, and the need to enable docker local cleanup in every cleanup |
Done. Reverted all code changes and rewrote the plan (commit a24d0a5). Changes:
Ready to proceed with code implementation once plan is approved. |
4962aa3 to
a79e78a
Compare
Created comprehensive plan to enable Docker cleanup across all backends (aws, gce, azure) instead of only docker backend, addressing resource accumulation on Jenkins builders. Plan includes 4 phases to simplify cleanup logic, remove unused builder scanning code, and add logging.
a79e78a to
358c112
Compare
|
@copilot now go an implement the whole plan |
Implemented all 4 phases of Docker cleanup plan:
Phase 1: Enable Docker cleanup for all backends
- Changed condition from 'if cluster_backend in ("docker", "")'
- To: 'if not cluster_backend.startswith("k8s-local")'
- Added explanatory comment
- Improved logging: "Cleaned Docker container/image: <name>"
Phase 2: Remove unused builder_name parameter
- Removed builder_name from clean_resources_docker() signature
- Updated call to list_resources_docker()
- Added docstring clarifying local-only behavior
Phase 3: Simplify list_resources_docker
- Removed builder_name and group_as_builder parameters
- Removed call to list_clients_docker()
- Now uses docker.from_env() directly for local daemon
- Simplified logic - no more parallel builder scanning
- Updated docstring
Phase 4: Remove obsolete list_clients_docker
- Verified function not used elsewhere in codebase
- Removed list_clients_docker() function completely
- Removed 47 lines of obsolete builder scanning code
Docker cleanup now runs for all backends (aws, gce, azure, docker,
k8s-*, xcloud) except k8s-local, scanning only the local Docker daemon.
Co-authored-by: fruch <[email protected]>
Updated plan document to reflect that all 4 phases have been implemented in commit 3005e2a. Co-authored-by: fruch <[email protected]>
Implemented all 4 phases in commits 3005e2a and f5a792b. Summary:
Total: -50 lines of code, simplified logic, Docker cleanup now works for aws/azure/gce backends. |
|
@copilot fix precommit issue, and this test was failing: |
sdcm/utils/resources_cleanup.py
Outdated
|
|
||
| def delete_image(image): | ||
| LOGGER.info("Going to delete Docker image tag(s) %s on `%s'", image.tags, image.client.info()["Name"]) | ||
| image_tags = image.tags or ["<untagged>"] |
There was a problem hiding this comment.
@copilot where this <untagged> is coming from ?
There was a problem hiding this comment.
Fixed in commit 2274704. The <untagged> string was an unnecessary addition I made. Reverted to the original approach of logging image.tags directly as-is, which correctly handles all cases including None or empty lists.
…nature Fixed unit test CleanResourcesDockerTest::test_destroy to match the new simplified function signature after removing builder_name and group_as_builder parameters. The test was calling list_resources_docker with: - builder_name=None - group_as_builder=False These parameters were removed in the Docker cleanup simplification, so the test now correctly calls the function with only tags_dict. Co-authored-by: fruch <[email protected]>
Fixed in commit 5fe0454. Updated test to call |
Reverted to original approach of logging image.tags directly without adding custom "<untagged>" fallback. The original code logged image.tags as-is, which correctly handles all cases including None or empty lists. The "<untagged>" string was an unnecessary addition that wasn't in the original implementation. Co-authored-by: fruch <[email protected]>
Description
Implemented Docker resource cleanup for all backends (aws, gce, azure, docker, k8s-*, xcloud) to fix the issue where Docker containers were only cleaned when
backend=docker, leaving containers uncleaned when tests run on AWS/Azure/GCE backends.The implementation follows the plan documented in
docs/plans/docker-cleanup-all-backends.mdand completes all 4 phases:builder_nameparameterChanges
Phase 1: Enable Docker Cleanup for All Backends
if cluster_backend in ("docker", "")toif not cluster_backend.startswith("k8s-local")Phase 2: Remove Unused Parameters
builder_nameparameter fromclean_resources_docker()functionlist_resources_docker()to not pass unused parametersPhase 3: Simplify list_resources_docker
builder_nameandgroup_as_builderparameters from function signaturelist_clients_docker()docker.from_env()directly to get local Docker clientPhase 4: Remove Obsolete Code
list_clients_docker()not used elsewhere in codebaselist_clients_docker()function (47 lines of obsolete builder scanning code)Bug Fixes
unit_tests/test_clean_cloud_resources_func.py::CleanResourcesDockerTest::test_destroyto match the new simplified function signature<untagged>string handling in image logging to match original implementationKey Points:
Backend Coverage (Implemented)
Files Modified:
sdcm/utils/resources_cleanup.py- Updated cleanup condition, improved logging, simplified function signaturesdcm/utils/common.py- Simplified list_resources_docker, removed list_clients_dockerunit_tests/test_clean_cloud_resources_func.py- Updated test to match new function signaturedocs/plans/docker-cleanup-all-backends.md- Implementation plan (all phases marked complete)Ref: SCT-99
Testing
PR pre-checks (self review)
backportlabelsReminders
sdcm/sct_config.py)unit-test/folder)💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.