Search code examples
google-cloud-platformgoogle-cloud-storagegcloudgoogle-artifact-registry

Google Artifact Registry: Unable to delete some docker images because of "Precondition check failed"


I'm trying to automatically clean up a docker repository in the Google Cloud Artifact Registry. I have created a small script which is fetching images based on some filters and then deleting them.
However, after a while, there are a lot of images which just cannot be deleted.

gcloud -q artifacts docker images delete --delete-tags <repository>@<digest>
Digests:
- <repository>@<digest>
Delete request issued.
Waiting for operation [<operation-id>] to complete...failed.                                                                                                                      
ERROR: (gcloud.artifacts.docker.images.delete) Precondition check failed.

Adding --verbosity debug does not really add anything useful. Basically, everything works with the command, it's just Google which is returning the cryptic error message.

DEBUG: (gcloud.artifacts.docker.images.delete) Precondition check failed.
Traceback (most recent call last):
  File "/opt/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 987, in Execute
    resources = calliope_command.Run(cli=self, args=args)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 807, in Run
    resources = command_instance.Run(args)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/google-cloud-sdk/lib/surface/artifacts/docker/images/delete.py", line 98, in Run
    docker_util.WaitForOperation(
  File "/opt/google-cloud-sdk/lib/googlecloudsdk/command_lib/artifacts/docker_util.py", line 606, in WaitForOperation
    waiter.WaitFor(poller, op_resource, message)
  File "/opt/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 261, in WaitFor
    operation = PollUntilDone(
                ^^^^^^^^^^^^^^
  File "/opt/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 322, in PollUntilDone
    operation = retryer.RetryOnResult(
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 249, in RetryOnResult
    if not should_retry(result, state):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 320, in _IsNotDone
    return not poller.IsDone(operation)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 182, in IsDone
    raise OperationError(operation.error.message)
googlecloudsdk.api_lib.util.waiter.OperationError: Precondition check failed.
ERROR: (gcloud.artifacts.docker.images.delete) Precondition check failed.

Also the same is happening when trying to delete the image via the UI enter image description here

Not sure what is causing this, because the majority of the images can be deleted without any problems (no matter if they have tags or not). Doing this as an admin also doesn't change anything.
Maybe they are already marked for deletion and Google hasn't come around to them yet, but the amount of undeletable images just seems to be growing.
Does anybody know what can be done about this?


Solution

  • This error can occur when trying to delete an image that is a part of existing manifest list or image index. You need to remove any such manifest list/image index before removing images that they depend on.

    Also check this document, may the command is failing due to below reasons:

    • Trying to delete an image by digest when the image is still tagged. Add --delete-tags to delete the digest and the tags.

    • Trying to delete an image by tag when the image has other tags. Add --delete-tags to delete all tags.

    • A valid repository format was not provided.

    • The specified image does not exist.

    • The active account does not have permission to delete images.