# OLM Mirrorring on RHEL 7
In reference to opm on RHEL 7.x
* https://access.redhat.com/solutions/5565971
## Setup System
```
sudo subscription-manager register
sudo subscription-manager refresh
sudo subscription-manager attach --auto
subscription-manager repos --enable=rhel-7-server-extras-rpms
subscription-manager repos --enable=rhel-7-server-optional-rpms
yum install podman tmux vim wget -y
```
**Configure OpenShift Packages**
```
curl -OL https://raw.githubusercontent.com/tosin2013/openshift-4-deployment-notes/master/pre-steps/configure-openshift-packages.sh
chmod +x configure-openshift-packages.sh
./configure-openshift-packages.sh -i
```
[Operator Lifecycle Manager on restricted networks](https://github.com/tosin2013/openshift-4-deployment-notes/blob/master/disconnected-scripts/operator-lifecycle-manager-on-restricted-networks.md)
**Get OpenShift Pull Secret and save it to `~/pull-secret.json`**
> [Install OpenShift on Bare Metal](https://console.redhat.com/openshift/install/metal/installer-provisioned)
**Disable the sources for the default catalogs by adding disableAllDefaultSources: true to the OperatorHub object:**
```
oc patch OperatorHub cluster --type json \
-p '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": true}]'
```
**Login to podman**
```
podman login registry.redhat.io
```
**Pull locally the index image:**
```
podman pull registry.redhat.io/redhat/redhat-operator-index:v4.10 --authfile ~/pull-secret.json
```
**Start the index container:**
```
podman run --name opm -d registry.redhat.io/redhat/redhat-operator-index:v4.10
```
**Copy the index database inside the container:**
```
podman exec -it opm cp /database/index.db /registry/index.db
```
**Prune the index usining the copied database file:**
[packages-4.10.x.out](https://github.com/tosin2013/openshift-4-deployment-notes/blob/master/disconnected-scripts/packages-4.10.x.out)
```
cat >saved-packages.log<<EOF
advanced-cluster-management
ansible-automation-platform-operator
cincinnati-operator
klusterlet-product
local-storage-operator
mcg-operator
multicluster-engine
ocs-operator
odf-csi-addons-operator
odf-lvm-operator
odf-multicluster-orchestrator
odf-operator
openshift-gitops-operator
openshift-pipelines-operator-rh
quay-operator
servicemeshoperator
EOF
cat saved-packages.log | paste -d ',' -s
```
```
$ podman exec -it opm opm registry prune -p advanced-cluster-management,ansible-automation-platform-operator,cincinnati-operator,klusterlet-product,local-storage-operator,mcg-operator,multicluster-engine,ocs-operator,odf-csi-addons-operator,odf-lvm-operator,odf-multicluster-orchestrator,odf-operator,openshift-gitops-operator,openshift-pipelines-operator-rh,quay-operator,servicemeshoperator --database /registry/index.db
```
**Generate the new image starting from the modified container:**
```
$ podman commit opm harbor-registry.gp.ocpincubator.com/ocp4/redhat-operator-index:v4.10
```
**Push the new index image in your local registry**
```
$ podman login harbor-registry.gp.ocpincubator.com
$ podman push harbor-registry.gp.ocpincubator.com/ocp4/redhat-operator-index:v4.10 --tls-verify=true
```
**Mirror the catalog based on the index image pushed in the local registry:**
```
$ tmux new -s mirror_images
$ oc adm catalog mirror harbor-registry.gp.ocpincubator.com/ocp4/redhat-operator-index:v4.10 harbor-registry.gp.ocpincubator.com/ocp4 -a ~/pull-secret.json
$ tmux a -t mirror_images
```
**Optional mirror to local file**
```
oc adm catalog mirror \
<index_image> \
file:///local/index \
-a ${REG_CREDS} \
--insecure \
--index-filter-by-os='<platform>/<arch>'
```
**Generate imagecontent source policy and catalog source**
```
$ oc adm catalog mirror harbor-registry.gp.ocpincubator.com/ocp4/redhat-operator-index:v4.10 harbor-registry.gp.ocpincubator.com/ocp4 --registry-config=pull-secret.json --max-per-registry=100 --manifests-only | tee -a mainfest.txt
$ export MANIFEST_DIRECTORY=$(grep -P -i -o 'redhat-operator-index([+-]?(?=\.\d|\d)(?:\d+)?(?:\.?\d*))(?:[eE]([+-]?\d+))?' mainfest.txt)
```
**add ImageContentSourcePolicy to cluster**
```
$ oc create -f manifests-$MANIFEST_DIRECTORY/imageContentSourcePolicy.yaml
```
**Adding a catalog source to a cluster**
**Rename `name:`**
```
$ vim manifests-$MANIFEST_DIRECTORY/catalogSource.yaml
```
**Create Catalog source for registry**
```
$ oc create -f manifests-$MANIFEST_DIRECTORY/catalogSource.yaml
```
**Check the status in OpenShift Marketplace**
```
$ oc get pods -n openshift-marketplace
NAME READY STATUS RESTARTS AGE
marketplace-operator-74657cd4bd-jqrpj 1/1 Running 0 5h59m
my-operator-catalog-gx4gg 0/1 ContainerCreating 0 4s
```
**Updating an index image**
```
opm index add \
--bundles <registry>/<namespace>/<new_bundle_image>@sha256:<digest> \
--from-index <registry>/<namespace>/<existing_index_image>:<existing_tag> \
--tag <registry>/<namespace>/<existing_index_image>:<updated_tag> \
--pull-tool podman
```
Links:
* https://docs.openshift.com/container-platform/4.10/operators/admin/olm-managing-custom-catalogs.html#olm-accessing-images-private-registries_olm-managing-custom-catalogs