-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdo-kind.sh
executable file
·345 lines (300 loc) · 10.2 KB
/
do-kind.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
#!/bin/bash
set -o errexit
set -x
topdir=$(pwd)
rundir=${topdir}/runtime
ovn_kind_heater_utils=${topdir}/ovn-kind-heater-utils
ovn_kh_playbooks=${ovn_kind_heater_utils}/playbooks
ovn_k8s_docker_file=${ovn_kind_heater_utils}/scripts/Dockerfile.ovnk8s.fedora
hosts_file=${rundir}/hosts
deployment_dir=${topdir}/physical-deployments
phys_deployment="${PHYS_DEPLOYMENT:-${deployment_dir}/physical-deployment.yml}"
installer_log_file=${rundir}/installer-log
ovn_kh_venv=venv
ovn_kh_tester=${topdir}/ovn-kind-heater-tester
ovn_khosts_generate=${ovn_kind_heater_utils}/generate-hosts.py
n_k8s_workers="${NUM_K8S_WORKERS:-5}"
ovn_kind_heater_log_file=test-log
# OVS/OVN env vars
ovs_repo="${OVS_REPO:-https://github.com/openvswitch/ovs.git}"
ovs_branch="${OVS_BRANCH:-master}"
ovn_repo="${OVN_REPO:-https://github.com/ovn-org/ovn.git}"
ovn_branch="${OVN_BRANCH:-main}"
ovn_k8s_repo="${OVN_K8S_REPO:-https://github.com/ovn-org/ovn-kubernetes.git}"
ovn_k8s_branch="${OVN_K8S_BRANCH:-master}"
os_image=${OS_IMAGE:-"registry.fedoraproject.org/fedora:32"}
function die() {
echo $1
exit 1
}
function generate() {
# Make sure rundir exists.
mkdir -p ${rundir}
install_venv
pushd ${rundir}
source ${ovn_kh_venv}/bin/activate
PYTHONPATH=${topdir}/utils python ${ovn_khosts_generate} ${phys_deployment} ${rundir} > ${hosts_file}
# PYTHONPATH=${topdir}/utils ${ovn_fmn_docker} ${phys_deployment} > ${docker_daemon_file}
# PYTHONPATH=${topdir}/utils ${ovn_fmn_podman} ${phys_deployment} > ${podman_registry_file}
deactivate
}
function clone_component() {
local comp_name=$1
local comp_repo=$2
local comp_branch=$3
local clonedir=$4
pushd ${clonedir}
local comp_exists="0"
if [ -d ${comp_name} ]; then
pushd ${comp_name}
local remote=$(git config --get remote.origin.url)
if [ "${remote}" = "${comp_repo}" ]; then
git fetch origin
if $(git show-ref --verify refs/tags/${comp_branch} &> /dev/null); then
local branch_diff=$(git diff ${comp_branch} HEAD --stat | wc -l)
else
local branch_diff=$(git diff origin/${comp_branch} HEAD --stat | wc -l)
fi
if [ "${branch_diff}" = "0" ]; then
comp_exists="1"
fi
fi
popd
fi
if [ ${comp_exists} = "1" ]; then
echo "-- Component ${comp_name} already installed"
else
rm -rf ${comp_name}
echo "-- Cloning ${comp_name} from ${comp_repo} at revision ${comp_branch}"
git clone ${comp_repo} ${comp_name}
pushd ${comp_name}
git checkout ${comp_branch}
popd
fi
popd
}
function install_deps() {
echo "-- Installing dependencies on all nodes"
ansible-playbook ${ovn_kh_playbooks}/install-dependencies.yml -i ${hosts_file}
echo "-- Installing local dependencies"
if yum install docker-ce --nobest -y || yum install -y docker
then
systemctl start docker
else
yum install -y podman podman-docker
fi
yum install redhat-lsb-core datamash \
python3-pip python3-virtualenv python3 python3-devel python-virtualenv \
--skip-broken -y
[ -e /usr/bin/pip ] || ln -sf /usr/bin/pip3 /usr/bin/pip
containers=$(docker ps --filter='name=(ovn|registry)' \
| grep -v "CONTAINER ID" | awk '{print $1}')
for container_name in $containers
do
docker stop $container_name
docker rm $container_name
done
[ -d /var/lib/registry ] || mkdir /var/lib/registry -p
docker run --privileged -d --name registry -p 5000:5000 \
-v /var/lib/registry:/var/lib/registry --restart=always docker.io/library/registry:2
cp /etc/containers/registries.conf /etc/containers/registries.conf.bak
cat > /etc/containers/registries.conf << EOF
[registries.search]
registries = ['registry.access.redhat.com', 'registry.redhat.io']
[registries.insecure]
registries = ['localhost:5000']
[registries.block]
registries = []
EOF
}
function install_venv() {
pushd ${rundir}
python3 -m virtualenv ${ovn_kh_venv}
source ${ovn_kh_venv}/bin/activate
pip install -r ${ovn_kh_tester}/requirements.txt
deactivate
popd
}
function configure_docker() {
echo "-- Configuring local registry on tester nodes"
if which podman
then
echo "-- Configuring podman local registry on all nodes"
ansible-playbook ${ovn_kh_playbooks}/configure-podman-registry.yml -i ${hosts_file}
else
echo "-- Configuring docker local registry on all nodes"
ansible-playbook ${ovn_kh_playbooks}/configure-docker-registry.yml -i ${hosts_file}
fi
}
function install_ovn_underlay() {
echo "-- Installing OVN underlay on all nodes"
ansible-playbook ${ovn_kh_playbooks}/install-ovn-underlay.yml -i ${hosts_file}
}
function create_ovn_underlay_resources() {
echo "-- Creating OVN underlay resources"
ansible-playbook ${ovn_kh_playbooks}/create-ovn-underlay-res.yml -i ${hosts_file}
}
function build_ovn_k8s_image() {
pushd ${rundir}
mkdir -p ovn-k8s-image-bin
pushd ovn-k8s-image-bin
clone_component ovn-kubernetes ${ovn_k8s_repo} ${ovn_k8s_branch} ${rundir}/ovn-k8s-image-bin
clone_component ovs ${ovs_repo} ${ovs_branch} ${rundir}/ovn-k8s-image-bin
clone_component ovn ${ovn_repo} ${ovn_branch} ${rundir}/ovn-k8s-image-bin
popd
cat > ovn-k8s-image-bin/build_ovn_k8s.sh << EOF
#!/bin/bash
set -x
dnf upgrade -y && dnf install --best --refresh -y --setopt=tsflags=nodocs \
python3-pyyaml bind-utils procps-ng openssl numactl-libs firewalld-filesystem \
libpcap hostname kubernetes-client python3-openvswitch python3-pyOpenSSL \
iptables iproute iputils strace socat\
@'Development Tools' rpm-build dnf-plugins-core kmod && \
dnf clean all && rm -rf /var/cache/dnf/*
dnf install -y autoconf automake libtool make openssl-devel wget
dnf install -y checkpolicy desktop-file-utils gcc-c++ groff libcap-ng-devel \
python3-devel selinux-policy-devel unbound unbound-devel python3-sphinx
echo "Building OVS"
pushd /root/sources/ovs
./boot.sh
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc --enable-ssl
make rpm-fedora
rm -rf /root/sources/bin
mkdir -p /root/sources/bin
cp rpm/rpmbuild/RPMS/x86_64/openvswitch-2*.rpm /root/sources/bin/
popd
pushd /root/sources/ovn
./boot.sh
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc --with-ovs-source=/root/sources/ovs
make rpm-fedora
cp rpm/rpmbuild/RPMS/x86_64/ovn*.rpm /root/sources/bin/
rm -f /root/sources/bin/*debug*.rpm
rm -f /root/sources/bin/ovn-docker*.rpm
rm -f /root/sources/bin/ovn-vtep*.rpm
popd
# Install golang
wget https://golang.org/dl/go1.17.1.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.17.1.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
pushd /root/sources/ovn-kubernetes/go-controller
make
cp _output/go/bin/* /root/sources/bin/
cp ../dist/images/ovnkube.sh /root/sources/bin/
cp ../dist/images/ovndb-raft-functions.sh /root/sources/bin/
cp -rf ../dist/images/iptables-scripts /root/sources/bin/
EOF
chmod 0755 ovn-k8s-image-bin/build_ovn_k8s.sh
docker rm -f ovn_image_build || :
docker run --privileged --network=host -v ${rundir}/ovn-k8s-image-bin:/root/sources --name ovn_image_build -it ${os_image} /root/sources/build_ovn_k8s.sh
docker rm -f ovn_image_build
popd
pushd ${rundir}/ovn-k8s-image-bin/bin
cp ${ovn_k8s_docker_file} .
echo "-- Building OVN K8s docker image"
docker build -t ovn-daemonset-f:dev --build-arg OS_IMAGE=${os_image} -f ${ovn_k8s_docker_file} .
docker tag ovn-daemonset-f:dev localhost:5000/ovn-daemonset-f:dev
docker push localhost:5000/ovn-daemonset-f:dev
}
function setup_kind() {
echo "-- Setting up kind on the nodes"
ansible-playbook ${ovn_kh_playbooks}/pull-ovn-k8s-image.yml -i ${hosts_file}
ansible-playbook ${ovn_kh_playbooks}/setup-kind.yml -i ${hosts_file}
}
function install() {
pushd ${rundir}
install_deps
configure_docker
popd
}
function setup() {
pushd ${rundir}
install_ovn_underlay
build_ovn_k8s_image
setup_kind
create_ovn_underlay_resources
popd
}
function deploy() {
echo "--Starting OVN services on kind nodes"
ansible-playbook ${ovn_kh_playbooks}/start-ovn-underlay.yml -i ${hosts_file}
echo "--Deploying base k8s cluster on central node"
ansible-playbook ${ovn_kh_playbooks}/deploy-ovn-k8s-kind.yml -i ${hosts_file}
source ${rundir}/${ovn_kh_venv}/bin/activate
#pushd ${out_dir}
echo "-- Adding k8s worker nodes"
python -u ${ovn_kh_tester}/ovn_kh_tester.py $phys_deployment ${n_k8s_workers} 2>&1 | tee ${ovn_kind_heater_log_file}
echo "-- Waiting for the nodes to be ready"
ansible-playbook ${ovn_kh_playbooks}/check-ovn-k8s-kind-ready.yml -i ${hosts_file}
}
function cleanup_kind() {
ansible-playbook ${ovn_kh_playbooks}/cleanup-kind.yml -i ${hosts_file}
ansible-playbook ${ovn_kh_playbooks}/stop-ovn-underlay.yml -i ${hosts_file}
}
function run() {
echo "run"
}
function usage() {
die "Usage: $0 install|setup|init|deploy|cleanup|run <scenario> <out-dir>"
}
do_lockfile=/tmp/do-kind.sh.lock
function take_lock() {
exec 42>${do_lockfile} || die "Failed setting FD for ${do_lockfile}"
flock -n 42 || die "Error: ovn-heater ($1) already running"
}
case "${1:-"usage"}" in
"install")
;&
"generate")
;&
"setup")
;&
"init")
;&
"deploy")
;&
"run")
take_lock $0
trap "rm -f ${do_lockfile}" EXIT
;;
esac
case "${1:-"usage"}" in
"install")
generate
# Store current environment variables.
(
echo "Environment:"
echo "============"
env
echo
) > ${installer_log_file}
# Run installer and store logs.
(
echo "Installer logs:"
echo "==============="
) >> ${installer_log_file}
install 2>&1 | tee -a ${installer_log_file}
;;
"generate")
generate
;;
"setup")
setup
;;
"init")
cleanup_kind
;;
"deploy")
deploy
;;
"cleanup")
cleanup_kind
;;
"run")
run
;;
*)
usage $0
;;
esac
exit 0