GoogleCloudPlatform / gcr-cleaner

Delete untagged image refs in Google Container Registry or Artifact Registry
Apache License 2.0
805 stars 112 forks source link

Recursive Flag Doesn't Work #38

Closed maxres-fr closed 3 years ago

maxres-fr commented 3 years ago

Expected:

Found:

I'm looking at using this project to replace some custom scripts and when testing this project I discovered that the -recursive wasn't working correctly. I don't see a great way to provide logs without running actual deletes.

The bug is here: https://github.com/sethvargo/gcr-cleaner/blob/0b89326a00e41dbe7831da1db49e58c84e223742/pkg/gcrcleaner/cleaner.go#L187

It's comparing a prefix with the domain, e.g. the cli argument value but a _catalog or Catalog wont return a list of repositories with a hostname, just the "path" portion.

maxres-fr commented 3 years ago

Using my dry run branch it's a little easier to see this:

(⎈ |k3d-k3s-default:default)
projects/gcr-cleaner [add-dry-run●]
❯ go run ./cmd/gcr-cleaner-cli/main.go -recursive -repo gcr.io/myproject/fidc -dry-run
gcr.io/myproject/fidc: dry run deleting refs since 2021-07-29 23:27:10.632140744 +0000 UTC
gcr.io/myproject/fidc: successfully deleted 0 refs

