-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_operator_bundles.sh
executable file
·66 lines (51 loc) · 1.9 KB
/
get_operator_bundles.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
CATALOG_IMG="registry.redhat.io/redhat/redhat-operator-index:v4.12"
TMP_DIR="/opt/data/mirror"
MAPPINGS_DIR="operator_mappings"
OC_MIRROR="${OC_MIRROR:-oc-mirror}"
OCP_VERSION="${OCP_VERSION:-4.12}"
OPERATOR_CATALOG="${OPERATOR_CATALOG:-registry.redhat.io/redhat/redhat-operator-index}"
OPERATOR="${OPERATOR:-compliance-operator}"
# No default channel or version is set here because these are different for some operators
# Must be set by the user
#OPERATOR_CHANNEL=""
#OPERATOR_VERSION=""
# Location to store all the mapping.txt file created by oc-mirror
mkdir "${MAPPINGS_DIR}"
# Get all Red Hat Operators and their default channel
if [ ! -e redhat_operators.list ]; then
oc-mirror list operators --catalog=${CATALOG_IMG} > redhat_operators.list
fi
while read -r line
do
OPERATOR=$(echo "${line}" | awk -F\ '{print $1}')
DEFAULT_CHANNEL=$(echo "${line}" | awk -F\ '{print $NF}')
# Skip this process if we already have the mappings file for this operator and channel
if [ -e "${MAPPINGS_DIR}/${OPERATOR}-${DEFAULT_CHANNEL}-mapping.txt" ]; then
continue
fi
echo "Processing: ${OPERATOR} Channel: ${DEFAULT_CHANNEL}"
rm -f /tmp/imageset-config.yaml
rm -rf ${TMP_DIR}
mkdir ${TMP_DIR}
rm -rf archives
cat <<EOF > /tmp/imageset-config.yaml
apiVersion: mirror.openshift.io/v1alpha2
kind: ImageSetConfiguration
storageConfig:
local:
path: ${TMP_DIR}
mirror:
operators:
- catalog: ${CATALOG_IMG}
packages:
- name: ${OPERATOR}
channels:
- name: ${DEFAULT_CHANNEL}
EOF
oc-mirror --config /tmp/imageset-config.yaml --dest-skip-tls --continue-on-error --dry-run file://archives
mv ./archives/oc-mirror-workspace/mapping.txt "${MAPPINGS_DIR}/${OPERATOR}-${DEFAULT_CHANNEL}-mapping.txt"
done < <(tail -n +2 redhat_operators.list) # Ship column names on first line
# Remove the right side of the mapping we don't need
sed -i 's/=.*//' ${MAPPINGS_DIR}/*.txt
exit 0