//Module included in the following assemblies:
//
// * microshift_running_apps/microshift_operators/microshift-operators-oc-mirror.adoc

:_mod-docs-content-type: PROCEDURE
[id="microshift-oc-mirror-transform-imageset-to-crio_{context}"]
= Configuring CRI-O for using a registry mirror for Operators

[role="_abstract"]
To use a registry mirror for Operators with {microshift-short}, you must transform the `ImageDigestMirrorSet` YAML file created by the oc-mirror plugin into a format that is compatible with the MicroShift CRI-O container runtime configuration.
.Prerequisites

* The {oc-first} is installed.
* You installed Operator Lifecycle Manager (OLM).
* You installed the oc-mirror plugin.
* You installed the `yq` binary.
* The `ImageDigestMirrorSet` and `CatalogSource` YAML files are available in the `cluster-resources` subdirectory.

.Procedure

. Confirm the contents of the `ImageDigestMirrorSet` YAML file by running the following command:
+
[source,terminal,subs="+quotes"]
----
$ cat _<v2_workspace>_/working-dir/cluster-resources/imagedigestmirrorset.yaml
----
+
Replace _<v2_workspace>_ with the directory name that you used when you generated mirroring resources.
+
.Example output
[source,yaml]
----
apiVersion: config.openshift.io/v1
kind: ImageDigestMirrorSet
metadata:
  labels:
    operators.openshift.org/catalog: "true"
  name: operator-0
spec:
  imageDigestMirrors:
  - mirrors:
    - registry.example.com/amq7
    source: registry.redhat.io/amq7
----

. Transform the `imagedigestmirrorset.yaml` into a format ready for CRI-O configuration by running the following command:
+
[source,terminal]
----
$ yq '.spec.imageDigestMirrors[] as $item ireduce([]; . + [{"mirror": $item.mirrors[], "source": ($item | .source)}]) | .[] |
  "[[registry]]
      prefix = \"" + .source + "\"
      location = \"" + .mirror + "\"
      mirror-by-digest-only = true
      insecure = true
      "' ./mirror1/working-dir/cluster-resources/imagedigestmirrorset.yaml
----
+
.Example output
[source,terminal]
----
[[registry]]
      prefix = "registry.redhat.io/amq7"
      location = "registry.example.com/amq7"
      mirror-by-digest-only = true
      insecure = true
----

. Add the output to the CRI-O configuration file in the `/etc/containers/registries.conf.d/` directory:
+
.Example `crio-config.yaml` mirror configuration file
[source,yaml]
----
[[registry]]
      prefix = "registry.redhat.io/amq7"
      location = "registry.example.com/amq7"
      mirror-by-digest-only = true
      insecure = true

[[registry]]
    prefix = ""
    location = "quay.io"
    mirror-by-digest-only = true
[[registry.mirror]]
    location = "<registry_host>:<port>"
    insecure = false
----
+
where

`registry.mirror.location`:: Specifies the hostname and port of your mirror registry server, for example `microshift-quay:8443`.

. Apply the CRI-O configuration changes by restarting {microshift-short} with the following command:
+
[source,terminal]
----
$ sudo systemctl restart crio
----
