Skip to content

Commit 655b531

Browse files
authored
change oc adm mirror in order to use oc-mirror (#598)
Migrate mirror steps to use oc-mirror This is quite a big change and it did a refactor on several areas of the code base. The gist and most important parts of this change are: - The ocp-mirror and olm-mirror have now been merged - The mirror is now done using `oc-mirror` - The mirror step only syncs the required packages from selected channels instead of downloading the latest from every channel as it was doing before. Architectures are not filtered. - There is now a single organization in Quay called `ztpfw` - ICSPs and catalogsources are created by oc-mirror - The catalogsource names are kept as the upstream ones to avoid having to mess with the subscriptions. Minor changes: - Several sleeps have been removed in favor of waiting for resources
1 parent 1c47354 commit 655b531

38 files changed

Lines changed: 678 additions & 971 deletions

deploy-disconnected-registry/common.sh

Lines changed: 21 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,6 @@ set -o pipefail
44
set -o nounset
55
set -m
66

7-
function create_cs() {
8-
9-
local mode=${1}
10-
11-
if [[ ${mode} == 'hub' ]]; then
12-
local CS_OUTFILE=${OUTPUTDIR}/catalogsource-hub.yaml
13-
local cluster="hub"
14-
elif [[ ${mode} == 'edgecluster' ]]; then
15-
local cluster=${2}
16-
local CS_OUTFILE=${OUTPUTDIR}/catalogsource-${cluster}.yaml
17-
fi
18-
19-
cat >${CS_OUTFILE} <<EOF
20-
21-
apiVersion: operators.coreos.com/v1alpha1
22-
kind: CatalogSource
23-
metadata:
24-
name: ${OC_DIS_CATALOG}
25-
namespace: ${MARKET_NS}
26-
spec:
27-
sourceType: grpc
28-
image: ${OLM_DESTINATION_INDEX}
29-
displayName: Disconnected Lab
30-
publisher: disconnected-lab
31-
updateStrategy:
32-
registryPoll:
33-
interval: 30m
34-
EOF
35-
echo
36-
37-
if [ -z $CERTIFIED_SOURCE_PACKAGES ]; then
38-
echo ">>>> There are no certified operators to be mirrored"
39-
else
40-
cat >>${CS_OUTFILE} <<EOF
41-
---
42-
apiVersion: operators.coreos.com/v1alpha1
43-
kind: CatalogSource
44-
metadata:
45-
name: ${OC_DIS_CATALOG}-certfied
46-
namespace: ${MARKET_NS}
47-
spec:
48-
sourceType: grpc
49-
image: ${OLM_CERTIFIED_DESTINATION_INDEX}
50-
displayName: Disconnected Lab Certified
51-
publisher: disconnected-lab-certified
52-
updateStrategy:
53-
registryPoll:
54-
interval: 30m
55-
EOF
56-
fi
57-
echo
58-
}
59-
607
function trust_internal_registry() {
618

629
if [[ $# -lt 1 ]]; then
@@ -111,7 +58,7 @@ function trust_internal_registry() {
11158

11259
}
11360

114-
function get_external_registry_cert() {
61+
function get_external_registry_cert() {
11562
KBKNFG=${EDGE_KUBECONFIG}
11663
echo "INFO: Getting external registry cert"
11764
export CA_CERT_DATA=$(openssl s_client -connect ${CUSTOM_REGISTRY_URL} -showcerts < /dev/null | openssl x509 | base64 | tr -d '\n')
@@ -129,7 +76,6 @@ function get_external_registry_cert() {
12976
oc --kubeconfig=${KBKNFG} patch image.config.openshift.io/cluster --patch '{"spec":{"additionalTrustedCA":{"name":"ztpfwregistry-external"}}}' --type=merge
13077

13178
}
132-
13379
if [[ $# -lt 1 ]]; then
13480
echo "Usage :"
13581
echo ' $1: hub|edgecluster'
@@ -152,11 +98,8 @@ export QUAY_MANIFESTS=quay-manifests
15298
export SECRET=auth
15399
export REGISTRY_CONFIG=config.yml
154100

155-
export SOURCE_PACKAGES='quay-operator,kubernetes-nmstate-operator,metallb-operator,ocs-operator,odf-operator,odf-csi-addons-operator,local-storage-operator,advanced-cluster-management,multicluster-engine,mcg-operator,nfd,odf-lvm-operator'
156-
export CERTIFIED_SOURCE_PACKAGES='gpu-operator-certified'
157-
export PACKAGES_FORMATED=$(echo ${SOURCE_PACKAGES} | tr "," " ")
158-
export CERTIFIED_PACKAGES_FORMATED=$(echo ${CERTIFIED_SOURCE_PACKAGES} | tr "," " ")
159101
export EXTRA_IMAGES=('quay.io/jparrill/registry:3' 'registry.access.redhat.com/rhscl/httpd-24-rhel7:latest' 'quay.io/ztpfw/ui:latest')
102+
160103
# TODO: Change static passwords by dynamic ones
161104
export REG_US=dummy
162105
export REG_PASS=dummy123
@@ -166,28 +109,23 @@ if [[ ${1} == "hub" ]]; then
166109
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
167110
export OPENSHIFT_RELEASE_IMAGE="quay.io/openshift-release-dev/ocp-release:${OC_OCP_TAG}"
168111
export SOURCE_REGISTRY="quay.io"
169-
export SOURCE_INDEX="registry.redhat.io/redhat/redhat-operator-index:v${OC_OCP_VERSION_MIN}"
170-
export CERTIFIED_SOURCE_INDEX="registry.redhat.io/redhat/certified-operator-index:v${OC_OCP_VERSION_MIN}"
112+
export REDHAT_OPERATORS_INDEX="registry.redhat.io/redhat/redhat-operator-index"
113+
export CERTIFIED_OPERATORS_INDEX="registry.redhat.io/redhat/certified-operator-index"
114+
171115
export DESTINATION_REGISTRY="$(oc get configmap --namespace ${REGISTRY} ztpfw-config -o jsonpath='{.data.uri}' | base64 -d)"
172116
# OLM
173117
## NS where the OLM images will be mirrored
174118
export OLM_DESTINATION_REGISTRY_IMAGE_NS=olm
175119
## Image name where the OLM INDEX for RH OPERATORS image will be mirrored
176-
export OLM_DESTINATION_REGISTRY_INDEX_NS=${OLM_DESTINATION_REGISTRY_IMAGE_NS}/redhat-operator-index
177-
## OLM INDEX IMAGE
178-
export OLM_DESTINATION_INDEX="${DESTINATION_REGISTRY}/${OLM_DESTINATION_REGISTRY_INDEX_NS}:v${OC_OCP_VERSION_MIN}"
179-
180-
## NS where the OLM CERTIFIED images will be mirrored
181-
export OLM_CERTIFIED_DESTINATION_REGISTRY_IMAGE_NS=olm
182-
## Image name where the OLM INDEX for RH CERTIFIED OPERATORS image will be mirrored
183-
export OLM_CERTIFIED_DESTINATION_REGISTRY_INDEX_NS=${OLM_CERTIFIED_DESTINATION_REGISTRY_IMAGE_NS}/certified-operator-index
184-
## OLM CERTIFIED INDEX IMAGE
185-
export OLM_CERTIFIED_DESTINATION_INDEX="${DESTINATION_REGISTRY}/${OLM_CERTIFIED_DESTINATION_REGISTRY_INDEX_NS}:v${OC_OCP_VERSION_MIN}"
120+
#export OLM_DESTINATION_REGISTRY_INDEX_NS=${OLM_DESTINATION_REGISTRY_IMAGE_NS}/redhat/redhat-operator-index
121+
export OLM_DESTINATION_REGISTRY_INDEX_NS=ztpfw/redhat/redhat-operator-index
122+
186123
# OCP
187124
## The NS for INDEX and IMAGE will be the same here, this is why there is only 1
188-
export OCP_DESTINATION_REGISTRY_IMAGE_NS=ocp4/openshift4
125+
export OCP_DESTINATION_REGISTRY_IMAGE_NS=ztpfw/openshift/release-images
189126
## OCP INDEX IMAGE
190127
export OCP_DESTINATION_INDEX="${DESTINATION_REGISTRY}/${OCP_DESTINATION_REGISTRY_IMAGE_NS}:${OC_OCP_TAG}"
128+
export OC_MIRROR_DESTINATION_REGISTRY=${DESTINATION_REGISTRY}
191129

192130
elif [[ ${1} == "edgecluster" ]]; then
193131
if [[ ${EDGE_KUBECONFIG:-} == "" ]]; then
@@ -198,7 +136,8 @@ elif [[ ${1} == "edgecluster" ]]; then
198136
echo "HUB: ${KUBECONFIG_HUB}"
199137
echo "EDGE: ${EDGE_KUBECONFIG}"
200138
echo "REGISTRY NS: ${REGISTRY}"
201-
if [[ $(oc get --kubeconfig=${EDGE_KUBECONFIG} ns ${REGISTRY} | wc -l) -gt 0 ]]; then
139+
140+
if [[ $(oc --kubeconfig=${EDGE_KUBECONFIG} get ns | grep ${REGISTRY} | wc -l) -gt 0 && $(oc --kubeconfig=${EDGE_KUBECONFIG} get -n ztpfw-registry deployment ztpfw-registry-quay-app -ojsonpath='{.status.availableReplicas}') -gt 0 ]]; then
202141
echo "Registry NS exists so, we can continue with the workflow"
203142
## Common
204143
## FIX the race condition where the MCO is restarting services and get lost the route query
@@ -227,7 +166,7 @@ elif [[ ${1} == "edgecluster" ]]; then
227166

228167
export OPENSHIFT_RELEASE_IMAGE="$(oc --kubeconfig=${KUBECONFIG_HUB} get clusterimageset --no-headers openshift-v${OC_OCP_VERSION_FULL} -o jsonpath={.spec.releaseImage})"
229168
## The NS for INDEX and IMAGE will be the same here, this is why there is only 1
230-
export OCP_DESTINATION_REGISTRY_IMAGE_NS=ocp4/openshift4
169+
export OCP_DESTINATION_REGISTRY_IMAGE_NS=ztpfw/openshift/release-image
231170
## OCP INDEX IMAGE
232171
export OCP_DESTINATION_INDEX="${DESTINATION_REGISTRY}/${OCP_DESTINATION_REGISTRY_IMAGE_NS}:${OC_OCP_TAG}"
233172

@@ -237,18 +176,14 @@ elif [[ ${1} == "edgecluster" ]]; then
237176
## NS where the OLM images will be mirrored
238177
export OLM_DESTINATION_REGISTRY_IMAGE_NS=olm
239178
## Image name where the OLM INDEX for RH OPERATORS image will be mirrored
240-
export OLM_DESTINATION_REGISTRY_INDEX_NS=${OLM_DESTINATION_REGISTRY_IMAGE_NS}/redhat-operator-index
241-
242-
export SOURCE_INDEX="${SOURCE_REGISTRY}/${OLM_DESTINATION_REGISTRY_INDEX_NS}:v${OC_OCP_VERSION_MIN}"
243-
export OLM_DESTINATION_INDEX="${DESTINATION_REGISTRY}/${OLM_DESTINATION_REGISTRY_INDEX_NS}:v${OC_OCP_VERSION_MIN}"
244-
245-
## NS where the OLM CERTIFIED images will be mirrored
246-
export OLM_CERTIFIED_DESTINATION_REGISTRY_IMAGE_NS=olm
247-
## Image name where the OLM INDEX for RH OPERATORS image will be mirrored
248-
export OLM_CERTIFIED_DESTINATION_REGISTRY_INDEX_NS=${OLM_CERTIFIED_DESTINATION_REGISTRY_IMAGE_NS}/certified-operator-index
249-
250-
export CERTIFIED_SOURCE_INDEX="${SOURCE_REGISTRY}/${OLM_CERTIFIED_DESTINATION_REGISTRY_INDEX_NS}:v${OC_OCP_VERSION_MIN}"
251-
export OLM_CERTIFIED_DESTINATION_INDEX="${DESTINATION_REGISTRY}/${OLM_CERTIFIED_DESTINATION_REGISTRY_INDEX_NS}:v${OC_OCP_VERSION_MIN}"
179+
#export OLM_DESTINATION_REGISTRY_INDEX_NS=${OLM_DESTINATION_REGISTRY_IMAGE_NS}/redhat/redhat-operator-index
180+
export OLM_DESTINATION_REGISTRY_INDEX_NS=ztpfw/redhat/redhat-operator-index
181+
182+
export OC_MIRROR_DESTINATION_REGISTRY=${DESTINATION_REGISTRY}/ztpfw
183+
export REDHAT_OPERATORS_INDEX=$(oc --kubeconfig=${KUBECONFIG_HUB} get catalogsource -n openshift-marketplace redhat-operators -o template={{.spec.image}})
184+
export REDHAT_OPERATORS_INDEX="${REDHAT_OPERATORS_INDEX%%:*}"
185+
export CERTIFIED_OPERATORS_INDEX=$(oc --kubeconfig=${KUBECONFIG_HUB} get catalogsource -n openshift-marketplace certified-operators -o template={{.spec.image}})
186+
export CERTIFIED_OPERATORS_INDEX="${CERTIFIED_OPERATORS_INDEX%%:*}"
252187
fi
253188
fi
254189
fi

0 commit comments

Comments
 (0)