-
Notifications
You must be signed in to change notification settings - Fork 21
/
Vagrantfile
344 lines (322 loc) · 11 KB
/
Vagrantfile
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
CPUS = (ENV['VAGRANT_RKE2_SELINUX_CPUS'] || 2).to_i
MEMORY = (ENV['VAGRANT_RKE2_SELINUX_MEMORY'] || 2048).to_i
# Adapted from https://github.com/containerd/containerd/pull/4451
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.provider :virtualbox do |v|
config.vm.box_url = "https://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box"
v.memory = MEMORY
v.cpus = CPUS
end
config.vm.provider :libvirt do |v|
config.vm.box_url = "https://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-2004_01.LibVirt.box"
v.memory = MEMORY
v.cpus = CPUS
end
# Disabled by default. To run:
# vagrant up --provision-with=upgrade-packages
# To upgrade only specific packages:
# UPGRADE_PACKAGES=selinux vagrant up --provision-with=upgrade-packages
#
config.vm.provision "upgrade-packages", type: "shell", run: "never" do |sh|
sh.upload_path = "/tmp/vagrant-upgrade-packages"
sh.env = {
'UPGRADE_PACKAGES': ENV['UPGRADE_PACKAGES'],
}
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
yum -y upgrade ${UPGRADE_PACKAGES}
SHELL
end
# Disabled by default. To run:
# vagrant provision --provision-with=kernel-mainline
config.vm.provision "kernel-mainline", type: "shell", run: "never" do |sh|
sh.upload_path = "/tmp/vagrant-kernel-mainline"
sh.inline = <<~SHELL
#!/usr/bin/env bash
yum -y install \
https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel -y install kernel-ml
sed -i -e "s|GRUB_DEFAULT.*$|GRUB_DEFAULT=0|" /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
SHELL
sh.reboot = true
end
# To re-run, installing CNI from RPM:
# INSTALL_PACKAGES="containernetworking-plugins" vagrant up --provision-with=install-packages
#
config.vm.provision "install-packages", type: "shell", run: "once" do |sh|
sh.upload_path = "/tmp/vagrant-install-packages"
sh.env = {
'INSTALL_PACKAGES': ENV['INSTALL_PACKAGES'],
}
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
yum -y install \
bzip2 \
container-selinux \
curl \
gcc \
git \
iptables \
libseccomp-devel \
libselinux-devel \
lsof \
make \
selinux-policy-devel \
socat \
${INSTALL_PACKAGES}
SHELL
end
config.vm.provision "install-policy", type: "shell", run: "always" do |sh|
sh.upload_path = "/tmp/vagrant-install-policy"
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
pushd /vagrant
yum install -y yum-utils rpm-build
yum-builddep -y container-selinux
yum -y remove rke2-selinux
# TODO build
yum -y install ./dist/centos7/noarch/*.rpm
SHELL
end
# To re-run this provisioner, installing a different version of go:
# GO_VERSION="1.15rc2" vagrant up --provision-with=install-golang
#
config.vm.provision "install-golang", type: "shell", run: "once" do |sh|
sh.upload_path = "/tmp/vagrant-install-golang"
sh.env = {
'GO_VERSION': ENV['GO_VERSION'] || "1.13.15",
}
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
curl -fsSL "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" | tar Cxz /usr/lib
ln -fnsv /usr/lib/go/bin/{go,gofmt} /usr/bin
SHELL
end
config.vm.provision "install-runc", type: "shell", run: "once" do |sh|
sh.upload_path = "/tmp/vagrant-install-runc"
sh.env = {
'GOPATH': "/usr",
'RUNC_VERSION': ENV['RUNC_VERSION'] || "v1.0.0-rc92",
}
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
go get -d github.com/opencontainers/runc
pushd ${GOPATH}/src/github.com/opencontainers/runc
git checkout ${RUNC_VERSION}
make BUILDTAGS='apparmor seccomp selinux' runc
make BINDIR=${GOPATH}/bin install
type runc
runc --version
restorecon -v $(type -ap runc)
SHELL
end
config.vm.provision "install-cni", type: "shell", run: "once" do |sh|
sh.upload_path = "/tmp/vagrant-install-cni"
sh.env = {
'GOPATH': "/usr",
'CNI_DIR': "/opt/cni",
'CNI_CONFIG_DIR': "/etc/cni/net.d",
'CNI_PLUGINS_VERSION': ENV['CNI_PLUGINS_VERSION'] || "v0.7.6",
'CNI_PLUGINS_BINARIES': 'bridge dhcp flannel host-device host-local ipvlan loopback macvlan portmap ptp tuning vlan',
}
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
go get -d github.com/containernetworking/plugins/...
pushd "$GOPATH"/src/github.com/containernetworking/plugins
git checkout $CNI_PLUGINS_VERSION
FASTBUILD=true ./build.sh
sudo mkdir -p $CNI_DIR
sudo cp -r ./bin $CNI_DIR
sudo mkdir -p $CNI_CONFIG_DIR
PATH=/opt/cni/bin:$PATH type ${CNI_PLUGINS_BINARIES} || true
cat <<EOF | sudo tee $CNI_CONFIG_DIR/10-containerd-net.conflist
{
"cniVersion": "0.3.1",
"name": "containerd-net",
"plugins": [
{
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"promiscMode": true,
"ipam": {
"type": "host-local",
"subnet": "10.88.0.0/16",
"routes": [
{ "dst": "0.0.0.0/0" }
]
}
},
{
"type": "portmap",
"capabilities": {"portMappings": true}
}
]
}
EOF
SHELL
end
config.vm.provision "install-containerd", type: "shell", run: "once" do |sh|
sh.upload_path = "/tmp/vagrant-install-containerd"
sh.env = {
'GOPATH': "/usr",
'CONTAINERD_REPO': ENV['CONTAINERD_REPO'] || "github.com/rancher/containerd",
'CONTAINERD_VERSION': ENV['CONTAINERD_VERSION'] || "v1.3.6-k3s2",
}
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
if [ ! -d ${GOPATH}/src/github.com/containerd/containerd ]; then
git clone https://${CONTAINERD_REPO}.git ${GOPATH}/src/github.com/containerd/containerd
fi
pushd ${GOPATH}/src/github.com/containerd/containerd
git checkout ${CONTAINERD_VERSION}
make PACKAGE=${CONTAINERD_REPO} \
DESTDIR=${GOPATH} \
BUILDTAGS="seccomp selinux no_aufs no_btrfs no_devmapper no_zfs" \
binaries install
type containerd
containerd --version
restorecon -v /usr/bin/{containerd,containerd-shim*}
SHELL
end
config.vm.provision "install-cri-tools", type: "shell", run: "once" do |sh|
sh.upload_path = "/tmp/vagrant-install-cri-tools"
sh.env = {
'GOPATH': "/usr",
'CRI_TOOLS_VERSION': ENV['CRI_TOOLS_VERSION'] || 'master',
}
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
go get -u github.com/onsi/ginkgo/ginkgo
go get -d github.com/kubernetes-sigs/cri-tools/...
pushd ${GOPATH}/src/github.com/kubernetes-sigs/cri-tools
git checkout $CRI_TOOLS_VERSION
make
sudo make BINDIR=${GOPATH}/bin install
cat << EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///run/k3s/containerd/containerd.sock
EOF
type crictl critest ginkgo
critest --version
SHELL
end
# SELinux is Enforcing by default.
# To set SELinux as Disabled on a VM that has already been provisioned:
# SELINUX=Disabled vagrant up --provision-with=selinux
# To set SELinux as Permissive on a VM that has already been provsioned
# SELINUX=Permissive vagrant up --provision-with=selinux
config.vm.provision "selinux", type: "shell", run: "once" do |sh|
sh.upload_path = "/tmp/vagrant-selinux"
sh.env = {
'SELINUX': ENV['SELINUX'] || "Enforcing"
}
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
if ! type -p getenforce setenforce &>/dev/null; then
echo SELinux is Disabled
exit 0
fi
case "${SELINUX}" in
Disabled)
if mountpoint -q /sys/fs/selinux; then
setenforce 0
umount -v /sys/fs/selinux
fi
;;
Enforcing)
mountpoint -q /sys/fs/selinux || mount -o rw,relatime -t selinuxfs selinuxfs /sys/fs/selinux
setenforce 1
;;
Permissive)
mountpoint -q /sys/fs/selinux || mount -o rw,relatime -t selinuxfs selinuxfs /sys/fs/selinux
setenforce 0
;;
*)
echo "SELinux mode not supported: ${SELINUX}" >&2
exit 1
;;
esac
echo SELinux is $(getenforce)
SHELL
end
# SELinux is permissive by default (via provisioning) in this VM. To re-run with SELinux enforcing:
# vagrant up --provision-with=selinux-enforcing,test-cri
#
config.vm.provision "test-cri", type: "shell", run: "never" do |sh|
sh.upload_path = "/tmp/test-cri"
sh.env = {
'CRITEST_ARGS': ENV['CRITEST_ARGS'],
}
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
cat << EOF > /vagrant/containerd.service
[Unit]
Description=rke2 containerd
Documentation=https://github.com/rancher/rke2
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd \
-c /var/lib/rancher/rke2/agent/etc/containerd/config.toml \
-a /run/k3s/containerd/containerd.sock \
--state /run/k3s/containerd \
--root /var/lib/rancher/rke2/agent/containerd \
Delegate=yes
KillMode=process
Restart=always
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=1048576
TasksMax=infinity
[Install]
WantedBy=multi-user.target
EOF
systemctl disable --now containerd || true
rm -rf /var/lib/rancher/rke2 /run/rke2
enable_selinux=false
if [[ $(getenforce) != Disabled ]]; then
enable_selinux=true
fi
mkdir -p /var/lib/rancher/rke2/agent/etc/containerd
cat << EOF | sudo tee /var/lib/rancher/rke2/agent/etc/containerd/config.toml
version = 2
[plugins]
[plugins."io.containerd.grpc.v1.cri"]
enable_selinux = ${enable_selinux}
EOF
chcon -v -t container_unit_file_t /vagrant/containerd.service
systemctl enable --now /vagrant/containerd.service
function cleanup()
{
journalctl -u containerd > /tmp/containerd.log
systemctl stop containerd
}
trap cleanup EXIT
ctr --address /run/k3s/containerd/containerd.sock version
critest --parallel=$(nproc) --ginkgo.skip='runtime should support HostIpc is true' ${CRITEST_ARGS}
SHELL
end
config.vm.provision "rke2", type: "shell", run: "once" do |sh|
sh.upload_path = "/tmp/vagrant-rke2"
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
curl -sfL https://get.rke2.io | sh -
SHELL
end
end