How to delete images using oc-mirror v2 that were mirrored using oc-mirror v1 in RHOCP 4

Solution Verified - Updated -

Environment

  • Red Hat OpenShift Container Platform (RHOCP)
    • 4
  • oc-mirror
    • v2

Issue

  • How to delete images using oc-mirror v2 that were mirrored using oc-mirror v1 in RHOCP 4.

Resolution

1) Let's assume the mirrored images version using oc-mirror v1 is 4.14.31. Mirroring mirrorToDisk using oc-mirror v2 is requirement or a prerequisite step to be able to perform delete using v2 for the images mirrored with v1.

$ cat imagesetfile.yaml
kind: ImageSetConfiguration
apiVersion: mirror.openshift.io/v2alpha1
archiveSize: 4
mirror:
  platform:
   channels:
   - name: stable-4.14
     minVersion: 4.14.31
     maxVersion: 4.14.31

2) Perform mirrorToDisk using oc-mirror v2.

$ ./oc-mirror -c imagesetfile.yaml file://`pwd` --v2

2025/02/20 03:52:00  [INFO]   :  Hello, welcome to oc-mirror
2025/02/20 03:52:00  [INFO]   :   setting up the environment for you...
2025/02/20 03:52:00  [INFO]   :  workflow mode: mirrorToDisk 
2025/02/20 03:52:01  [INFO]   :   going to discover the necessary images...
..
2025/02/20 03:59:50  [INFO]   :   190 / 190 release images mirrored successfully
2025/02/20 03:59:50  [INFO]   :  Preparing the tarball archive...

2025/02/20 04:01:43  [INFO]   : mirror time     : 9m42.887046994s
2025/02/20 04:01:43  [INFO]   : Goodbye, thank you for using oc-mirror

3) Generate delete-images.yaml using below DeleteImageSetConfiguration.

$ cat deleteImageSetConfiguration.yaml 
kind: DeleteImageSetConfiguration
apiVersion: mirror.openshift.io/v2alpha1
delete:
  platform:
   channels:
   - name: stable-4.14
     minVersion: 4.14.31
     maxVersion: 4.14.31

$ ./oc-mirror delete -c deleteImageSetConfiguration.yaml --workspace file://`pwd` --v2 --generate --delete-v1-images docker://myregistry

2025/02/20 04:08:25  [INFO]   : Hello, welcome to oc-mirror
2025/02/20 04:08:25  [INFO]   :  setting up the environment for you...
2025/02/20 04:08:25  [INFO]   :  workflow mode: diskToMirror / delete
2025/02/20 04:08:26  [INFO]   :   going to discover the necessary images...
2025/02/20 04:08:26  [INFO]   :  collecting release images...
2025/02/20 04:08:26  [INFO]   :  collecting operator images...
2025/02/20 04:08:26  [INFO]   :  collecting additional images...
2025/02/20 04:08:26  [INFO]   :  collecting helm images...
2025/02/20 04:08:26  [INFO]   :  Generating delete file...
2025/02/20 04:08:26  [INFO]   : /home/user/v2/working-dir/delete file created
2025/02/20 04:08:26  [INFO]   : delete time     : 148.856635ms
2025/02/20 04:08:26  [INFO]   :  Goodbye, thank you for using oc-mirror

4) Now delete images using generated ./working-dir/delete/delete-images.yaml.

$ ./oc-mirror delete --v2 --delete-yaml-file working-dir/delete/delete-images.yaml docker://myregistry

2025/02/20 04:08:59  [INFO]   :  Hello, welcome to oc-mirror
2025/02/20 04:08:59  [INFO]   :  setting up the environment for you...
2025/02/20 04:08:59  [INFO]   :  workflow mode: diskToMirror / delete
2025/02/20 04:08:59  [INFO]   :  Reading delete file...
2025/02/20 04:09:00  [INFO]   :  Start deleting the images...
2025/02/20 04:09:00  [INFO]   :  images to delete 190 
...
..
2025/02/20 04:10:03  [INFO]   : === Results ===
2025/02/20 04:10:03  [INFO]   :    190 / 190 release images deleted successfully
2025/02/20 04:10:03  [INFO]   : delete time     : 1m3.048673462s
2025/02/20 04:10:03  [INFO]   :  Remember to execute a garbage collect (or similar) on your remote repository
2025/02/20 04:10:03  [INFO]   :  Goodbye, thank you for using oc-mirror

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments