Skip to content

Commit f0d8b69

Browse files
saumeyavarshab1210
andauthored
feat: add script for installing nightly olm operator (#604)
* olm nightly install script fix fix fix fix fix fix Signed-off-by: saumeya <[email protected]> update ns Signed-off-by: saumeya <[email protected]> add operator group Signed-off-by: saumeya <[email protected]> review changes Signed-off-by: saumeya <[email protected]> add operator group Signed-off-by: saumeya <[email protected]> fixes Signed-off-by: saumeya <[email protected]> * fix Signed-off-by: saumeya <[email protected]> --------- Signed-off-by: saumeya <[email protected]> Co-authored-by: Varsha B <[email protected]>
1 parent 391e26f commit f0d8b69

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

hack/scripts/olm-nightly-install.sh

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env bash
2+
3+
# To run the script , you have to export the IIB_ID like so
4+
# export IIB_ID=581525
5+
6+
# There are 2 options '-i' and '-m' (for first install on the cluster or for migrating to nightly) that you have to provide
7+
#./olm-install-script -i
8+
# or
9+
#./olm-install-script -m
10+
11+
set -e
12+
13+
if [ ! ${IIB_ID} ] ;
14+
then
15+
echo -e "\nPlease set the environment variable IIB_ID\n"
16+
exit
17+
fi
18+
19+
20+
REGISTRY_NAME=${OPERATOR_REGISTRY:-"brew.registry.redhat.io/rh-osbs"}
21+
REPO_NAME=${REPO_NAME:-"iib"}
22+
23+
INDEX="${REGISTRY_NAME}/${REPO_NAME}:$IIB_ID"
24+
25+
echo "INDEX IMAGE:- $INDEX"
26+
27+
#patch to disable default catalog source
28+
oc patch operatorhub.config.openshift.io/cluster -p='{"spec":{"disableAllDefaultSources":true}}' --type=merge
29+
30+
# apply image content source policy
31+
32+
cat << EOF | oc apply -f -
33+
apiVersion: operator.openshift.io/v1alpha1
34+
kind: ImageContentSourcePolicy
35+
metadata:
36+
name: brew-registry
37+
spec:
38+
repositoryDigestMirrors:
39+
- mirrors:
40+
- brew.registry.redhat.io
41+
source: registry.redhat.io
42+
- mirrors:
43+
- brew.registry.redhat.io
44+
source: registry.stage.redhat.io
45+
- mirrors:
46+
- brew.registry.redhat.io
47+
source: registry-proxy.engineering.redhat.com
48+
EOF
49+
50+
# apply catalog source
51+
cat << EOF | oc apply -f -
52+
apiVersion: operators.coreos.com/v1alpha1
53+
kind: CatalogSource
54+
metadata:
55+
name: redhat-operators
56+
namespace: openshift-marketplace
57+
spec:
58+
displayName: ''
59+
image: ${INDEX}
60+
publisher: ''
61+
sourceType: grpc
62+
EOF
63+
64+
# Wait for the Catalog source to be ready
65+
i=0
66+
until [ $(oc get catalogsource -n openshift-marketplace -o jsonpath="{.items[0].status.connectionState.lastObservedState}") = "READY" ]
67+
do
68+
echo "Waiting for the catalog source to be in READY state"
69+
i=`expr $i + 1`
70+
sleep 10
71+
if [[ $i -eq 20 ]];
72+
then
73+
echo "Catalog source not READY"
74+
oc patch operatorhub.config.openshift.io/cluster -p='{"spec":{"disableAllDefaultSources":false}}' --type=merge
75+
exit
76+
fi
77+
done
78+
79+
# install nightly operator on fresh cluster
80+
81+
function apply_subscription() {
82+
83+
# create namespace
84+
oc create ns openshift-gitops-operator
85+
86+
# create OperatorGroup
87+
cat << EOF | oc apply -f -
88+
apiVersion: operators.coreos.com/v1
89+
kind: OperatorGroup
90+
metadata:
91+
name: gitops-operator-group
92+
namespace: openshift-gitops-operator
93+
spec: {}
94+
EOF
95+
96+
#create Subscription
97+
cat << EOF | oc apply -f -
98+
apiVersion: operators.coreos.com/v1alpha1
99+
kind: Subscription
100+
metadata:
101+
name: openshift-gitops-operator
102+
namespace: openshift-gitops-operator
103+
spec:
104+
channel: nightly
105+
installPlanApproval: Automatic
106+
name: openshift-gitops-operator
107+
source: redhat-operators
108+
sourceNamespace: openshift-marketplace
109+
EOF
110+
111+
}
112+
113+
key=$1
114+
115+
case $key in
116+
-i)
117+
echo "Installing Nightly Operator"
118+
apply_subscription
119+
;;
120+
-m)
121+
122+
echo "Migrating to Nightly Operator"
123+
124+
#patch the channel to nightly for automatic upgrade
125+
oc patch subscription openshift-gitops-operator -n openshift-gitops-operator --type='merge' -p='{"spec":{"channel": "nightly"}}'
126+
;;
127+
*)
128+
echo "[ERROR] Invalid argument $key"
129+
exit 1
130+
;;
131+
esac
132+
133+
# Wait for the operator to upgrade
134+
NEW_VER="99.9.0"
135+
NEW_BUILD="openshift-gitops-operator.v$NEW_VER"
136+
until [[ $(oc get csv -n openshift-operators -o name) == *"$NEW_BUILD"* ]];
137+
do
138+
echo "Operator upgrading..."
139+
sleep 10
140+
if [[ $(oc get csv -n openshift-operators -o name) == *"$NEW_BUILD"* ]]; then
141+
break
142+
fi
143+
done
144+
echo -e "\nOperator upgraded, Waiting for the pods to come up"
145+
146+
# Establish some time for the pods to refresh
147+
sleep 30
148+
149+
# Wait for the deployments to be successfully rolled out
150+
deployments=($(echo $(oc get deployments -n openshift-gitops --no-headers -o custom-columns=':metadata.name')))
151+
for deployment in "${deployments[@]}"; do
152+
oc rollout status deployment/"${deployment}" -n openshift-gitops --timeout=60s
153+
done
154+
155+
echo -e "\nProvide cluster-admin access to argocd-application-controller service account"
156+
oc adm policy add-cluster-role-to-user cluster-admin system:serviceaccount:openshift-gitops:openshift-gitops-argocd-application-controller
157+
158+
# Re-enable the default Catalog Sources after the upgrade testing
159+
oc patch operatorhub.config.openshift.io/cluster -p='{"spec":{"disableAllDefaultSources":false}}' --type=merge

0 commit comments

Comments
 (0)