forked from borball/sno-agent-based-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sno-iso.sh
executable file
·439 lines (376 loc) · 15.8 KB
/
sno-iso.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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
#!/bin/bash
#
# Helper script to generate bootable ISO with OpenShift agent based installer
# usage: ./sno-iso.sh -h
#
if ! type "yq" > /dev/null; then
echo "Cannot find yq in the path, please install yq on the node first. ref: https://github.com/mikefarah/yq#install"
fi
if ! type "jinja2" > /dev/null; then
echo "Cannot find jinja2 in the path, will install it with pip3 install jinja2-cli and pip3 install jinja2-cli[yaml]"
pip3 install --user jinja2-cli
pip3 install --user jinja2-cli[yaml]
fi
info(){
printf $(tput setaf 2)"%-56s %-10s"$(tput sgr0)"\n" "$@"
}
warn(){
printf $(tput setaf 3)"%-56s %-10s"$(tput sgr0)"\n" "$@"
}
usage(){
info "Usage: $0 [config file] [ocp version]"
info "config file and ocp version are optional, examples:"
info "- $0 sno130.yaml" " equals: $0 sno130.yaml stable-4.14"
info "- $0 sno130.yaml 4.14.33"
echo
info "Prepare a configuration file by following the example in config.yaml.sample"
echo "-----------------------------------"
echo "# content of config.yaml.sample"
cat config.yaml.sample
echo
echo "-----------------------------------"
echo
info "Example to run it: $0 config-sno130.yaml"
echo
}
if [ $# -lt 1 ]
then
usage
exit
fi
if [[ ( $@ == "--help") || $@ == "-h" ]]
then
usage
exit
fi
basedir="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
templates=$basedir/templates
operators=$basedir/operators
config_file_input=$1; shift
ocp_release=$1; shift
if [ -z "$config_file_input" ]
then
config_file_input=config.yaml
fi
cluster_name=$(yq '.cluster.name' $config_file_input)
cluster_workspace=$basedir/instances/$cluster_name
if [[ -d "${cluster_workspace}" ]]; then
echo "${cluster_workspace} already exists, please delete the folder ${cluster_workspace} and re-run the script."
exit -1
fi
echo "Creating workspace: ${cluster_workspace}."
mkdir -p $cluster_workspace
mkdir -p $cluster_workspace/openshift
if [ -z "$ocp_release" ]
then
ocp_release='stable-4.14'
fi
ocp_release_version=$(curl -s https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/${ocp_release}/release.txt | grep 'Version:' | awk -F ' ' '{print $2}')
#if release not available on mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/, probably ec (early candidate) version, or nightly/ci build.
if [ -z $ocp_release_version ]; then
ocp_release_version=$ocp_release
fi
export ocp_y_release=$(echo $ocp_release_version |cut -d. -f1-2)
export OCP_Y_VERSION=$ocp_y_release
export OCP_Z_VERSION=$ocp_release_version
config_file="$cluster_workspace/config-resolved.yaml"
if [ $(cat $config_file_input |grep -E 'OCP_Y_RELEASE|OCP_Z_RELEASE' |wc -l) -gt 0 ]; then
sed "s/OCP_Y_RELEASE/$ocp_y_release/g;s/OCP_Z_RELEASE/$ocp_release_version/g" $config_file_input > $config_file
else
cp $config_file_input $config_file
fi
echo "Will use $config_file as the configuration in other sno-* scripts."
echo "You are going to download OpenShift installer $ocp_release: ${ocp_release_version}"
if [ ! -f $basedir/openshift-install-linux.$ocp_release_version.tar.gz ]; then
status_code=$(curl -s -o /dev/null -w "%{http_code}" https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/$ocp_release_version/)
if [ $status_code = "200" ]; then
curl -L https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/${ocp_release_version}/openshift-install-linux.tar.gz -o $basedir/openshift-install-linux.$ocp_release_version.tar.gz
if [[ $? -eq 0 ]]; then
tar zxf $basedir/openshift-install-linux.$ocp_release_version.tar.gz -C $basedir openshift-install
else
rm -f $basedir/openshift-install-linux.$ocp_release_version.tar.gz
exit -1
fi
else
#fetch from image
if [[ $ocp_release == *"nightly"* ]] || [[ $ocp_release == *"ci"* ]]; then
oc adm release extract --command=openshift-install registry.ci.openshift.org/ocp/release:$ocp_release_version --registry-config=$(yq '.pull_secret' $config_file) --to="$basedir"
else
oc adm release extract --command=openshift-install quay.io/openshift-release-dev/ocp-release:$ocp_release_version-x86_64 --registry-config=$(yq '.pull_secret' $config_file) --to="$basedir"
fi
fi
else
tar zxf $basedir/openshift-install-linux.$ocp_release_version.tar.gz -C $basedir openshift-install
fi
day1_config(){
if [ "false" = "$(yq '.day1.workload_partition' $config_file)" ]; then
warn "Workload partitioning:" "disabled"
else
if [ "4.12" = "$ocp_y_release" ] || [ "4.13" = "$ocp_y_release" ]; then
info "Workload partitioning:" "enabled"
export crio_wp=$(jinja2 $templates/day1/workload-partition/crio.conf $config_file |base64 -w0)
export k8s_wp=$(jinja2 $templates/day1/workload-partition/kubelet.conf $config_file |base64 -w0)
jinja2 $templates/day1/workload-partition/02-master-workload-partitioning.yaml.j2 $config_file > $cluster_workspace/openshift/02-master-workload-partitioning.yaml
else
info "Workload partitioning:" "enabled(through install-config)"
fi
fi
if [ "false" = "$(yq '.day1.boot_accelerate' $config_file)" ]; then
warn "SNO boot accelerate:" "disabled"
else
info "SNO boot accelerate:" "enabled"
cp $templates/day1/accelerate/*.yaml $cluster_workspace/openshift/
if [ "4.12" = "$ocp_y_release" ] || [ "4.13" = "$ocp_y_release" ]; then
cp $templates/day1/accelerate/$ocp_y_release/*.yaml $cluster_workspace/openshift/
else
cp $templates/day1/accelerate/4.14-above/*.yaml $cluster_workspace/openshift/
fi
fi
if [ "false" = "$(yq '.day1.kdump.enabled' $config_file)" ]; then
warn "kdump service:" "disabled"
else
if [ "true" = "$(yq '.day1.kdump.secure_boot' $config_file)" ]; then
info "kdump service(secure boot):" "enabled"
cp $templates/day1/kdump/06-kdump-master-secureboot.yaml $cluster_workspace/openshift/
else
info "kdump service:" "enabled"
cp $templates/day1/kdump/06-kdump-master.yaml $cluster_workspace/openshift/
fi
fi
if [ "true" = "$(yq '.day1.kdump.blacklist_ice' $config_file)" ]; then
info "kdump, blacklist_ice(for HPE):" "enabled"
cp $templates/day1/kdump/05-kdump-config-master.yaml $cluster_workspace/openshift/
else
warn "kdump, blacklist_ice(for HPE):" "disabled"
fi
if [ "4.12" = $ocp_y_release ]; then
warn "Container runtime crun(4.13+):" "disabled"
else
#4.13+ by default enabled.
if [ "false" = "$(yq '.day1.crun' $config_file)" ]; then
warn "Container runtime crun(4.13+):" "disabled"
else
info "Container runtime crun(4.13+):" "enabled"
cp $templates/day1/crun/*.yaml $cluster_workspace/openshift/
fi
fi
# 4.14+ specific
if [ "4.12" = $ocp_y_release ] || [ "4.13" = $ocp_y_release ]; then
#do nothing
sleep 1
else
if [ "false" = "$(yq '.day1.sriov_kernel' $config_file)" ]; then
warn "SR-IOV kernel(intel_iommu):" "disabled"
else
info "SR-IOV kernel(intel_iommu):" "enabled"
cp $templates/day1/sriov-kernel/*.yaml $cluster_workspace/openshift/
fi
if [ "false" = "$(yq '.day1.rcu_normal' $config_file)" ]; then
warn "Set rcu_normal=1 after node reboot:" "disabled"
else
info "Set rcu_normal=1 after node reboot:" "enabled"
cp $templates/day1/rcu-normal/*.yaml $cluster_workspace/openshift/
fi
if [ "false" = "$(yq '.day1.sync_time_once' $config_file)" ]; then
warn "Sync time once after node reboot:" "disabled"
else
info "Sync time once after node reboot:" "enabled"
cp $templates/day1/sync-time-once/*.yaml $cluster_workspace/openshift/
fi
#4.14 or 4.15, cgv1 is the default
if [ "4.14" = $ocp_y_release ] || [ "4.15" = $ocp_y_release ]; then
if [ "false" = "$(yq '.day1.cgv1' $config_file)" ]; then
warn "enable cgroup v1:" "false"
else
info "enable cgroup v1:" "true"
cp $templates/day1/cgroupv1/*.yaml $cluster_workspace/openshift/
fi
else
#4.16+
if [ "true" = "$(yq '.day1.cgv1' $config_file)" ]; then
warn "default cgv2, enable cgroup v1:" "true"
cp $templates/day1/cgroupv1/*.yaml $cluster_workspace/openshift/
else
info "default cgv2, enable cgroup v1:" "false"
fi
fi
fi
if [ "true" = "$(yq '.day1.container_storage.enabled' $config_file)" ]; then
info "Container storage partition:" "enabled"
jinja2 $templates/day1/container-storage-partition/98-var-lib-containers-partitioned.yaml.j2 $config_file > $cluster_workspace/openshift/98-var-lib-containers-partitioned.yaml
else
warn "Container storage partition:" "disabled"
fi
}
install_operator(){
op_name=$1
cp $operators/$op_name/*.yaml $cluster_workspace/openshift/
#render j2 files
j2files=$(ls $operators/$op_name/*.j2 2>/dev/null)
for f in $j2files; do
tname=$(basename $f)
fname=${tname//.j2/}
yq ".day1.operators.$key" $config_file| jinja2 $f > $cluster_workspace/openshift/$fname
done
}
install_operators(){
readarray -t keys < <(yq ".operators|keys" $operators/operators.yaml|yq '.[]')
for ((k=0; k<${#keys[@]}; k++)); do
key="${keys[$k]}"
desc=$(yq ".operators.$key.desc" $operators/operators.yaml)
enabled_by_default=$(yq ".operators.$key.enabled" $operators/operators.yaml)
#enabled by default
if [[ "true" == "$enabled_by_default" ]]; then
#disable by intention
if [[ "false" == $(yq ".day1.operators.$key.enabled" $config_file) ]]; then
warn "$desc" "disabled"
else
info "$desc" "enabled"
install_operator $key
fi
#disabled by default
else
#enable by intention
if [[ "true" == $(yq ".day1.operators.$key.enabled" $config_file) ]]; then
info "$desc" "enabled"
install_operator $key
else
warn "$desc" "disabled"
fi
fi
done
echo
}
config_operators(){
echo "Configuring operators..."
#right now only local storage operator
if [[ "false" == $(yq ".day1.operators.local-storage.enabled" $config_file) ]]; then
sleep 1
else
# enabled
if [[ $(yq ".day1.operators.local-storage.provision" $config_file) == "null" ]]; then
sleep 1
else
info "local-storage operator: provision storage"
export CREATE_LVS_FOR_SNO=$(cat $templates/day1/local-storage/create_lvs_for_lso.sh |base64 -w0)
export DISK=$(yq '.day1.operators.local-storage.provision.disk_by_path' $config_file)
export LVS=$(yq '.day1.operators.local-storage.provision.lvs|to_entries|map(.value + "x" + .key)|join(" ")' $config_file)
jinja2 $templates/day1/local-storage/60-create-lvs-mc.yaml.j2 $config_file > $cluster_workspace/openshift/60-create-lvs-mc.yaml
fi
fi
}
setup_ztp_hub(){
#will be ztp hub
if [ "true" = "$(yq '.day1.ztp_hub' $config_file)" ]; then
info "ZTP Hub(LVM, RHACM, GitOps, TALM):" "enabled"
cp $operators/lvm/*.yaml $cluster_workspace/openshift/
cp $operators/rhacm/*.yaml $cluster_workspace/openshift/
jinja2 $operators/lvm/StorageLVMSubscription.yaml.j2 > $cluster_workspace/openshift/StorageLVMSubscription.yaml
jinja2 $operators/rhacm/AdvancedClusterManagementSubscription.yaml.j2 > $cluster_workspace/openshift/AdvancedClusterManagementSubscription.yaml
jinja2 $operators/talm/TopologyAwareLifeCycleManagerSubscription.yaml.j2 > $cluster_workspace/openshift/TopologyAwareLifeCycleManagerSubscription.yaml
jinja2 $operators/gitops/GitopsSubscription.yaml.j2 > $cluster_workspace/openshift/GitopsSubscription.yaml
echo
fi
}
copy_extra_manifests(){
extra_manifests=$(yq '.day1.extra_manifests' $config_file)
if [ "$extra_manifests" == "null" ]; then
sleep 1
else
echo "Process extra-manifest files"
all_paths_config=$(yq '.day1.extra_manifests|join(" ")' $config_file)
all_paths=$(eval echo $all_paths_config)
for d in $all_paths; do
if [ -d $d ]; then
for file in $d/*.yaml; do
info "copy file $file to $cluster_workspace/openshift/"
cp "$file" "$cluster_workspace"/openshift/ 2>/dev/null
done
for file in $d/*.yaml.j2; do
tname=$(basename $file)
fname=${tname//.j2/}
info "render file $file to $cluster_workspace/openshift/$fname"
jinja2 $file $config_file > "$cluster_workspace"/openshift/$fname
done
fi
done
fi
}
operator_catalog_sources(){
if [ "4.12" = $ocp_y_release ] || [ "4.13" = $ocp_y_release ] || [ "4.14" = $ocp_y_release ] || [ "4.15" = $ocp_y_release ]; then
if [[ $(yq '.container_registry' $config_file) != "null" ]]; then
jinja2 $templates/day1/operatorhub.yaml.j2 $config_file > $cluster_workspace/openshift/operatorhub.yaml
fi
else
#4.16+, disable marketplace operator
cp $templates/day1/marketplace/09-openshift-marketplace-ns.yaml $cluster_workspace/openshift/
#create unmanaged catalog sources
if [[ "$(yq '.container_registry.catalog_sources.defaults' $config_file)" != "null" ]]; then
#enable the ones in container_registry.catalog_sources.defaults
local size=$(yq '.container_registry.catalog_sources.defaults|length' $config_file)
for ((k=0; k<$size; k++)); do
local name=$(yq ".container_registry.catalog_sources.defaults[$k]" $config_file)
jinja2 $templates/day1/catalogsource/$name.yaml.j2 > $cluster_workspace/openshift/$name.yaml
done
else
#by default redhat-operators and certified-operators shall be enabled
jinja2 $templates/day1/catalogsource/redhat-operators.yaml.j2 > $cluster_workspace/openshift/redhat-operators.yaml
jinja2 $templates/day1/catalogsource/certified-operators.yaml.j2 > $cluster_workspace/openshift/certified-operators.yaml
fi
fi
#all versions
if [ "$(yq '.container_registry.catalog_sources.customs' $config_file)" != "null" ]; then
local size=$(yq '.container_registry.catalog_sources.customs|length' $config_file)
for ((k=0; k<$size; k++)); do
yq ".container_registry.catalog_sources.customs[$k]" $config_file |jinja2 $templates/day1/catalogsource/catalogsource.yaml.j2 > $cluster_workspace/openshift/catalogsource-$k.yaml
done
fi
#all versions
if [ "$(yq '.container_registry.icsp' $config_file)" != "null" ]; then
local size=$(yq '.container_registry.icsp|length' $config_file)
for ((k=0; k<$size; k++)); do
local name=$(yq ".container_registry.icsp[$k]" $config_file)
cp $basedir/$name $cluster_workspace/openshift/
done
fi
}
echo
echo "Enabling day1 configuration..."
day1_config
echo
echo "Enabling operators..."
operator_catalog_sources
install_operators
config_operators
echo
setup_ztp_hub
copy_extra_manifests
pull_secret=$(yq '.pull_secret' $config_file)
export pull_secret=$(cat $pull_secret)
ssh_key=$(yq '.ssh_key' $config_file)
export ssh_key=$(cat $ssh_key)
bundle_file=$(yq '.additional_trust_bundle' $config_file)
if [[ "null" != "$bundle_file" ]]; then
export additional_trust_bundle=$(cat $bundle_file)
fi
jinja2 $templates/agent-config.yaml.j2 $config_file > $cluster_workspace/agent-config.yaml
jinja2 $templates/install-config.yaml.j2 $config_file > $cluster_workspace/install-config.yaml
mirror_source=$(yq '.container_registry.image_source' $config_file)
if [[ "null" != "$mirror_source" ]]; then
cat $mirror_source >> $cluster_workspace/install-config.yaml
fi
cp $cluster_workspace/agent-config.yaml $cluster_workspace/agent-config-backup.yaml
cp $cluster_workspace/install-config.yaml $cluster_workspace/install-config-backup.yaml
echo
echo "Generating boot image..."
echo
$basedir/openshift-install --dir $cluster_workspace agent --log-level=info create image
echo ""
echo "------------------------------------------------"
echo "kubeconfig: $cluster_workspace/auth/kubeconfig."
echo "kubeadmin password: $cluster_workspace/auth/kubeadmin-password."
echo "------------------------------------------------"
echo
echo "Next step: Go to your BMC console and boot the node from ISO: $cluster_workspace/agent.x86_64.iso."
echo "You can also run ./sno-install.sh to boot the node from the image automatically if you have a HTTP server serves the image."
echo "Enjoy!"