(garbage-collection): `cdk gc` fails on ECR with `InvalidParameterException` when a ListImages page has only untagged images
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- aws, typescript
- 領域
- cli
調査の方向性
packages/@aws-cdk/toolkit-lib/lib/api/garbage-collection/garbage-collector.ts を開き、readRepoInBatches を imageMap() と一緒に読んでください。map はタグなしイメージを破棄しますが、結果として得られる imageIds 配列は依然として DescribeImages と BatchGetImage に送信されます。修正は、continuation token を進め、imageIds が空の場合はページをスキップすることです。toolkit-lib の garbage-collection テストの下で、readRepoInBatches の既存のカバレッジを探し、すべてタグなしのページで拡張してください。完了とは、ループが空の imageIds 呼び出しなしで全ページを走査することです。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- TypeScript
- スター
- 110
- フォーク
- 138
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 56
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
aws/aws-cdk-cli のほかの issue
-
(cli): deploy waits forever when an AWS API call gets no response, because requestTimeout only logs a warning対応中かも @abhiramshaji-cyber が 27 日前に担当しました。 オープンaws-cdk bug p2
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
aws/aws-cdk-cli#2097 ·
メンテナーはふだん 1 日以内に返信
-
(bootstrap) FilePublishingRoleDefaultPolicy permission incorrect when FileAssetsBucketKmsKeyId is an ARN value対応中かも @lemon0333 が 95 日前に担当しました。 オープンbug p2
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
aws/aws-cdk-cli#921 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
(garbage-collection): cdk gc takes hours on a large bootstrap bucket対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
aws/aws-cdk-cli#2165 ·
メンテナーはふだん 1 日以内に返信
-
(cli): cdk flags --set always reports no template differences before applying flags対応中かも @go-to-k が 9 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
aws/aws-cdk-cli#2153 ·
メンテナーはふだん 1 日以内に返信
-
integ-runner: update workflow fails when deploying an existing snapshot対応中かも @gibkim が 11 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 32/100
aws/aws-cdk-cli#2150 ·
メンテナーはふだん 1 日以内に返信
aws/aws-cdk-cli の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
volcengine/OpenViking#8432 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
jupyterlab/eslint-plugin#178 · コメント 2 件 ·
-
bug from-app needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
nightly-labs/openbot#16303 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100