1
1
#! /usr/bin/env bash
2
2
3
- declare CONFIGS_DIR
4
- declare CERT_MANAGER_OPERATOR_IMAGE
5
- declare CERT_MANAGER_OPERATOR_BUNDLE_IMAGE
6
- declare CERT_MANAGER_IMAGE
7
- declare CERT_MANAGER_ACMESOLVER_IMAGE
8
- declare KUBE_RBAC_PROXY_IMAGE
3
+ #
4
+ # Example usage:
5
+ # ./update_catalog.sh ./bin/tools/opm \
6
+ # registry.stage.redhat.io/cert-manager/cert-manager-operator-bundle@sha256:4114321b0ab6ceb882f26501ff9b22214d90b83d92466e7c5a62217f592c1fed \
7
+ # catalogs/v4.17/catalog \
8
+ # bundle-v1.15.0.yaml \
9
+ # yes \
10
+ # yes
11
+ #
9
12
10
- CATALOG_MANIFEST_FILE_NAME=" catalog.yaml"
13
+ declare OPM_TOOL_PATH
14
+ declare OPERATOR_BUNDLE_IMAGE
15
+ declare CATALOG_DIR
16
+ declare BUNDLE_FILE_NAME
17
+ declare REPLICATE_BUNDLE_FILE_IN_CATALOGS
18
+ declare USE_MIGRATE_LEVEL_FLAG
11
19
12
- update_catalog_manifest ()
13
- {
14
- CATALOG_MANIFEST_FILE=" ${CONFIGS_DIR} /${CATALOG_MANIFEST_FILE_NAME} "
15
- if [[ ! -f " ${CATALOG_MANIFEST_FILE} " ]]; then
16
- echo " [$( date) ] -- ERROR -- catalog manifest file \" ${CATALOG_MANIFEST_FILE} \" does not exist"
17
- exit 1
18
- fi
19
-
20
- # # replace cert-manager operand related images
21
- sed -i " s#registry.redhat.io/cert-manager/jetstack-cert-manager-rhel9.*#${CERT_MANAGER_IMAGE} #g" " ${CATALOG_MANIFEST_FILE} "
22
- sed -i " s#registry.redhat.io/cert-manager/jetstack-cert-manager-acmesolver-rhel9.*#${CERT_MANAGER_ACMESOLVER_IMAGE} #g" " ${CATALOG_MANIFEST_FILE} "
20
+ CERT_MANAGER_CATALOG_NAME=" openshift-cert-manager-operator"
23
21
24
- # # replace cert-manager-operator image
25
- sed -i " s#registry.redhat.io/cert-manager/cert-manager-operator-rhel9.*#${CERT_MANAGER_OPERATOR_IMAGE} #g" " ${CATALOG_MANIFEST_FILE} "
22
+ render_catalog_bundle ()
23
+ {
24
+ render_cmd_args=" "
25
+ # --migrate-level=bundle-object-to-csv-metadata is used for creating bundle metadata in `olm.csv.metadata` format.
26
+ # Refer https://github.com/konflux-ci/build-definitions/blob/main/task/fbc-validation/0.1/TROUBLESHOOTING.md for details.
27
+ if [[ ${USE_MIGRATE_LEVEL_FLAG} == " yes" ]]; then
28
+ render_cmd_args=" --migrate-level=bundle-object-to-csv-metadata"
29
+ fi
26
30
27
- # # replace cert-manager-operator-bundle image
28
- sed -i " s#registry.redhat.io/cert-manager/cert-manager-operator-bundle.*#${CERT_MANAGER_OPERATOR_BUNDLE_IMAGE} #g" " ${CATALOG_MANIFEST_FILE} "
31
+ bundle_file=" ${CATALOG_DIR} /${CERT_MANAGER_CATALOG_NAME} /${BUNDLE_FILE_NAME} "
32
+ echo " [$( date) ] -- INFO -- generating catalog bundle \" ${bundle_file} \" "
33
+ if ! " ${OPM_TOOL_PATH} " render " ${OPERATOR_BUNDLE_IMAGE} " $render_cmd_args -o yaml > " ${bundle_file} " ; then
34
+ echo " [$( date) ] -- ERROR -- failed to render catalog bundle"
35
+ exit 1
36
+ fi
29
37
30
- # # replace kube-rbac-proxy image
31
- sed -i " s#registry.redhat.io/openshift4/ose-kube-rbac-proxy-rhel9.*#${KUBE_RBAC_PROXY_IMAGE} #g" " ${CATALOG_MANIFEST_FILE} "
38
+ if ! " ${OPM_TOOL_PATH} " validate " ${CATALOG_DIR} " ; then
39
+ echo " [$( date) ] -- ERROR -- failed to validate catalog"
40
+ exit 1
41
+ fi
32
42
}
33
43
34
44
usage ()
35
45
{
36
46
echo -e " usage:\n\t$( basename " ${BASH_SOURCE[0]} " ) " \
37
- ' "<CATALOG_CONFIG_DIR >"' \
38
- ' "<CERT_MANAGER_OPERATOR_IMAGE >"' \
39
- ' "<CERT_MANAGER_OPERATOR_BUNDLE_IMAGE >"' \
40
- ' "<CERT_MANAGER_IMAGE >"' \
41
- ' "<CERT_MANAGER_ACMESOLVER_IMAGE >"' \
42
- ' "<KUBE_RBAC_PROXY_IMAGE >"'
47
+ ' "<OPM_TOOL_PATH >"' \
48
+ ' "<OPERATOR_BUNDLE_IMAGE >"' \
49
+ ' "<CATALOG_DIR >"' \
50
+ ' "<BUNDLE_FILE_NAME >"' \
51
+ ' "<REPLICATE_BUNDLE_FILE_IN_CATALOGS >"' \
52
+ ' "<USE_MIGRATE_LEVEL_FLAG >"'
43
53
exit 1
44
54
}
45
55
56
+ replicate_catalog_bundle ()
57
+ {
58
+ if [[ " ${REPLICATE_BUNDLE_FILE_IN_CATALOGS} " == " no" ]]; then
59
+ return
60
+ fi
61
+
62
+ bundle_file=" ${CATALOG_DIR} /${CERT_MANAGER_CATALOG_NAME} /${BUNDLE_FILE_NAME} "
63
+
64
+ find catalogs/* /catalog/openshift-cert-manager-operator -type d ! -path " ${CATALOG_DIR} /*" -exec /bin/cp " ${bundle_file} " {} \; -print
65
+ }
66
+
46
67
# #############################################
47
68
# ############## MAIN #######################
48
69
# #############################################
@@ -51,20 +72,42 @@ if [[ $# -ne 6 ]]; then
51
72
usage
52
73
fi
53
74
54
- CONFIGS_DIR =$1
55
- CERT_MANAGER_OPERATOR_IMAGE =$2
56
- CERT_MANAGER_OPERATOR_BUNDLE_IMAGE =$3
57
- CERT_MANAGER_IMAGE =$4
58
- CERT_MANAGER_ACMESOLVER_IMAGE =$5
59
- KUBE_RBAC_PROXY_IMAGE =$6
75
+ OPM_TOOL_PATH =$1
76
+ OPERATOR_BUNDLE_IMAGE =$2
77
+ CATALOG_DIR =$3
78
+ BUNDLE_FILE_NAME =$4
79
+ REPLICATE_BUNDLE_FILE_IN_CATALOGS =$5
80
+ USE_MIGRATE_LEVEL_FLAG =$6
60
81
61
82
echo " [$( date) ] -- INFO -- $* "
62
83
63
- if [[ ! -d ${CONFIGS_DIR} ]]; then
64
- echo " [$( date) ] -- ERROR -- manifests directory \" ${MANIFESTS_DIR } \" does not exist"
84
+ if [[ ! -d " ${CATALOG_DIR} " ]]; then
85
+ echo " [$( date) ] -- ERROR -- catalog directory \" ${CATALOG_DIR } \" does not exist"
65
86
exit 1
66
87
fi
67
88
68
- update_catalog_manifest
89
+ if [[ ! -x " ${OPM_TOOL_PATH} " ]]; then
90
+ echo " [$( date) ] -- ERROR -- \" ${OPM_TOOL_PATH} \" does not exist or does not execute permissions"
91
+ exit 1
92
+ fi
93
+
94
+ if [[ -z " ${BUNDLE_FILE_NAME} " ]]; then
95
+ echo " [$( date) ] -- ERROR -- \"\" bundle file name cannot be empty"
96
+ exit 1
97
+ fi
98
+
99
+ if [[ -z " ${REPLICATE_BUNDLE_FILE_IN_CATALOGS} " ]] || [[ " ${REPLICATE_BUNDLE_FILE_IN_CATALOGS} " != @ (yes| no) ]]; then
100
+ echo " [$( date) ] -- ERROR -- invalid value provided for \" REPLICATE_BUNDLE_FILE_IN_CATALOGS\" , must be \" yes\" or \" no\" "
101
+ exit 1
102
+ fi
103
+
104
+ if [[ -z " ${USE_MIGRATE_LEVEL_FLAG} " ]] || [[ " ${USE_MIGRATE_LEVEL_FLAG} " != @ (yes| no) ]]; then
105
+ echo " [$( date) ] -- ERROR -- invalid value provided for \" USE_MIGRATE_LEVEL_FLAG\" , must be \" yes\" or \" no\" "
106
+ exit 1
107
+ fi
108
+
109
+ render_catalog_bundle
110
+
111
+ replicate_catalog_bundle
69
112
70
113
exit 0
0 commit comments