forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
275 lines (251 loc) · 12.1 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 2.0.0"
if ARGV.first == "up" && ENV['CILIUM_SCRIPT'] != 'true'
raise Vagrant::Errors::VagrantError.new, <<END
Calling 'vagrant up' directly is not supported. Instead, please run the following:
export NWORKERS=n
./contrib/vagrant/start.sh
END
end
if ENV['IPV4'] == '0'
raise Vagrant::Errors::VagrantError.new, <<END
Disabling IPv4 is currently not allowed until k8s 1.9 is released
END
end
$bootstrap = <<SCRIPT
echo "----------------------------------------------------------------"
export PATH=/home/vagrant/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
echo "editing journald configuration"
sudo bash -c "echo RateLimitIntervalSec=1s >> /etc/systemd/journald.conf"
sudo bash -c "echo RateLimitBurst=10000 >> /etc/systemd/journald.conf"
echo "restarting systemd-journald"
sudo systemctl restart systemd-journald
echo "getting status of systemd-journald"
sudo service systemd-journald status
echo "done configuring journald"
sudo service docker restart
echo 'cd ~/go/src/github.com/cilium/cilium' >> /home/vagrant/.bashrc
sudo -E /usr/local/go/bin/go get github.com/cilium/go-bindata/...
sudo -E /usr/local/go/bin/go get -u github.com/google/gops
sudo -E /usr/local/go/bin/go get -d github.com/lyft/protoc-gen-validate
sudo -E /usr/local/go/bin/go get -u github.com/gordonklaus/ineffassign
(cd ~/go/src/github.com/lyft/protoc-gen-validate ; sudo git checkout 930a67cf7ba41b9d9436ad7a1be70a5d5ff6e1fc ; make build)
sudo chown -R vagrant:vagrant /home/vagrant 2>/dev/null
curl -SsL https://github.com/cilium/bpf-map/releases/download/v1.0/bpf-map -o bpf-map
chmod +x bpf-map
mv bpf-map /usr/bin
SCRIPT
$build = <<SCRIPT
export PATH=/home/vagrant/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
~/go/src/github.com/cilium/cilium/common/build.sh
rm -fr ~/go/bin/cilium*
SCRIPT
$install = <<SCRIPT
sudo -E make -C /home/vagrant/go/src/github.com/cilium/cilium/ install
sudo mkdir -p /etc/sysconfig
sudo cp /home/vagrant/go/src/github.com/cilium/cilium/contrib/systemd/cilium-consul.service /lib/systemd/system
sudo cp /home/vagrant/go/src/github.com/cilium/cilium/contrib/systemd/cilium-docker.service /lib/systemd/system
sudo cp /home/vagrant/go/src/github.com/cilium/cilium/contrib/systemd/cilium-etcd.service /lib/systemd/system
sudo cp /home/vagrant/go/src/github.com/cilium/cilium/contrib/systemd/cilium.service /lib/systemd/system
sudo cp /home/vagrant/go/src/github.com/cilium/cilium/contrib/systemd/cilium /etc/sysconfig
sudo usermod -a -G cilium vagrant
SCRIPT
$testsuite = <<SCRIPT
sudo -E env PATH="${PATH}" make -C ~/go/src/github.com/cilium/cilium/ runtime-tests
SCRIPT
$node_ip_base = ENV['IPV4_BASE_ADDR'] || ""
$node_nfs_base_ip = ENV['IPV4_BASE_ADDR_NFS'] || ""
$num_workers = (ENV['NWORKERS'] || 0).to_i
$workers_ipv4_addrs = $num_workers.times.collect { |n| $node_ip_base + "#{n+(ENV['FIRST_IP_SUFFIX']).to_i+1}" }
$workers_ipv4_addrs_nfs = $num_workers.times.collect { |n| $node_nfs_base_ip + "#{n+(ENV['FIRST_IP_SUFFIX_NFS']).to_i+1}" }
$master_ip = ENV['MASTER_IPV4']
$master_ipv6 = ENV['MASTER_IPV6_PUBLIC']
$workers_ipv6_addrs_str = ENV['IPV6_PUBLIC_WORKERS_ADDRS'] || ""
$workers_ipv6_addrs = $workers_ipv6_addrs_str.split(' ')
# Create unique ID for use in vboxnet name so Jenkins pipeline can have concurrent builds.
$job_name = ENV['JOB_BASE_NAME'] || "local"
$build_number = ENV['BUILD_NUMBER'] || "0"
$build_id = "#{$job_name}-#{$build_number}"
# Only create the build_id_name for Jenkins environment so that
# we can run VMs locally without having any the `build_id` in the name.
if ENV['BUILD_NUMBER'] then
$build_id_name = "-build-#{$build_id}"
end
if ENV['K8S'] then
$vm_base_name = "k8s"
else
$vm_base_name = "runtime"
end
# Set locate to en_US.UTF-8
ENV["LC_ALL"] = "en_US.UTF-8"
ENV["LC_CTYPE"] = "en_US.UTF-8"
# We need this workaround since kube-proxy is not aware of multiple network
# interfaces. If we send a packet to a service IP that packet is sent
# to the default route, because the service IP is unknown by the linux routing
# table, with the source IP of the interface in the default routing table, even
# though the service IP should be routed to a different interface.
# This particular workaround is only needed for cilium, running on a pod on host
# network namespace, to reach out kube-api-server.
$kube_proxy_workaround = <<SCRIPT
sudo iptables -t nat -A POSTROUTING -o enp0s8 ! -s 192.168.34.12 -j MASQUERADE
SCRIPT
Vagrant.configure(2) do |config|
config.vm.provision "bootstrap", type: "shell", inline: $bootstrap
config.vm.provision "build", type: "shell", run: "always", privileged: false, inline: $build
config.vm.provision "install", type: "shell", run: "always", privileged: false, inline: $install
config.vm.provider "virtualbox" do |vb|
# Do not inherit DNS server from host, use proxy
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
# Prevent VirtualBox from interfering with host audio stack
vb.customize ["modifyvm", :id, "--audio", "none"]
config.vm.box = "cilium/ubuntu-dev"
config.vm.box_version = "138"
vb.memory = ENV['VM_MEMORY'].to_i
vb.cpus = ENV['VM_CPUS'].to_i
if ENV["NFS"] then
mount_type = "nfs"
# Don't forget to enable this ports on your host before starting the VM
# in order to have nfs working
# iptables -I INPUT -p udp -s 192.168.34.0/24 --dport 111 -j ACCEPT
# iptables -I INPUT -p udp -s 192.168.34.0/24 --dport 2049 -j ACCEPT
# iptables -I INPUT -p udp -s 192.168.34.0/24 --dport 20048 -j ACCEPT
else
mount_type = ""
end
config.vm.synced_folder '.', '/home/vagrant/go/src/github.com/cilium/cilium', type: mount_type
if ENV['USER_MOUNTS'] then
# Allow multiple mounts divided by commas
ENV['USER_MOUNTS'].split(",").each do |mnt|
# Split "<to>=<from>"
user_mount = mnt.split("=", 2)
# Only one element, assume a path relative to home directories in both ends
if user_mount.length == 1 then
user_mount_to = "/home/vagrant/" + user_mount[0]
user_mount_from = "~/" + user_mount[0]
else
user_mount_to = user_mount[0]
# Remove "~/" prefix if any.
if user_mount_to.start_with?('~/') then
user_mount_to[0..1] = ''
end
# Add home directory prefix for non-absolute paths
if !user_mount_to.start_with?('/') then
user_mount_to = "/home/vagrant/" + user_mount_to
end
user_mount_from = user_mount[1]
# Add home prefix for host for any path in the project directory
# as it is already mounted.
if !user_mount_from.start_with?('/', '.', '~') then
user_mount_from = "~/" + user_mount_from
end
end
puts "Mounting host directory #{user_mount_from} as #{user_mount_to}"
config.vm.synced_folder "#{user_mount_from}", "#{user_mount_to}", type: mount_type
end
end
end
master_vm_name = "#{$vm_base_name}1#{$build_id_name}"
config.vm.define master_vm_name, primary: true do |cm|
node_ip = "#{$master_ip}"
cm.vm.network "forwarded_port", guest: 6443, host: 7443
cm.vm.network "private_network", ip: "#{$master_ip}",
virtualbox__intnet: "cilium-test-#{$build_id}",
:libvirt__guest_ipv6 => "yes",
:libvirt__dhcp_enabled => false
if ENV["NFS"] || ENV["IPV6_EXT"] then
if ENV['FIRST_IP_SUFFIX_NFS'] then
$nfs_ipv4_master_addr = $node_nfs_base_ip + "#{ENV['FIRST_IP_SUFFIX_NFS']}"
end
cm.vm.network "private_network", ip: "#{$nfs_ipv4_master_addr}", bridge: "enp0s9"
# Add IPv6 address this way or we get hit by a virtualbox bug
cm.vm.provision "ipv6-config",
type: "shell",
run: "always",
inline: "ip -6 a a #{$master_ipv6}/16 dev enp0s9"
node_ip = "#{$nfs_ipv4_master_addr}"
if ENV["IPV6_EXT"] then
node_ip = "#{$master_ipv6}"
end
end
cm.vm.hostname = "#{$vm_base_name}1"
if ENV['CILIUM_TEMP'] then
if ENV["K8S"] then
k8sinstall = "#{ENV['CILIUM_TEMP']}/cilium-k8s-install-1st-part.sh"
cm.vm.provision "k8s-install-master-part-1",
type: "shell",
run: "always",
env: {"node_ip" => node_ip},
privileged: true,
path: k8sinstall
end
script = "#{ENV['CILIUM_TEMP']}/node-1.sh"
cm.vm.provision "config-install", type: "shell", privileged: true, run: "always", path: script
# In k8s mode cilium needs etcd in order to run which was started in
# the first part of the script. The 2nd part will install the
# policies into kubernetes and cilium.
if ENV["K8S"] then
k8sinstall = "#{ENV['CILIUM_TEMP']}/cilium-k8s-install-2nd-part.sh"
cm.vm.provision "k8s-install-master-part-2",
type: "shell",
run: "always",
env: {"node_ip" => node_ip},
privileged: true,
path: k8sinstall
end
end
if ENV['RUN_TEST_SUITE'] then
cm.vm.provision "testsuite", run: "always", type: "shell", privileged: false, inline: $testsuite
end
end
$num_workers.times do |n|
# n starts with 0
node_vm_name = "#{$vm_base_name}#{n+2}#{$build_id_name}"
node_hostname = "#{$vm_base_name}#{n+2}"
config.vm.define node_vm_name do |node|
node_ip = $workers_ipv4_addrs[n]
node.vm.network "private_network", ip: "#{node_ip}",
virtualbox__intnet: "cilium-test-#{$build_id}",
:libvirt__guest_ipv6 => 'yes',
:libvirt__dhcp_enabled => false
if ENV["NFS"] || ENV["IPV6_EXT"] then
nfs_ipv4_addr = $workers_ipv4_addrs_nfs[n]
node_ip = "#{nfs_ipv4_addr}"
ipv6_addr = $workers_ipv6_addrs[n]
node.vm.network "private_network", ip: "#{nfs_ipv4_addr}", bridge: "enp0s9"
# Add IPv6 address this way or we get hit by a virtualbox bug
node.vm.provision "ipv6-config",
type: "shell",
run: "always",
inline: "ip -6 a a #{ipv6_addr}/16 dev enp0s9"
if ENV["IPV6_EXT"] then
node_ip = "#{ipv6_addr}"
end
end
node.vm.hostname = "#{$vm_base_name}#{n+2}"
if ENV['CILIUM_TEMP'] then
if ENV["K8S"] then
k8sinstall = "#{ENV['CILIUM_TEMP']}/cilium-k8s-install-1st-part.sh"
node.vm.provision "k8s-install-node-part-1",
type: "shell",
run: "always",
env: {"node_ip" => node_ip},
privileged: true,
path: k8sinstall
end
script = "#{ENV['CILIUM_TEMP']}/node-#{n+2}.sh"
node.vm.provision "config-install", type: "shell", privileged: true, run: "always", path: script
if ENV["K8S"] then
k8sinstall = "#{ENV['CILIUM_TEMP']}/cilium-k8s-install-2nd-part.sh"
node.vm.provision "k8s-install-node-part-2",
type: "shell",
run: "always",
env: {"node_ip" => node_ip},
privileged: true,
path: k8sinstall
end
end
end
end
end