(garbage-collection): `cdk gc` fails on ECR with `InvalidParameterException` when a ListImages page has only untagged images
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- aws, typescript
- Lĩnh vực
- cli
Hướng nghiên cứu
Mở packages/@aws-cdk/toolkit-lib/lib/api/garbage-collection/garbage-collector.ts và đọc readRepoInBatches cùng với imageMap(): map loại bỏ các image không gắn tag, và mảng imageIds thu được vẫn được gửi đến DescribeImages và BatchGetImage. Cách sửa là tiến continuation token và bỏ qua trang khi imageIds rỗng. Tìm trong các test garbage-collection của toolkit-lib phần coverage hiện có của readRepoInBatches để mở rộng với một trang hoàn toàn không gắn tag; hoàn tất nghĩa là vòng lặp đi qua mọi trang mà không có lệnh gọi imageIds rỗng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
cdk gc fails on the ECR part with EcrGarbageCollectionFailed when the bootstrap ECR repository contains untagged images.
In readRepoInBatches, imageMap() skips images without a tag. When every image in a ListImages page is untagged, imageIds becomes empty, and it is still passed to DescribeImages and BatchGetImage. ECR rejects an empty imageIds.
In our repository, all 274 untagged images are child manifests of the 137 OCI image indexes pushed as Docker image assets. The first 2 of the 399 ListImages pages contain only these untagged images, so the unpatched CLI fails at 0%.
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Version
This is not a regression: imageMap() has skipped untagged images, and the empty imageIds is passed to DescribeImages, since ECR garbage collection was added in v2.165.0 (aws/aws-cdk#31841).
Expected Behavior
Pages without tagged images are skipped, and garbage collection continues.
Current Behavior
$ cdk gc aws://<account-id>/ap-northeast-1 --unstable=gc --type=ecr --action=print -v
[14:58:35] CDK Toolkit CLI version: 2.1148.1 (build fcf5e34)
...
[14:58:40] Parsing through 450 stacks
[15:02:28] Done parsing through stacks
[15:02:28] Waiting for stack CDKToolkit to finish creating or updating...
[15:05:24] Found bootstrap repo cdk-hnb659fds-container-assets-<account-id>-ap-northeast-1 with 39828 images
[15:05:24] Parsing through 39828 images in batches
[0.00%] 0 files scanned: 0 assets (0.00 MiB) eligible for deletion.
EcrGarbageCollectionFailed: InvalidParameterException: Invalid parameter at 'imageIds' failed to satisfy constraint: 'Member must have length greater than or equal to 1'
The bootstrap ECR repository has 37,888 images: 37,614 tagged (137 of them are OCI image indexes) and 274 untagged.
Reproduction Steps
-
Have untagged images in the bootstrap ECR repository, enough that one
ListImagespage contains only untagged images. -
Run:
cdk gc aws://<account-id>/<region> --unstable=gc --type=ecr --action=print
Possible Solution
Skip the page when imageIds is empty, in readRepoInBatches of packages/@aws-cdk/toolkit-lib/lib/api/garbage-collection/garbage-collector.ts:
const imageIds = Object.keys(images).map(key => ({ imageDigest: key }));
if (imageIds.length === 0) {
continuationToken = response.nextToken;
if (!continuationToken) break;
continue;
}
With this change applied to a local copy of the 2.1148.1 CLI, cdk gc --type=ecr --action=print --created-buffer-days=7 -v on the same repository scanned to the last batch:
[18:20:35] 971 images total
...
[93.18%] 37111 files scanned: 37020 assets (30890.90 GiB) eligible for deletion.
The percentage stays below 100% because the total counts ListImages entries (one per tag, untagged included), while the scanned count includes only tagged images older than --created-buffer-days.
Additional Information/Context
Workaround: run cdk gc --type=s3 to skip ECR.
CDK CLI Version
2.1148.1 (build fcf5e34)
Framework Version
2.262.0
Node.js Version
v24.22.1
OS
macOS 27.2.1
Language
Python
Language Version
Python (3.12.13)
Other information
No response
- Ngôn ngữ chính
- TypeScript
- Star
- 110
- Fork
- 138
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 55
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws/aws-cdk-cli
-
(cli): deploy waits forever when an AWS API call gets no response, because requestTimeout only logs a warningCó thể đã có người làm @abhiramshaji-cyber đã nhận 27 ngày trước. Đang mởaws-cdk bug p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
aws/aws-cdk-cli#2097 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
(bootstrap) FilePublishingRoleDefaultPolicy permission incorrect when FileAssetsBucketKmsKeyId is an ARN valueCó thể đã có người làm @lemon0333 đã nhận 95 ngày trước. Đang mởbug p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
aws/aws-cdk-cli#921 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
(garbage-collection): cdk gc takes hours on a large bootstrap bucketCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
aws/aws-cdk-cli#2165 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
(cli): cdk flags --set always reports no template differences before applying flagsCó thể đã có người làm @go-to-k đã nhận 9 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
aws/aws-cdk-cli#2153 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
integ-runner: update workflow fails when deploying an existing snapshotCó thể đã có người làm @gibkim đã nhận 11 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 32/100
aws/aws-cdk-cli#2150 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của aws/aws-cdk-cli
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
volcengine/OpenViking#8432 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
jupyterlab/eslint-plugin#178 · 2 bình luận ·
-
bug from-app needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
nightly-labs/openbot#16303 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100