-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdtk
executable file
·204 lines (178 loc) · 5.28 KB
/
dtk
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
#!/usr/bin/env bash
set -e
long_opts=help,check-compatibility,up:,down:,delete:,verify:,config:,create-template:,install-addon:,no-create-vms
# This snippet enables all scripts to exec all other scripts without knowing any
# other script's path, as long all the scripts (except this one) are children
# of the 'scripts' directory.
export DTKBASE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
function xec() {
if echo $1 | grep -q /; then
f=$(find $DTKBASE/scripts -type d -name $(dirname $1) | xargs -I% find % -type f -name $(basename $1))
else
f=$(find $DTKBASE/scripts -name $1)
fi
[[ -n $f ]] && $f "${@:2}"
}
export -f xec
# set from cmdline
help=0
check_compatibility=0
up=
down=
delete=
verify=
config=$DTKBASE/config.yaml
create_template=
install_addon=
no_create_vms=false
# set by scripts/helpers/parse-config.py:
virt=
k8s_containerized_cplane=
k8s_cluster_cidr=
k8s_cluster_dns=
k8s_kube_proxy=
kvm_network=
kvm_kickstart=
kvm_os_variant=
vbox_host_network_interface=
vbox_host_only_network=
vbox_kickstart=
vbox_vboxdir=
vm_linux=
vm_create_template=1
vm_template_vmname=
# entry point
set -a
source $DTKBASE/artifacts
set +a
# parse cmdline
if ! parsed=$(xec parseargs $long_opts "$@"); then
echo "$parsed"
exit 1
fi
eval $(echo -e "$parsed")
if [[ $help -eq 1 ]]; then
xec show-usage
exit 0
fi
if [[ $check_compatibility -eq 1 ]]; then
xec check-compatibility
exit 0
fi
if [[ -n "$verify" ]]; then
if [[ "$verify" != "upstreams" ]] && [[ "$verify" != "files" ]]; then
echo "unsupported value for --verify option: $verify"
exit 1
fi
xec check-objects "$verify"
exit 0
fi
# ensure config.yaml exists
config=$(realpath $config)
if [[ ! -f "$config" ]]; then
echo "config file not found: $config"
exit 1
fi
# parse config.yaml
xec parse-config.py $config check || exit
eval $(xec parse-config.py $config)
if [[ -n "$up" ]]; then
xec $virt/up-down-del up $up $config
exit 0
elif [[ -n "$down" ]]; then
xec $virt/up-down-del down $down $config
exit 0
elif [[ -n "$delete" ]]; then
xec $virt/up-down-del delete $delete $config
exit 0
fi
if [[ -n "$install_addon" ]]; then
xec install-addons\
--config=$config\
--admin-kubeconfig=$DTKBASE/generated/kubeconfig/admin.kubeconfig\
--priv-key=$DTKBASE/generated/kickstart/id_ed25519\
--addon=$install_addon
exit 0
fi
if [[ $virt == "virtualbox" ]]; then
if [[ -z "$vbox_host_network_interface" ]] && [[ -z "$vbox_host_only_network" ]]; then
echo "either --host-network-interface or --host-only-network is required"
exit 1
elif [[ ! -z "$vbox_host_network_interface" ]] && [[ ! -z "$vbox_host_only_network" ]]; then
echo "--host-network-interface and --host-only-network are exclusive of each other"
exit 1
fi
if [[ -z "$vbox_vboxdir" ]]; then
vbox_vboxdir=$(vboxmanage list systemproperties | grep folder | awk -F: '{print $2}' | xargs)
fi
if [[ -z "$vbox_vboxdir" ]]; then
echo "directory for virtualbox VMs is not defined"
exit 1
elif [[ ! -d $vbox_vboxdir ]]; then
echo "directory for virtualbox VMs does not exist: $vbox_vboxdir"
exit 1
fi
fi
if [[ "$vm_linux" != "centos9" ]] && [[ "$vm_linux" != "rocky" ]] && [[ "$vm_linux" != "alma" ]]; then
echo "unsupported value for linux config: $vm_linux"
exit 1
fi
# --create-template on the cmdline overrides config.yaml
if [[ "$create_template" == "true" ]]; then
vm_create_template=1
elif [[ "$create_template" == "false" ]]; then
vm_create_template=0
fi
echo "creating directories to generate various files into"
mkdir -p $DTKBASE/generated/kickstart\
$DTKBASE/generated/kubeconfig\
$DTKBASE/generated/cert\
$DTKBASE/generated/hostonly-netcfg\
$DTKBASE/generated/iso
echo "downloading core cluster components"
xec download-objects\
--create-template=$vm_create_template\
--linux=$vm_linux\
--virt=$virt
if [[ $no_create_vms == false ]]; then
echo "provisioning vms"
if [[ $virt == "virtualbox" ]]; then
xec virtualbox/provision-vms\
--create-template=$vm_create_template\
--linux=$vm_linux\
--host-network-interface=$vbox_host_network_interface\
--host-only-network=$vbox_host_only_network\
--vboxdir=$vbox_vboxdir\
--template-vmname=$vm_template_vmname\
--config=$config
else
xec kvm/provision-vms\
--create-template=$vm_create_template\
--linux=$vm_linux\
--template-vmname=$vm_template_vmname\
--config=$config\
--os-variant=$kvm_os_variant
fi
fi
echo "generating root CA to $DTKBASE/generated/cert/ca.pem (and ca-key.pem)"
xec gen-root-ca
echo "generating Kubernetes core cluster"
xec gen-core-k8s\
--containerized-cplane=$k8s_containerized_cplane\
--kube-proxy-enabled=$k8s_kube_proxy\
--priv-key=$DTKBASE/generated/kickstart/id_ed25519\
--ca-cert=$DTKBASE/generated/cert/ca.pem\
--ca-key=$DTKBASE/generated/cert/ca-key.pem\
--config=$config\
--cluster-cidr=$k8s_cluster_cidr\
--virt=$virt
echo "installing add-ons"
xec install-addons\
--config=$config\
--admin-kubeconfig=$DTKBASE/generated/kubeconfig/admin.kubeconfig\
--priv-key=$DTKBASE/generated/kickstart/id_ed25519
echo
echo "finished provisioning cluster. To interact with the cluster:"
echo " export KUBECONFIG=$DTKBASE/generated/kubeconfig/admin.kubeconfig"
echo
echo "use the 'sshto' script to ssh into a VM"