-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathoinst
executable file
·1547 lines (1418 loc) · 49 KB
/
oinst
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Copyright 2019-2020 Robert Krawitz/Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function fatal() {
echo "FATAL: $*" 1>&2
exit 1
}
set -u
# Find our helpers
function ___find_topdir() {
local path_to_file
path_to_file=$(readlink -f "$0")
if [[ -z $path_to_file ]] ; then
return 1
elif [[ -d $path_to_file ]] ; then
echo "$path_to_file/"
elif [[ -e $path_to_file ]] ; then
echo "${path_to_file%/*}/"
else
return 1
fi
return 0
}
declare ___realsc=
declare ___topsc=${___topsc:-}
if [[ -z ${___topsc:-} ]] ; then
export ___topsc="${0##*/}"
# shellcheck disable=SC2155
export ___topdir="$(___find_topdir "$0")"
[[ -z $___topdir ]] && fatal "Can't find directory for $0"
fi
function ___clean_startup() {
[[ -f $___realsc ]] && rm -f "$___realsc"
}
# This allows us to edit the script while another instance is running
# since this script sticks around until the user exits the spawned shell.
# It's fine for the running script to be removed, since the shell still
# has its open file descriptor.
if [[ $# = 0 || $1 != "---DoIt=$0" ]] ; then
___tmpsc=$(mktemp -t "${___topsc}.XXXXXXXXXX")
[[ -z $___tmpsc || ! -f $___tmpsc || -L $___tmpsc ]] && fatal "Can't create temporary script file"
trap ___clean_startup EXIT SIGHUP SIGINT SIGQUIT SIGTERM
PATH+=${PATH:+:}$___topdir
cat "$0" > "$___tmpsc"
chmod +x "$___tmpsc"
exec "$___tmpsc" "---DoIt=$___tmpsc" "$@"
else
___realsc=${1#---DoIt=}
___clean_startup
export -n ___topsc ___topdir
shift
fi
# Globals
declare -A release_base_map=()
release_base_map[origin-release]='4.2.0-0.okd'
release_base_map[openshift-release]='4-stable'
declare -A subdir_map=()
subdir_map[origin-release]='origin'
subdir_map[openshift-release]='ocp'
declare -r kubechart=${KUBECHART:-$GOPATH/src/github.com/sjenning/kubechart/kubechart}
declare -r oschart=${OSCHART:-$GOPATH/src/github.com/sjenning/oschart/oschart}
declare -r default_repo_base=openshift-release
declare -A global_platforms=()
declare -a global_platform_list=()
declare -A global_diagnostics=()
declare -a platform_path=()
declare install_type=
declare install_domain=${OPENSHIFT_INSTALL_DOMAIN:-}
declare install_dir=${OPENSHIFT_INSTALL_DIR:-$install_domain}
declare install_version=latest_default
declare pull_secret=${OPENSHIFT_INSTALL_PULL_SECRET_PATH:-$HOME/.docker/config.json}
declare pubkey_file=${OPENSHIFT_INSTALL_SSH_PUB_KEY_PATH:-$HOME/.ssh/id_rsa.pub}
declare installer_src=${GOPATH:-$HOME/go}/src/github.com/openshift/installer
declare install=$installer_src/bin/openshift-install
declare release_channel=
declare repo=$default_repo_base
declare ____current_platform
# shellcheck disable=SC2155
declare -r OC=$(type -p oc)
[[ -z $OC ]] && fatal "Can't find oc command"
# shellcheck disable=SC2155
declare -r JQ=$(type -p jq)
[[ -z $JQ ]] && fatal "Can't find jq command"
# shellcheck disable=SC2155
declare -r owd=$(pwd)
declare -i all_releases=0
declare -i clean_install_cache=0
declare -i clean_shutdown=0
declare -i cleanup_run=0
declare -i create_bastion=1
declare -i created_kubechart=0
declare -i created_oschart=0
declare -i do_cleanup=1
declare -i do_login=1
declare -i do_override=0
declare -i download_oc=0
declare -i force_local_tools=0
declare -i force_postinstall=0
declare -i generate_cluster_key=0
declare -i generate_manifest=0
declare -i install_stage=0
declare -i login_succeeded=0
declare -i master_count=0
declare -i noconfirm=0
declare -i overwrite=0
declare -i query=0
declare -i rebuild=0
declare -i run_kubechart=0
declare -i run_oschart=0
declare -i save_artifacts=0
declare -i wait_for_complete=1
declare -i worker_count=0
declare -i cvo=1
declare -i host_prefix_bits=23
declare valid_channels=-G
declare api_version=v1
declare cleanup_only_dir=
declare config_file=
declare console_route=
declare edit_manifest=
declare ext_installer=
declare -r -i default_kubechart_port=3000
declare kubechart_port=
declare loglevel=
declare network_type=OpenShiftSDN
declare oschart_port=
declare release_source=
declare run_command=
declare platform_type=
declare master_type=
declare worker_type=
declare masterconffile=
declare masterconfdata=
declare workerconffile=
declare workerconfdata=
declare platformconffile=
declare platformconfdata=
declare -a options_to_process=()
declare -A option_registrations=()
function _print_help() {
cat <<EOF
Usage: $___topsc [options] [install_type]
install_type: one of
$(do_platforms platform_help install_types | indent 7)
Options (all are processed in order):
-p profile Read the specified profile file. Profile
may be a JSON file or shell code.
--option[=value]
-X option[=value] Set the specified extended option.
Short options listed with a KEY can be
invoked as --KEY[=value].
-H Print list of additional extended command
line options.
Options listed as -a/-A are inverted by the second listed option.
-a/-A List all releases with query (not just validated
ones).
KEY: all_releases (default=0)
-b/-B Launch kubechart and oschart (if available).
See https://github.com/sjenning/kubechart
KEY: run_kubechart (default=0)
-c/-C Clean install cache, in case it is corrupted.
KEY: clean_install_cache (default=0)
-d install_dir Use the specified dir as working directory and
cluster name. Default is ${LOGNAME:-}-<platform>.
-k pubkey_file Use the specified public key file for the cluster.
Default $pubkey_file
-K Generate ssh key for the cluster. If not set,
use user's standard ssh key or value of -k
KEY: generate_cluster_key (default=0)
-l/-L Don't clean up on exit. You can exit with status
77 for no cleanup or 88 to force cleanup.
KEY: do_cleanup (default=1)
-n release_channel Use the specified release channel.
-O/-o Allow overwrite an existing install directory.
KEY: overwrite (default=0)
-u/-U Query for release (and optionally channel) to use.
Also see -a/-A.
KEY: query (default=0)
-V install_version Install the specified image version (default
latest). Use '$___topsc -H' for more details.
-v/-q Print debug information.
KEY/VALUE: loglevel='--log-level=debug'
-x cleanup_only_dir Only clean up (requires cluster already exists).
-y/-Y Do not prompt prior to starting install
KEY: noconfirm (default=0)
EOF
}
function print_help() {
_print_help | ${PAGER:-more}
}
function help() {
[[ -n ${1:-} ]] && echo "$___topsc: Unknown option $1"
print_help
exit 1
}
function _help_extended() {
print_help
cat <<EOF
Other options with no short command line option:
Generic cluster configuration:
host_prefix_bits Use the specified host prefix size (default $host_prefix_bits,
must be between 8 and 24)
network_type Use the specified network type. Default is
$network_type; alternative is OVNKubernetes.
masterconfdata Specify the data for master configuration.
masterconffile Take master platform config from specified file.
platformconfdata Specify the data for platform configuration.
platformconffile Take platform configuration from specified file.
workerconfdata Specify the data for worker configuration.
workerconffile Take master platform config from specified file.
Node type/count, all default by platform:
master_count Use the specified number of master nodes.
master_type Instance type to use for master.
worker_count Use the specified number of worker nodes.
worker_type Instance type to use for workers.
platform_type Instance type to use for both workers and masters.
$(do_platforms platform_help options |indent -6)
Installation options:
config_file Use the specified file as the install config file.
create_bastion Create a bastion ssh host if supported
by platform (default 1).
disable_cvo Turn off the cluster version operator so that
the resulting cluster is not overwritten.
Option variable is 'cvo' (default 1, not disabled).
do_login Login to the console (default=1)
download_oc Download the matching oc binary (default=0)
edit_manifest=func Edit manifest files using supplied function.
Only relevant if --generate-manifest is in use.
If this is supplied but empty, spawn an
interactive shell.
ext_installer Use the specified command to install OpenShift.
force_postinstall Always run the postinstall even if setup fails.
generate_manifest Generate the manifest files explicitly (default 0,
unless overridden by platform)
install_domain Use the specified domain name.
$(do_platforms platform_help default_domain | indent -28)
install_version Install the specified image version. Default
is to use the latest version.
Use empty value to install from local workspace
(installer_src, default ${installer_src}).
install_type Specify the install type, as described above.
installer_src Specify the source directory for the installer.
Default is ${installer_src}.
kubechart_port Use the specified port for kubechart. oschart
runs at port+1. Implies -b. Default is ${default_kubechart_port}.
pubkey_file Specify the path to the desired public key
Equivalent to -k. Default $pubkey_file
pull_secret Specify the path to the pull secret.
Default $pull_secret
rebuild Always rebuild the installer, when using local
installer.
repo Use the specified repo (default $default_repo_base).
run_command Run the specified command rather than an
interactive shell on completion of installation.
save_artifacts Preserve install config, manifests, etc.
wait_for_complete Wait for console to come online (default=1)
The following extended options are normally not recommended:
api_version Use the specified API version (default $api_version).
do_override Override install image.
force_local_tools Use the local toolchain to install with.
Turns on do_override if a version is specified.
EOF
}
function help_extended() {
_help_extended | ${PAGER:-more}
exit 1
}
################################################################
### Utilities ###
################################################################
function clear_env() {
local var
for var in "${!_OPENSHIFT_INSTALL@}" "${!OPENSHIFT_INSTALL@}" KUBECONFIG ; do unset "$var"; done
}
function printerval() {
local milestone=$1
local interval=$2
echo -n "$milestone took "
local h=$((interval / 3600))
(( h > 0 )) && echo -n "$h:"
printf "%02d:%02d\n" $(((interval % 3600) / 60)) $((interval % 60))
}
function set_diagnostic() {
local diagnostic_id="$1"
local print_diagnostic_message_func="$2"
global_diagnostics["$diagnostic_id"]="$print_diagnostic_message_func"
}
function _timestamp() {
while read -r REPLY ; do
platform_dispatch diagnose "$REPLY"
# Make the message look vaguely Go-like.
printf "T0000 %s %s\n" "$(TZ=GMT-0 date '+%Y-%m-%dT%T.%N' | cut -c1-26)" "$REPLY"
done
}
function timestamp() {
if [[ -n "$*" ]] ; then
_timestamp <<< "$*"
else
_timestamp
fi
}
function tsec() {
printf "%(%s)T" -1
}
function indent() {
local -i depth=${1:-2}
local -i always_indent=0
if (( depth < 0 )) ; then
depth=$((-depth))
always_indent=1
fi
# shellcheck disable=SC2155
local sol=$(printf "%${depth}s" '')
while IFS='' read -r line ; do
[[ always_indent -eq 0 && -z $line ]] || echo "$sol$line"
done
}
function cmdline_replicas() {
local node_type=$1
local default=$2
case "$node_type" in
master)
case "$master_count" in
1|3) echo "$master_count" ;;
0) echo "$default" ;;
*)
fatal "Unspported number of masters (should be 1 or 3)"
;;
esac
return
;;
worker)
(( worker_count < 0 )) && worker_count=0
echo "$worker_count"
return
;;
*) ;;
esac
echo "$default"
}
function run_installer() {
# shellcheck disable=SC2086
"${install}" $loglevel "--dir=$install_dir" "$@"
}
function dispatch_unknown() {
# Don't force platforms to implement every new item
:
# local platform=$1
# shift
# fatal "Unexpected command ($platform): $*"
}
# Not all platforms support the standard bastion host.
function do_create_bastion_if_needed() {
(( create_bastion )) || return
platform_dispatch supports_bastion || return
echo "Creating bastion host"
curl -s -S -L https://raw.githubusercontent.com/eparis/ssh-bastion/master/deploy/deploy.sh | bash
# shellcheck disable=SC2181
if (( $? )) ; then
echo "Create bastion host failed"
else
echo "Alternatively, you may prefer to use ${___topdir:-}bastion-ssh"
# shellcheck disable=SC2155
export OPENSHIFT_BASTION_ADDRESS="$(oc get service -n openshift-ssh-bastion ssh-bastion -o json | jq -r 'if .status.loadBalancer.ingress[0].hostname == null then .status.loadBalancer.ingress[0].ip else .status.loadBalancer.ingress[0].hostname end')"
[[ -z $OPENSHIFT_BASTION_ADDRESS ]] && echo "Unable to find bastion address!"
fi
}
function add_platform() {
if [[ -z ${____current_platform:-} ]] ; then
fatal "Attempt to add a platform outside of its definition"
fi
local -r dispatch=$1
local plat
for plat in "${global_platform_list[@]}" ; do
if [[ $____current_platform = "$plat" ]] ; then return; fi
done
global_platform_list+=("$____current_platform")
global_platforms[$____current_platform]=$dispatch
}
function _default_split_instance_func() {
echo ' '
echo "$1"
}
function _list_instance_types() {
local -i list_all=0
local cmd=$1
local list_option_name=$2
local split_instance_func=${3:-_default_split_instance_func}
shift 3
while read -r REPLY ; do echo "$REPLY" ; done
if [[ $cmd = list_all ]] ; then
list_all=1
else
echo "Use '$___topsc --$list_option_name=list-all' to list all instance types."
fi
echo
local last_class=
local -i tot_cols=0
local -i groups_printed=0
# shellcheck disable=SC2155
local -i term_width=$(tput cols 2>/dev/null)
(( term_width > 0 )) || term_width=80
local instance
local -i c=0
local -i s=0
local -a cla
# Find the widest class name and instance name
for instance in "$@" ; do
case "$instance" in
" X."*)
(( list_all == 0 && groups_printed++ )) && break
;;
" Y"*)
;;
*)
readarray -t cla < <("$split_instance_func" "$instance")
(( ${#cla[0]} < c )) || c=$((${#cla[0]}+1))
(( ${#cla[1]} <= s )) || s=${#cla[1]}
;;
esac
done
groups_printed=0
for instance in "$@" ; do
case "$instance" in
" X."*)
(( list_all == 0 && groups_printed++ )) && break
echo -ne "${last_class:+\n\n}${instance# X.}:"
last_class=
;;
" Y."*)
echo -ne "\n ${instance#*.}"
;;
*)
readarray -t cla < <("$split_instance_func" "$instance")
if [[ ${cla[0]} = "$last_class" ]] ; then
tot_cols+=$((s+1))
if (( tot_cols > (term_width - s) )) ; then
printf "\n %${c}s " ''
tot_cols=$((c+2))
fi
printf " %-${s}s" "${cla[1]}"
else
tot_cols=$((c+2))
local sep=:
if [[ ${cla[0]} = ' ' ]] ; then
sep=
fi
printf "\n %-${c}s %-${s}s" "${cla[0]}$sep" "${cla[1]}"
last_class=${cla[0]}
fi
;;
esac
done
echo
}
function list_instance_types() {
while IFS= read -r line ; do
line=${line## }
echo "$line"
done < <(_list_instance_types "$@")
}
function _check_instance_type() {
local instance_type=$1
local platform=$2
local list_option_name=$3
local split_instance_func=$4
shift 4
[[ -z ${instance_type:-} ]] && return 0
local instance
for instance in "$@" ; do
[[ $instance = "$instance_type" ]] && return 0
done
echo "*** WARNING: '$instance_type' is not a currently known $platform instance type!"
local -a cla
local -a icla
readarray -t cla < <("$split_instance_func" "$instance_type")
# shellcheck disable=SC2155
local -i term_width=$(tput cols 2>/dev/null)
(( term_width > 0 )) || term_width=80
local -i tot_cols=0
local j=0
for instance in "$@" ; do
readarray -t icla < <("$split_instance_func" "$instance")
if [[ ${cla[0]} = "${icla[0]}" ]] ; then
(( j++ )) || echo "Possible candidates:"
if (( tot_cols > (term_width - 5) )) ; then
echo
tot_cols=0
fi
echo -n " $instance"
tot_cols=$((tot_cols + ${#instance} + 1))
fi
done
echo -e '\n'
(( j )) || return 2
return 1
}
function validate_instance_type() {
local worker_type=$1
local master_type=$2
local platform=$3
local list_option_name=$4
local split_instance_func=$5
shift 5
if [[ $master_type = list-all || $worker_type = list-all ||
$platform_type = list-all ||
$master_type = list_all || $worker_type = list_all ||
$platform_type = list_all ]] ; then
list_instance_types list_all "$list_option_name" "$split_instance_func" "$@"
exit
fi
if [[ $master_type = list || $worker_type = list ||
$platform_type = list ]] ; then
list_instance_types list "$list_option_name" "$split_instance_func" "$@"
exit
fi
local need_to_list_instance_types=0
_check_instance_type "$master_type" "$platform" "$list_option_name" "$split_instance_func" "$@"
(( $? == 2 )) && need_to_list_instance_types=1
_check_instance_type "$worker_type" "$platform" "$list_option_name" "$split_instance_func" "$@"
(( $? == 2 )) && need_to_list_instance_types=1
(( need_to_list_instance_types )) && list_instance_types list "$list_option_name" "$split_instance_func" "$@"
return 0
}
function platform_dispatch() {
if [[ $1 = -p ]] ; then
shift
local platform=$1
shift
if [[ -z ${global_platforms[$platform]:-} ]] ; then
fatal "Platform $platform not found"
fi
"${global_platforms[$platform]}" "$@"
elif [[ -n ${OPENSHIFT_INSTALL_PLATFORM:-} ]] ; then
"${global_platforms[$OPENSHIFT_INSTALL_PLATFORM]}" "$@"
else
local -i status=0
local platform
for platform in "${global_platform_list[@]}" ; do
"${global_platforms[$platform]}" "$@" || status=1
done
return $status
fi
}
function do_platforms() {
OPENSHIFT_INSTALL_PLATFORM='' platform_dispatch "$@"
}
function find_first_platform() {
local platform
for platform in "${global_platform_list[@]}" ; do
if platform_dispatch -p "$platform" "$@" ; then
echo "$platform"
return 0
fi
done
return 1
}
function cleanup() {
(( cleanup_run )) && exit
(( !clean_shutdown && install_stage >= 2 )) && echo -en '\n*** '
case "$install_stage" in
0) ;;
1)
[[ -n $install_dir && $install_dir != . && $install_dir != .. && -d "$install_dir" ]] && rm -rf "$install_dir"
;;
*)
echo "Cleaning up, please do not interrupt"
if (( do_cleanup )) ; then
# Shut up some very uninteresting noise
exec 3>&2 2>/dev/null
if (( created_kubechart )) ; then
kill -9 %run_kubechart
wait %run_kubechart
fi
if (( created_oschart )) ; then
kill -9 %run_oschart
wait %run_oschart
fi
exec 2>&3 3>&-
run_installer destroy cluster 2>&1 |timestamp
if (( PIPESTATUS[0] == 0 || clean_install_cache)) ; then
[[ -n $install_dir && $install_dir != . && $install_dir != .. && -d "$install_dir" ]] && rm -rf "$install_dir"
else
echo "$install --dir=$install_dir destroy cluster failed, not removing install dir!"
fi
platform_dispatch cleanup
else
cat 1>&2 <<EOF
*** Not cleaning up!
*** When you are finished, run:
"${install}" $loglevel "--dir=$install_dir" destroy cluster
EOF
fi
;;
esac
cleanup_run=1
exit
}
function platform_data() {
local what=${1:-}
local data=${2:-}
local file=${3:-}
local -i indent=${4:-0}
local platform_code
if [[ -n $data ]] ; then
platform_code="$data"
elif [[ -n $file && -r $file ]] ; then
platform_code="$(< "$file")"
else
platform_code=${what:+$(platform_dispatch "$what")}
fi
if [[ -z $platform_code ]] ; then
echo '{}'
else
echo
indent "$indent" <<< "$platform_code"
fi
}
# This has the problem that the install config format can change and
# we're left chasing it. But much of the idea of this script is that
# people not have to run the installer interactively.
function template() {
sed -e 's/[ \t]*$//' -e '/^$/d' <<EOF
apiVersion: $api_version
baseDomain: $(platform_dispatch base_domain)
compute:
- hyperthreading: Enabled
name: worker
platform: $(platform_data worker "${workerconfdata:-}" "${workerconfdata:-}" 4)
replicas: $(platform_dispatch replicas worker)
controlPlane:
hyperthreading: Enabled
name: master
platform: $(platform_data master "${masterconfdata:-}" "${masterconfdata:-}" 4)
replicas: $(platform_dispatch replicas master)
metadata:
creationTimestamp: null
name: $OPENSHIFT_INSTALL_CLUSTER_NAME
networking:
clusterNetwork:
- cidr: 10.128.0.0/14
hostPrefix: $host_prefix_bits
machineCIDR: $(platform_dispatch machine_cidr)
networkType: $network_type
serviceNetwork:
- 172.30.0.0/16
platform: $(platform_data platform "${platformconfdata:-}" "${platformconfdata:-}" 2)
publish: External
pullSecret: '$(jq -scM '.[0]' < "$pull_secret")'
sshKey: |
$(< "$pubkey_file")
EOF
}
# Use this to determine whether we need some particular workaround.
# Most of the time it will be more problematic than it's worth to
# do something like this, but occasionally we may need to
# temporarily.
function git_newer_than() {
local -l rev="$1"
git rev-parse -q --verify "$rev" -- >/dev/null 2>&1 || return 1
[[ -n $(git rev-list "@..$(git rev-parse "$rev")") ]]
}
function wait_and_run() {
until [[ -f $KUBECONFIG ]] ; do sleep 1; done
cmd=${1##*/}
echo "Starting $cmd..." | timestamp
if [[ $loglevel = '--log-level=debug' ]] ; then
exec "$@"
else
exec "$@" >/dev/null 2>&1
fi
}
# We need actual commands/functions named run_kubechart and run_oschart with
# known names, so that they can be waited for.
function run_kubechart() {
wait_and_run "$kubechart" ${kubechart_port:+--http-port "$kubechart_port"}
}
function run_oschart() {
wait_and_run "$oschart" ${oschart_port:+--http-port "$oschart_port"}
}
function run_shell() {
cd "$owd" || fatal "Cannot cd to $owd"
if [[ -n $run_command ]] ; then
exec "$SHELL" -c "$run_command"
else
if (( do_cleanup )) ; then
timestamp "Spawning interactive shell. Exit with status 77 to suppress cleanup."
else
timestamp "Spawning interactive shell. Exit with status 88 to clean up."
fi
exec "$SHELL" -i
fi
}
function warn_authentication_failure() {
cat <<\EOF
* [auth] You need to download your pull secrets.
Visit https://try.openshift.com and log in. Click on Self-managed
(https://cloud.redhat.com/openshift/create/datacenter?trial=ocp) and
select Local (https://cloud.redhat.com/openshift/create/local).
From there, select User-Provisioned Infrastructure. Download or
copy your pull secret and place it in or merge it into
~/.docker/config.json
* [auth] You need an appropriate quay.io credential.
Get the required key from
https://access.redhat.com/solutions/3533201. Add the auth for
quay.io to your ~/.docker/config.json.
* [auth] You need to oc login (or periodically refresh your login). All
three steps must be performed. Not doing this can lead to very
strange errors; see https://bugzilla.redhat.com/show_bug.cgi?id=1647479.
+ Go to
https://oauth-openshift.apps.ci.l2s4.p1.openshiftapps.com/oauth/token/request
and choose the appropriate option to log in. Click "Display token" to get
the login command, and run it.
+ Run 'oc registry login'.
+ This will generate or update additional secrets in
~/.docker/config.json.
* [auth] Ensure that you have correct credentials for your cloud platform,
as appropriate.
EOF
}
function warn_installer_fail() {
cat <<\EOF
Could not extract installer from image. Common reasons:
* You've specified an installer version that does not exist (even if
you've used the query option). This will fail quickly with a
clear error message.
* The version of `oc' on your system is too old.
Versions of oc prior to 4.1 do not understand the command to
extract the installer.
EOF
warn_authentication_failure
}
function fail_installer_extract() {
local image=$1
warn_installer_fail
fatal "Cannot extract openshift-install from image $image"
}
function fail_find_image() {
local install_version=$1
warn_installer_fail
fatal "Can't find image for version $install_version"
}
# This should run in a subshell to not change the current directory
function do_installer_setup() {
local install_dir=$1
local image=$2
local install_version=$3
cd "$install_dir" || exit 1
for f in "openshift-"*".tar.gz" ; do
rm -f "$f"
done
"${OC}" adm release extract --tools "${image}" || fail_installer_extract "$image"
for f in "openshift-"*".tar.gz" ; do
echo "Extracting $f"
tar xf "$f" || fail_installer_extract "$image"
done
[[ -f openshift-install ]] || fail_installer_extract "$image"
chmod +x openshift-install
echo "${install_version}" > version.txt
}
function list_release_channels() {
local -a channels=(" X.Available release channels:")
readarray -t -O 1 channels < <(openshift-release-info -B "$repo" channels < /dev/null | sort -r)
list_instance_types list_all "release_channel" '' "${channels[@]}" < /dev/null
}
function list_install_versions() {
local channel=$1
local -a releases=()
if [[ -n $channel ]] ; then
channels=("$channel")
else
local -a channels=()
readarray -t channels < <(openshift-release-info -B "$repo" channels < /dev/null | sort -r)
fi
for channel in "${channels[@]}" ; do
local -a versions=()
readarray -t versions < <(openshift-release-info ${valid_channels} -B "$repo" ${channel:+-c "$channel"} releases < /dev/null | sort -r)
if [[ -n "${versions[*]:-}" ]] ; then
releases+=(" X.$channel")
releases+=("${versions[@]}")
fi
done
list_instance_types list_all "install_version" '' "${releases[@]}" </dev/null
}
function installer_setup() {
local -i not_latest=1
local release_data
local image
local release_source=${OPENSHIFT_RELEASE_SOURCE:-openshift-release.apps.ci.l2s4.p1.openshiftapps.com/api/v1/releasestream}
#release_channel=${release_channel:-${release_base_map[$repo]:-}}
if (( query )) ; then
if [[ -z ${release_channel:-} ]] ; then
local -a channels=()
readarray -t channels < <(echo 'all'; openshift-release-info -B "$repo" channels < /dev/null | sort -r)
OPS3=${PS3:-}
PS3="Select channel: "
select release_channel in "${channels[@]}" ; do break; done
PS3=$OPS3
fi
if [[ $release_channel = 'all' ]] ; then
release_channel=
fi
local -a versions=()
readarray -t versions < <(openshift-release-info ${valid_channels} -B "$repo" ${release_channel:+-c "$release_channel"} releases < /dev/null | sort -r)
OPS3=${PS3:-}
PS3="Select release: "
select install_version in "${versions[@]}" ; do break; done
PS3=$OPS3
elif [[ -n ${release_channel:-} ]] ; then
local -a versions=()
read -r install_version < <(openshift-release-info ${valid_channels} -B "$repo" ${release_channel:+-c "$release_channel"} releases < /dev/null | sort -r | head -1)
elif [[ $install_version = latest ]] ; then
not_latest=0
release_channel=${release_channel:-${release_base_map[$repo]:-}}
echo "Retrieving release data from $release_source/$release_channel/latest"
release_data="$(curl -S --silent -L "$release_source/$release_channel/latest")"
[[ -n $release_data ]] || fatal "Can't extract release data!"
install_version="$("$JQ" -r '.name' <<< "$release_data")"
[[ -n $install_version ]] || fatal "Can't extract install version!"
fi
echo "Using version $install_version${not_latest:- (latest)}" 1>&2
local -r pullspec="$install_version"
image=$("${OC}" adm release info --pullspecs "$pullspec" | awk '{if ($1 == "Pull") {print $3}}')
[[ -z $image ]] && fail_find_image "$install_version"
if (( ! force_local_tools )) ; then
echo "Using installer from image ${image} ($ext_installer)" 1>&2
installer_src=
(do_installer_setup "$install_dir" "$image" "$install_version") || exit 1
ext_installer="${install_dir}/openshift-install"
install="$ext_installer"
echo -e "installer version:\n$("$ext_installer" version |sed 's/^/ /')\n" 1>&2
elif (( not_latest )) ; then
do_override=1
fi
if (( do_override && not_latest )) ; then
export OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE=$pullspec
export _OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE=$pullspec
fi
}
# Try to catch obvious failures
function validate_environment() {
[[ -n $masterconffile && ! -r $masterconffile ]] &&
fatal "Master platform config $masterconffile not readable"
[[ -n $workerconffile && ! -r $workerconffile ]] &&
fatal "Worker platform config $workerconffile not readable"
[[ -n $platformconffile && ! -r $platformconffile ]] &&
fatal "Platform config $platformconffile not readable"
(( host_prefix_bits < 8 || host_prefix_bits > 23 )) &&
fatal "Host prefix size must be between 8 and 23"
local f
for f in quay.io registry.redhat.io registry.svc.ci.openshift.org ; do
local g=${f//./\\.}
grep -q "$g" "$pull_secret" || warn "No secret for '$f' in pull secret $pull_secret; expect installation to fail"
done
}
function confirm_install() {
cat <<EOF
About to run installer:
Installer: $install
EOF
if [[ -n $installer_src ]] ; then
cat <<EOF
Sourcedir: $installer_src$([[ $installer_src != /* ]] && echo " ($(cd "$installer_src" && pwd))")
EOF
fi
cat <<EOF
Install dir: $install_dir
Current dir: $(pwd)
Install version: $install_version
Override: ${OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE:-}
Install command: ${install} $loglevel --dir="$install_dir" create cluster
Configuration:
$OPENSHIFT_INSTALL_CONFIG
EOF
(( noconfirm )) && return 0
[[ -t 0 ]] || return 0
local proceed
echo
while : ; do
read -p "Proceed? [YnevV!?] " -r proceed
case "$proceed" in
y|Y|yes|YES|Yes|'')
break
;;
n|N|no|NO|No)
echo "Not confirmed"
return 1
;;
'!')
echo "Spawning shell..."
(cd "$install_dir" && "$SHELL" -i)
;;
e|E|edit|EDIT|Edit)
echo "Editing config..."
${EDITOR:-vi} "$install_dir/install-config.yaml"
;;
V)
env
;;
v)
set
;;
'?')
echo 'y Proceed with installation'
echo 'n Do not proceed with installation'
echo '! Spawn shell'
echo 'V Print environment'
echo 'v Print all variable settings'
echo 'e Edit install-config.yaml'
echo '? Print this help'
echo 'Abort installation with any other input'