1
+ #! /bin/bash
2
+ #
3
+ # Copyright 2021 IBM Corporation
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ # counter to keep track of installation steps
19
+ STEP=0
20
+
21
+ # script base directory
22
+ BASE_DIR=$( dirname " $0 " )
23
+
24
+ # ---------- Command functions ----------
25
+ . ${BASE_DIR} /utils.sh
26
+
27
+ function main() {
28
+ title " Moving to CatalogSource ibm-operator-catalog"
29
+ msg " "
30
+ check_preqreqs
31
+ switch_to_ibmcatalog
32
+ }
33
+
34
+
35
+ function check_preqreqs() {
36
+ title " [${STEP} ] Checking prerequesites ..."
37
+ msg " -----------------------------------------------------------------------"
38
+
39
+ # checking oc command
40
+ if [[ -z " $( command -v oc 2> /dev/null) " ]]; then
41
+ error " oc command not available"
42
+ else
43
+ success " oc command available"
44
+ fi
45
+
46
+ # checking oc command logged in
47
+ user=$( oc whoami 2> /dev/null)
48
+ if [ $? -ne 0 ]; then
49
+ error " You must be logged into the OpenShift Cluster from the oc command line"
50
+ else
51
+ success " oc command logged in as ${user} "
52
+ fi
53
+
54
+ # checking ibm catalogsource is existing
55
+ catalog=$( oc -n openshift-marketplace get pod | grep ibm-operator-catalog 2> /dev/null)
56
+ if [$? -ne 0]; then
57
+ error " You must deploy CatalofSource ${catalog} first"
58
+ else
59
+ success " CatalogSource ${catalog} is deployed"
60
+ fi
61
+ }
62
+
63
+ function switch_to_ibmcatalog() {
64
+ STEP=$(( STEP + 1 ))
65
+
66
+ title " [${STEP} ] Switch to IBM Operator Catalog Source ..."
67
+ msg " -----------------------------------------------------------------------"
68
+
69
+ while read -r ns cssub; do
70
+ msg " Updating subscription ${cssub} in namespace ${ns} ..."
71
+ msg " "
72
+
73
+ in_step=1
74
+ msg " [${in_step} ] Removing the startingCSV ..."
75
+ oc patch sub ${cssub} -n ${ns} --type=" json" -p ' [{"op": "remove", "path":"/spec/startingCSV"}]' 2> /dev/null
76
+
77
+ in_step=$(( in_step + 1 ))
78
+ msg " [${in_step} ] Switch Channel from stable-v1 to v3 ..."
79
+ oc patch sub ${cssub} -n ${ns} --type=" json" -p ' [{"op": "replace", "path":"/spec/channel", "value":"v3"}]' 2> /dev/null
80
+
81
+ in_step=$(( in_step + 1 ))
82
+ msg " [${in_step} ] Switch CatalogSource from opencloud-operators to ibm-operator-catalog ..."
83
+ oc patch sub ${cssub} -n ${ns} --type=" json" -p ' [{"op": "replace", "path":"/spec/source", "value":"ibm-operator-catalog"}]' 2> /dev/null
84
+ msg " -----------------------------------------------------------------------"
85
+ msg " "
86
+ done < <( oc get sub --all-namespaces | grep ibm-common-service-operator | awk ' {print $1" "$2}' )
87
+
88
+ success " Update all ibm-common-service-operator subscriptions successfully"
89
+ }
90
+ # --- Run ---
91
+
92
+ main $*
0 commit comments