// Module included in the following assemblies:
//
// * scalability_and_performance/low_latency_tuning/cnf-performing-platform-verification-latency-tests.adoc

:_mod-docs-content-type: PROCEDURE
[id="cnf-performing-end-to-end-tests-mirroring-to-cluster-internal-registry_{context}"]
= Mirroring images to the cluster {product-registry}

[role="_abstract"]
To make container images locally available for your deployment, mirror them to the built-in {product-registry}. This integrated component runs as a standard workload on your {product-title} cluster to ensure continuous access to required files.

.Procedure

. Gain external access to the registry by exposing the registry with a route. You can do this task by running a command similar to the following example:
+
[source,terminal]
----
$ oc patch configs.imageregistry.operator.openshift.io/cluster --patch '{"spec":{"defaultRoute":true}}' --type=merge
----

. Fetch the registry endpoint by running a command similar to the following example:
+
[source,terminal]
----
$ REGISTRY=$(oc get route default-route -n openshift-image-registry --template='{{ .spec.host }}')
----

. Create a namespace for exposing the images by running a command similar to the following example:
+
[source,terminal]
----
$ oc create ns cnftests
----

. Make the image stream available to all the namespaces used for tests. This is required to allow the tests namespaces to fetch the images from the `cnf-tests` image stream. Run commands similar to the following examples:
+
[source,terminal]
----
$ oc policy add-role-to-user system:image-puller system:serviceaccount:cnf-features-testing:default --namespace=cnftests
----
+
[source,terminal]
----
$ oc policy add-role-to-user system:image-puller system:serviceaccount:performance-addon-operators-testing:default --namespace=cnftests
----

. Retrieve the docker secret name by running a command similar to the following example:
+
[source,terminal]
----
$ SECRET=$(oc -n cnftests get secret | grep builder-docker | awk {'print $1'}
----

. Retrieve the docker auth token by running a command similar to the following example:
+
[source,terminal]
----
$ TOKEN=$(oc -n cnftests get secret $SECRET -o jsonpath="{.data['\.dockercfg']}" | base64 --decode | jq '.["image-registry.openshift-image-registry.svc:5000"].auth')
----

. Create a `dockerauth.json` file, for example:
+
[source,bash]
----
$ echo "{\"auths\": { \"$REGISTRY\": { \"auth\": $TOKEN } }}" > dockerauth.json
----

. Mirror the image by running a command similar to the following example:
+
[source,terminal,subs="attributes+"]
----
$ podman run -v $(pwd)/:/kubeconfig:Z -e KUBECONFIG=/kubeconfig/kubeconfig \
registry.redhat.io/openshift4/cnf-tests-rhel9:v{product-version} \
/usr/bin/mirror -registry $REGISTRY/cnftests |  oc image mirror --insecure=true \
-a=$(pwd)/dockerauth.json -f -
----

. Run the tests by running a command similar to the following example:
+
[source,terminal,subs="attributes+"]
----
$ podman run -v $(pwd)/:/kubeconfig:Z -e KUBECONFIG=/kubeconfig/kubeconfig \
-e LATENCY_TEST_RUNTIME=<time_in_seconds> \
-e IMAGE_REGISTRY=image-registry.openshift-image-registry.svc:5000/cnftests cnf-tests-local:latest /usr/bin/test-run.sh --ginkgo.v --ginkgo.timeout="24h"
----
