This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
install_ocp.sh
executable file
·383 lines (321 loc) · 11 KB
/
install_ocp.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/bin/bash
# ====================================================
# Standalone script for deploying syndesis on OCP (including imagestreams)
# Exit if any error occurs
# Fail on a single failed command in a pipeline (if supported)
set -o pipefail
# Fail on error and undefined vars (please don't use global vars, but evaluation of functions for return values)
set -eu
# Save global script args
ARGS=("$@")
# Helper functions:
# Dir where this script is located
basedir() {
# Default is current directory
local script=${BASH_SOURCE[0]}
# Resolve symbolic links
if [ -L $script ]; then
if readlink -f $script >/dev/null 2>&1; then
script=$(readlink -f $script)
elif readlink $script >/dev/null 2>&1; then
script=$(readlink $script)
elif realpath $script >/dev/null 2>&1; then
script=$(realpath $script)
else
echo "ERROR: Cannot resolve symbolic link $script"
exit 1
fi
fi
local dir=$(dirname "$script")
local full_dir=$(cd "${dir}" && pwd)
echo ${full_dir}
}
# Checks if a flag is present in the arguments.
hasflag() {
filters="$@"
if [[ ! -z ${ARGS+x} ]]; then
for var in "${ARGS[@]}"; do
for filter in $filters; do
if [ "$var" = "$filter" ]; then
echo 'true'
return
fi
done
done
fi
}
# Read the value of an option.
readopt() {
filters="$@"
if [[ ! -z ${ARGS+x} ]]; then
next=false
for var in "${ARGS[@]}"; do
if $next; then
echo $var
break;
fi
for filter in $filters; do
if [[ "$var" = ${filter}* ]]; then
local value="${var//${filter}=/}"
if [ "$value" != "$var" ]; then
echo $value
return
fi
next=true
fi
done
done
fi
}
# Getting base dir
BASEDIR=$(basedir)
# Get configuration and other scripts
pushd > /dev/null . && cd "${BASEDIR}"
source "$BASEDIR/base_functions.sh"
source "$BASEDIR/common_config.sh"
source "$BASEDIR/libs/download_functions.sh"
source "$BASEDIR/libs/openshift_functions.sh"
popd > /dev/null
DEFAULT_CR_FILE="$BASEDIR/default-cr.yml"
SYNDESIS_CLI=$(get_syndesis_bin)
check_error $SYNDESIS_CLI
display_usage() {
cat <<EOT
Fuse Online Installation Tool for OCP
Usage: install_ocp.sh [options]
with options:
-s --setup Install CRDs clusterwide. Use --grant if you want a specific user to be
able to install Fuse Online. You have to run this option once as cluster admin.
-u --grant <user> Add permissions for the given user so that user can install the operator
in her projects. You have to run this as cluster-admin
--cluster Add the permission for all projects in the cluster
(only when used together with --grant)
--force Override an existing installation if present
-p --project <project> Install into this project. The project will be deleted
if it already exists. By default, install into the current project (without deleting)
--skip-pull-secret Skip the creation of the pull-secret. By default, will create or replace the pull-secret.
-w --watch Wait until the installation has completed
-o --open Open Fuse Online after installation (implies --watch)
(version is optional)
--help This help message
-v --verbose Verbose logging
You have to run "--setup --grant <user>" as a cluster-admin before you can install Fuse Online as a user.
If there is no oc command on the PATH and there is minishift, it uses the oc command from the minishift installation.
EOT
}
# ============================================================
open_url() {
local url=$1
local cmd="$(probe_commands open xdg-open chrome firefox)"
if [ -z "$cmd" ]; then
echo "Cannot find command for opening URL:"
echo $url
exit 1
fi
exec $cmd $url
}
probe_commands() {
for cmd in $@; do
local ret=$(which $cmd 2>/dev/null)
if [ $? -eq 0 ]; then
echo $ret
return
fi
done
}
get_route_when_ready() {
local name="${1}"
local route=$(get_route $name)
while [ -z "$route" ]; do
sleep 10
route=$(get_route $name)
done
echo $route
}
get_route() {
local name="${1}"
oc get route $name -o jsonpath="{.spec.host}" 2>/dev/null
}
grant_role() {
local user_to_prepare="$1"
if [ -z "$user_to_prepare" ]; then
check_error "ERROR: Cannot perform grant as no user specified"
fi
echo "Grant syndesis-installer role to user $user_to_prepare"
#
# Check that the user calling --grant is a cluster-admin
#
if [ $(is_cluster_admin) != "OK" ]; then
check_error "ERROR: Can only execute --grant as cluster-admin."
fi
clusterwide=""
if [ $(hasflag --cluster) ]; then
clusterwide="--cluster"
fi
set +e
$SYNDESIS_CLI grant --user "$user_to_prepare" $clusterwide
set -e
}
# ==============================================================
if [ $(hasflag --help -h) ]; then
display_usage
exit 0
fi
if [ $(hasflag --verbose -v) ]; then
export PS4='+($(basename ${BASH_SOURCE[0]}):${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -x
fi
#
# Check for oc
#
err=$(setup_oc)
check_error $err
#
# Is the user executing this a cluster-admin?
#
cluster_admin=$(is_cluster_admin)
if [ "${cluster_admin}" == "OK" ]; then
echo "User $(oc whoami) is a cluster-admin"
fi
#
# If a project is given, only a cluster-admin
# can create it new or recreate it
#
project=$(readopt --project -p)
if [ -n "${project}" ]; then
if [ "$cluster_admin" == "OK" ]; then
recreate_project $project
else
check_error "ERROR: It is not possible to install into a new (or recreated) project without being a cluster-admin since artifacts required by the install cannot be (re)created."
fi
fi
prep_only="false"
if [ $(hasflag -s --setup) ]; then
echo "Installing Syndesis CRD"
#
# Check that the user calling --setup is a cluster-admin
#
if [ "$cluster_admin" != "OK" ]; then
check_error "ERROR: Can only execute --setup as cluster-admin."
fi
$SYNDESIS_CLI install cluster
prep_only="true"
fi
user_to_prepare="$(readopt -u --grant)"
if [ -n "$user_to_prepare" ]; then
grant_role "$user_to_prepare"
prep_only="true"
fi
if $prep_only; then
exit 0
fi
# ===========================
#
# Do some pre-flight install checks
#
# ===========================
#
# make sure pull secret is present (required since 7.3)
#
if [ ! $(hasflag --skip-pull-secret) ]; then
create_or_replace_secret
fi
#
# If a cluster-admin and the role has not yet been granted
# then ensure it is by grant it to the current user
#
if [ "$cluster_admin" == "OK" ]; then
if [ "$(is_role_granted)" != "OK" ]; then
echo "No syndesis-installer role has been granted so installing now"
grant_role "$(oc whoami)"
fi
fi
#
# Check that user has syndesis-installer role available
#
result=$(is_role_granted)
check_error "$result"
#
# Check CRD installed
#
set +e
oc get syndesis >/dev/null 2>&1
if [ $? -ne 0 ]; then
check_error "ERROR: No CRD Syndesis installed or no permissions to read them. Please run --setup and/or --grant as cluster-admin. Please use '--help' for more information."
fi
set -e
# Deploy operator and wait until its up
echo "Deploying Syndesis operator"
$SYNDESIS_CLI install operator --tag 1.9
set +e
oc scale deployment syndesis-operator --replicas 0
result=$(oc secrets link syndesis-operator syndesis-pull-secret --for=pull >$ERROR_FILE 2>&1)
check_error $result
if [ $(is_ocp3) == "true" ]; then
oc set env deployment/syndesis-operator RELATED_IMAGE_PROMETHEUS='registry.redhat.io/openshift3/prometheus:v3.9'
fi
#Hotfix for ENTESB-
oc set env deployment/syndesis-operator RELATED_IMAGE_UI=registry.redhat.io/fuse7/fuse-online-ui-rhel8:1.9
oc set env deployment/syndesis-operator RELATED_IMAGE_S2I=registry.redhat.io/fuse7/fuse-online-builder-rhel8:1.9
oc set env deployment/syndesis-operator RELATED_IMAGE_UPGRADE=registry.redhat.io/fuse7/fuse-online-upgrade-rhel8:1.9
oc set env deployment/syndesis-operator RELATED_IMAGE_META=registry.redhat.io/fuse7/fuse-online-meta-rhel8:1.9
oc set env deployment/syndesis-operator RELATED_IMAGE_PSQL_EXPORTER=registry.redhat.io/fuse7/fuse-postgres-exporter-rhel8:1.9
oc set env deployment/syndesis-operator RELATED_IMAGE_SERVER=registry.redhat.io/fuse7/fuse-online-server-rhel8:1.9
oc scale deployment syndesis-operator --replicas 1
set -e
# Wait for deployment
wait_for_deployments deployment 1 syndesis-operator
# Check syndesis cr already installed. If force then remove first.
syndesis_installed=$(oc get syndesis -o name | wc -l)
force=$(hasflag --force)
if [ $syndesis_installed -gt 0 ]; then
echo "Warning ... Syndesis custom resource already installed: '${syndesis_installed}'"
if [ -n "${force}" ]; then
echo "Removing already installed Syndesis custom resource"
oc delete $(oc get syndesis -o name)
fi
fi
# Create syndesis resource
echo "Creating Syndesis with fuse-online resource"
if [ ! -f "${DEFAULT_CR_FILE}" ]; then
echo "Cannot custom-resource file '$DEFAULT_CR_FILE' ... exiting."
exit 1
fi
set +e
result=$($SYNDESIS_CLI install app --custom-resource ${DEFAULT_CR_FILE})
check_error $result
set -e
jaeger_enabled=$(oc get syndesis app -o jsonpath='{.spec.addons.jaeger.enabled}')
check_error $jaeger_enabled
if [ "$jaeger_enabled" == "true" ]; then
# on OCP 4 the jaeger-operator is installed from operatorhub on openshift-operator namespace
# in that case there is no need to set secrets for it
if [ $(is_ocp3) == "true" ]; then
wait_for sa jaeger-operator
result=$(oc secrets link jaeger-operator syndesis-pull-secret --for=pull)
check_error $result
# workaround as the previous "oc secrets link" doesn't trigger a pod restart
oc delete `oc get -o name pod -l name=jaeger-operator`
wait_for sa syndesis-jaeger-ui-proxy
result=$(oc secrets link syndesis-jaeger-ui-proxy syndesis-pull-secret --for=pull)
check_error $result
# workaround as the previous "oc secrets link" doesn't trigger a pod restart
oc delete `oc get -o name pod -l app.kubernetes.io/name=syndesis-jaeger`
fi
fi
if [ $(hasflag --watch -w) ] || [ $(hasflag --open -o) ]; then
wait_for_deployments dc 1 syndesis-server syndesis-ui syndesis-meta
fi
# ==========================================================
echo "Getting Syndesis route"
route=$(get_route_when_ready "syndesis")
cat <<EOT
========================================================
Congratulation, Fuse Online $TAG has been installed successfully !
Open now your browser at the following URL:
https://$route
Enjoy !
EOT
if [ $(hasflag --open -o) ]; then
open_url "https://$route"
fi