(⎈ |k3d-k3s-default:default)
projects/gcr-cleaner [add-dry-run●]
❯ go run ./cmd/gcr-cleaner-cli/main.go -recursive -repo gcr.io/myproject/fidc/am -dry-run
gcr.io/myproject/fidc/am: dry run deleting refs since 2021-07-29 23:27:23.85063709 +0000 UTC
dry delete: gcr.io/myproject/fidc/am@sha256:6c76d87a8f2fa3567c4b127a3e6ff671f95f595f0c4dc3e3a393cece9a49d5e8
dry delete: gcr.io/myproject/fidc/am@sha256:da3968914cba4df9534e6c67e7243e898610d543a5280aaa44509e44ad144269
dry delete: gcr.io/myproject/fidc/am@sha256:ddcab18bd0cf9b32268bad253794fa941e27518bcfa2833d5f896b02c4126642
dry delete: gcr.io/myproject/fidc/am@sha256:10bdeb78f62d6b4c726cccd520ca1e95dcb121b4c56ffa39ed0efbd1556bfa40
dry delete: gcr.io/myproject/fidc/am@sha256:44da8390e2c9eff95db1a557a510a705e2a919acda8dfcc98d28ff260593d2a7
dry delete: gcr.io/myproject/fidc/am@sha256:4a0488c4c6ba5079b6e36ff66255aeb0ab46f813c465144b7e7cd50cb6147267
dry delete: gcr.io/myproject/fidc/am@sha256:b95f77eb5076b24742aa6ac03792588b049ed4a487efdf77cc14f6004239efc7
dry delete: gcr.io/myproject/fidc/am@sha256:436cb1e22123181abb4c5da6a8ac38a5a15928868a6811d8550428b0e8dc71a9
dry delete: gcr.io/myproject/fidc/am@sha256:403c8b647b2df5fd447977f39868f0a6de6ed38fdd36e485d17093acc399359c
dry delete: gcr.io/myproject/fidc/am@sha256:a69402974f67fc49c9eeca9bbe1fdb35f34c84ee802cbb77515c2c327b00a4c6
dry delete: gcr.io/myproject/fidc/am@sha256:a461502022495a8bb6c90be1c21cc0b52e2cc38825348284e6afb02f4b840a76
dry delete: gcr.io/myproject/fidc/am@sha256:3af079625622e5641eb44db22447e3ae281895cc4b0094901c5e0de181ce44f3
dry delete: gcr.io/myproject/fidc/am@sha256:43567aae876039c5293de0da887894fbc096ac19099fb144cc928e6fa7ded02a
dry delete: gcr.io/myproject/fidc/am@sha256:f2df565430b4d0f35f235b02fdbc80182a520717454c4935093b8af2aee1686d
dry delete: gcr.io/myproject/fidc/am@sha256:c37c14e7faee5f481564fffada0d26c01a72c93f2ed0acae11c1cea574c08354
dry delete: gcr.io/myproject/fidc/am@sha256:a9228733f52dd4b33273269e9b87bcbe75afc82cf08e7b9ad73910ed37e0b147
dry delete: gcr.io/myproject/fidc/am@sha256:069d5bfb8bc6d1b8dbbbd31b96825cdfb66ff473c10b74ce357555c119aece27
dry delete: gcr.io/myproject/fidc/am@sha256:33c68b5a6261083cdfd94d71bd0715e84aa51ac98a54858a2375d97b6ab6eb87
dry delete: gcr.io/myproject/fidc/am@sha256:d9e13e23efb0633cdcaa7b6226a71858a67ffa684d316772a50857eef3f71ade
dry delete: gcr.io/myproject/fidc/am@sha256:60c0d9aec9a5669a0ffec17ff2f9df5e8c37a0e3fd7431d2ede96fdf89e2debf
dry delete: gcr.io/myproject/fidc/am@sha256:5dd74fb1279a58c8675bbd5ab2cc66a52daa69c185793c378307086fafcbd337
dry delete: gcr.io/myproject/fidc/am@sha256:918f3eb693ceed35ba8e2d11fe0567a52553e3405b8f913419e9d146c43a5576
dry delete: gcr.io/myproject/fidc/am@sha256:ce7b86295b2e70af193666d57be724c7a74b2a441abf47b6f356d7864fb78ba8
dry delete: gcr.io/myproject/fidc/am@sha256:9d4f598a43ac48190e31f68b779663fbb6a87fd7fc72ddc6d7c06e79992c2ad4
dry delete: gcr.io/myproject/fidc/am@sha256:4215f93fa9b0a5633477fdc6f74c2a2dce27c05fa5f62271641092b07790cd43
dry delete: gcr.io/myproject/fidc/am@sha256:c1b241567cad645fc0562459b7ccc7a1292dbaa126aa26d5fdafebde3c940f43
dry delete: gcr.io/myproject/fidc/am@sha256:96d81d6f4bf705c7e571d87a11e3c7c368cdb4baf9a11834767d2bc7f7625d44
dry delete: gcr.io/myproject/fidc/am@sha256:530791b364f148d3541feb56b9bbff8313794428c085d77cfc01794946a3311d
dry delete: gcr.io/myproject/fidc/am@sha256:aa223c128d823dc338f042be66ec8ed39daf9262d3032022c37fb416dbe05ce8
dry delete: gcr.io/myproject/fidc/am@sha256:27e6f5ba6a0b69e0b7833199bc63d4d4211292de641791334a930c8b85f811bb
dry delete: gcr.io/myproject/fidc/am@sha256:f70aa8bb76241cef11dfe8fee444c3e74a0d8a2cdd0a7cbdabfe334a3a0bbdd7
dry delete: gcr.io/myproject/fidc/am@sha256:922590b75878a0a64fe885b51aa2aa5742cc8217b59a2b57e95f7aceac02e9da
dry delete: gcr.io/myproject/fidc/am@sha256:3047a1cbb118972fe2848c45c0246b1d347128b179d4994bd60a6ddbfdae3217
dry delete: gcr.io/myproject/fidc/am@sha256:cce4dc63366f57ff8e163a7e928145ce054b8be14ca058a6c53175a5fb2da080
dry delete: gcr.io/myproject/fidc/am@sha256:1425a0bf8d38e35e5c708418fcf2b94199d7a6e5cf1ff624c431e86ed9703fad
dry delete: gcr.io/myproject/fidc/am@sha256:6f7a4e5b898c9bcc7b73995518094a93851b87bbd47ae7e45646f9226f33be78
dry delete: gcr.io/myproject/fidc/am@sha256:4e72022ca59f6ecbdd074800f3de0c27139435b6444f26937622cadac6c64ea5
dry delete: gcr.io/myproject/fidc/am@sha256:8e08a6ec1d63ebd710e5ead45fe8ef6f11e467776b37f2f79926d19106adc0b5
dry delete: gcr.io/myproject/fidc/am@sha256:08731a204b071d921383f2871987feb2e1eedf3506394cf7a2a1c3a7791ef965
dry delete: gcr.io/myproject/fidc/am@sha256:6d90ea843277ec700ca788cfd81d7a7f6b7cb7f6979e4f3561b451a57b412c57
dry delete: gcr.io/myproject/fidc/am@sha256:faf70c8d8c53169dd75d4bebfb558849949d8f7966b780cd8ff1abd0fe1df332
dry delete: gcr.io/myproject/fidc/am@sha256:f9d99d61c3c630d0fd495d3d4ff934a16101241b71b4a1d418e1d922446b0b61
dry delete: gcr.io/myproject/fidc/am@sha256:7d47402d5af9e176281cc955cb29c0188e57221ef52f0e0bd2a2af8a878cb5dd
dry delete: gcr.io/myproject/fidc/am@sha256:b44eee1c032f1c671223bbdffa70f0fcf6ae758ba96c9eab796ed75bf53e4ea4
dry delete: gcr.io/myproject/fidc/am@sha256:89cd851d33add171e7b5b5acc6198369ac59562510a541d2f24f46b50bc7bf89
dry delete: gcr.io/myproject/fidc/am@sha256:795ae6818fd194c6b30c99020ca3ca7eea6c35971d931a67734829d2f3ebc0d1
dry delete: gcr.io/myproject/fidc/am@sha256:dad4286f2bf9480b3e25628e9abd0c9d2500b0500e323533ca11610722677ffa
dry delete: gcr.io/myproject/fidc/am@sha256:c59d10576989b6a7b4a027d02457006c8354442d98cbd6f5d220c9b53087b91c
dry delete: gcr.io/myproject/fidc/am@sha256:a381644767c40d67b66a3c52b62678cb365c9267c12bdc894c863fccee179e04
dry delete: gcr.io/myproject/fidc/am@sha256:d4e8f8656b43b1f31caa7a774f7dd44646342f3c2fc91fc387ddfe92be42a0e6
dry delete: gcr.io/myproject/fidc/am@sha256:773079b9032a2fe8b17e7285520b0c59d69bbb53dd2a03e94dc3407f61c7ada0
dry delete: gcr.io/myproject/fidc/am@sha256:6d3312432d815963e39b491ada81a7ff77a036eb2b7e305c660e8cf47df9dfb5
dry delete: gcr.io/myproject/fidc/am@sha256:c6ad5eac11c1ebf352a46a6daba18efa99f28989ecf34b0936ea49f2bd9f43ce
dry delete: gcr.io/myproject/fidc/am@sha256:a5fa39370356069f3aa8e51ed86ae1deb9799bcde7b15f9653d6203b59654c93
dry delete: gcr.io/myproject/fidc/am@sha256:0e9a1505b442d8cf4dd149c522309a05fc2d8cdca6fd386ce5bbf53fc5ad941c
dry delete: gcr.io/myproject/fidc/am@sha256:275abc49cdcb9d1cf5b6ce66b1cb95c0b4784e6f427a85e96c66d640287c0844
dry delete: gcr.io/myproject/fidc/am@sha256:413b9630b7bb515503c936dca8fed1efa70fc1b10a58c06bd21ebe0ed848ee42
dry delete: gcr.io/myproject/fidc/am@sha256:33f2d6237cbcbf12bc7b4c4bf61bec3c2d38be5b3ab7cdab461fd46229f238df
dry delete: gcr.io/myproject/fidc/am@sha256:0b090e2740c5821330a6f0eab1eb6b38499fa4796f536ac9e6fc41e1741193e0
dry delete: gcr.io/myproject/fidc/am@sha256:a3aef2e1130a8982dfd66130b63f00f7238706d3b31726d3cfda0ff4a04314be
dry delete: gcr.io/myproject/fidc/am@sha256:06ca32a14680bf3500dab53da236250aedd06d2dde62e51f7c626c033884ec9e
dry delete: gcr.io/myproject/fidc/am@sha256:9fd00d75713c2c610a4877289e819138921107b18b6145164c46d96fcab7a780
dry delete: gcr.io/myproject/fidc/am@sha256:793da5542a54b8678530757dcb1864bcb40b4e542b0b2a24d944fcb45ae47a27
dry delete: gcr.io/myproject/fidc/am@sha256:4091b5049ac8ba3ca9a13360577bc1e1ecd7bc42d0b923474bc8fbf329681432
dry delete: gcr.io/myproject/fidc/am@sha256:d15a1fd3f8071a1b3d6007742930626a7e09eadd6666c2641771ac33aa08506d
dry delete: gcr.io/myproject/fidc/am@sha256:ba7e072b152e2e4829ae9b6ed7ff84764ef1c93739c87ac87a577339a9f3812d
dry delete: gcr.io/myproject/fidc/am@sha256:891ea28e6a331aa5e4a937be813a11a2154dc8f4bfa5d0b690555eb259658220
gcr.io/myproject/fidc/am: successfully deleted 67 refs
grumps commented 3 years ago

@sethvargo sorry I got two GH accounts going here. The recursive is also missing from the server implementation. I've got changes for that, you want that as a different PR?