Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
222 lines (206 sloc) 9.92 KB
# -*- mode: ruby -*-
# vi: set ft=ruby Vagrant.require_version ">= 2.2.0"
# The source of truth for vagrant box versions.
# Sets SERVER_BOX, SERVER_VERSION, NETNEXT_SERVER_BOXET and NEXT_SERVER_VERSION
# Accepts overrides from env variables
require_relative '../vagrant_box_defaults.rb'
$SERVER_BOX = (ENV['SERVER_BOX'] || $SERVER_BOX)
$SERVER_VERSION= (ENV['SERVER_VERSION'] || $SERVER_VERSION)
$NETNEXT_SERVER_BOX = (ENV['NETNEXT_SERVER_BOX'] || $NETNEXT_SERVER_BOX)
$NETNEXT_SERVER_VERSION= (ENV['NETNEXT_SERVER_VERSION'] || $NETNEXT_SERVER_VERSION)
$BUILD_NUMBER = ENV['BUILD_NUMBER'] || "0"
$JOB_NAME = ENV['JOB_BASE_NAME'] || "LOCAL"
$K8S_VERSION = ENV['K8S_VERSION'] || "1.19"
$K8S_NODES = (ENV['K8S_NODES'] || "2").to_i
$NFS = ENV['NFS']=="1"? true : false
$IPv6=(ENV['IPv6'] || "0")
$CONTAINER_RUNTIME=(ENV['CONTAINER_RUNTIME'] || "docker")
$CNI_INTEGRATION=(ENV['CNI_INTEGRATION'] || "")
$CILIUM_IMAGE = ENV['CILIUM_IMAGE'] || ""
$CILIUM_TAG = ENV['CILIUM_TAG'] || ""
$CILIUM_OPERATOR_IMAGE = ENV['CILIUM_OPERATOR_IMAGE'] || ""
$CILIUM_OPERATOR_TAG = ENV['CILIUM_OPERATOR_TAG'] || ""
$HUBBLE_RELAY_IMAGE = ENV['HUBBLE_RELAY_IMAGE'] || ""
$HUBBLE_RELAY_TAG = ENV['HUBBLE_RELAY_TAG'] || ""
$PRELOAD_VM = ENV['PRELOAD_VM'] || "false"
$PROVISION_EXTERNAL_WORKLOAD = ENV['PROVISION_EXTERNAL_WORKLOAD'] || "false"
$SKIP_K8S_PROVISION = ENV['SKIP_K8S_PROVISION'] || "false"
$NO_CILIUM_ON_NODE = ENV['NO_CILIUM_ON_NODE'] || ""
$KUBEPROXY = (ENV['KUBEPROXY'] || "1")
$RACE = ENV['RACE'] || ""
$LOCKDEBUG = ENV['LOCKDEBUG'] || ""
$BASE_IMAGE = ENV['BASE_IMAGE'] || ""
$DOCKER_LOGIN = ENV['DOCKER_LOGIN'] || ""
$DOCKER_PASSWORD = ENV['DOCKER_PASSWORD'] || ""
# RAM and CPU settings
$MEMORY = (ENV['VM_MEMORY'] || "4096").to_i
$CPU = (ENV['VM_CPUS'] || "2").to_i
if ENV['NETNEXT'] == "true" || ENV['NETNEXT'] == "1" || ENV['KERNEL'] == "net-next" then
$SERVER_BOX = $NETNEXT_SERVER_BOX
$SERVER_VERSION = $NETNEXT_SERVER_VERSION
elsif ENV['KERNEL'] != nil && ENV['KERNEL'] != "" then
$SERVER_BOX = instance_variable_get("@v"+ ENV['KERNEL'] + "_SERVER_BOX")
$SERVER_VERSION = instance_variable_get("@v"+ ENV['KERNEL'] + "_SERVER_VERSION")
end
# Workaround issue as described here:
# https://github.com/cilium/cilium/pull/12520
class VagrantPlugins::ProviderVirtualBox::Action::Network
def dhcp_server_matches_config?(dhcp_server, config)
true
end
end
Vagrant.configure("2") do |config|
cilium_dir = '../'
cilium_path = '/home/vagrant/go/src/github.com/cilium/cilium'
if ENV["SHARE_PARENT"] then
cilium_dir = '../..'
cilium_path = '/home/vagrant/go/src/github.com/cilium'
end
config.vm.define "runtime" do |server|
server.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
vb.cpus = $CPU
vb.memory= $MEMORY
vb.linked_clone = true
vb.default_nic_type = "virtio"
# Prevent VirtualBox from interfering with host audio stack
vb.customize ["modifyvm", :id, "--audio", "none"]
end
server.vm.box = "#{$SERVER_BOX}"
server.vm.box_version = $SERVER_VERSION
server.vm.boot_timeout = 600
server.vm.hostname = "runtime"
server.vm.network "private_network",
ip: "192.168.36.10",
virtualbox__intnet: "cilium-k8s#{$BUILD_NUMBER}-#{$JOB_NAME}-#{$K8S_VERSION}"
server.vm.network "private_network",
ip: "192.168.37.10",
virtualbox__intnet: "cilium-k8s-2#{$BUILD_NUMBER}-#{$JOB_NAME}-#{$K8S_VERSION}"
# @TODO: Clean this one when https://github.com/hashicorp/vagrant/issues/9822 is fixed.
server.vm.provision "ipv6-config-primary",
type: "shell",
run: "always",
inline: "ip -6 a a fd04::1/96 dev enp0s8 || true"
server.vm.provision "ipv6-config-secondary",
type: "shell",
run: "always",
inline: "ip -6 a a fd05::1/96 dev enp0s9 || true"
# This network is only used by NFS
if $NFS
# This network is only used by NFS
server.vm.network "private_network", ip: "192.168.38.10"
server.vm.synced_folder cilium_dir, cilium_path, type: "nfs", nfs_udp: false
else
server.vm.synced_folder cilium_dir, cilium_path
end
# Provision section
server.vm.provision :shell,
:inline => "sed -i 's/^mesg n$/tty -s \\&\\& mesg n/g' /root/.profile"
# Disable unattended-upgrades to prevent it from holding the dpkg frontend lock
# To be removed once this has been added through packer-ci-build
server.vm.provision :shell,
:inline => "sudo systemctl disable unattended-upgrades.service"
server.vm.provision :shell,
:inline => "sudo systemctl stop unattended-upgrades.service"
server.vm.provision :shell,
:inline => "echo 'export GOPATH=$(go env GOPATH)' >> /home/vagrant/.bashrc"
server.vm.provision "file", source: "provision/", destination: "/tmp/"
server.vm.provision "shell" do |sh|
sh.path = "./provision/runtime_install.sh"
sh.env = {
"RACE" => "#{$RACE}",
"LOCKDEBUG" => "#{$LOCKDEBUG}",
"BASE_IMAGE" => "#{$BASE_IMAGE}",
"PROVISION_EXTERNAL_WORKLOAD" => "#{$PROVISION_EXTERNAL_WORKLOAD}"
}
end
end
(1..$K8S_NODES).each do |i|
config.vm.define "k8s#{i}-#{$K8S_VERSION}" do |server|
server.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
vb.cpus = $CPU
vb.memory = $MEMORY
if "k8s#{i}" == $NO_CILIUM_ON_NODE
vb.memory = $MEMORY / 2
vb.cpus = 1
end
vb.linked_clone = true
vb.default_nic_type = "virtio"
# Prevent VirtualBox from interfering with host audio stack
vb.customize ["modifyvm", :id, "--audio", "none"]
if ENV['PRELOAD_VM'] == "false" then
# Use serial ports if the VM is no longer accessible via SSH
vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
vb.customize ["modifyvm", :id, "--uartmode1", "server", "k8s#{i}-#{$K8S_VERSION}-ttyS0.sock"]
end
end
server.vm.box = "#{$SERVER_BOX}"
server.vm.box_version = $SERVER_VERSION
server.vm.hostname = "k8s#{i}"
server.vm.boot_timeout = 600
if i == 1 then
# grafana
server.vm.network "forwarded_port", guest: 3000, host: 3000,
auto_correct: true
server.vm.network "forwarded_port", guest: 6443, host: 9443,
auto_correct: true
end
server.vm.network "private_network",
ip: "192.168.36.1#{i}",
virtualbox__intnet: "cilium-k8s#{$BUILD_NUMBER}-#{$JOB_NAME}-#{$K8S_VERSION}"
server.vm.network "private_network",
ip: "192.168.37.1#{i}",
virtualbox__intnet: "cilium-k8s-2#{$BUILD_NUMBER}-#{$JOB_NAME}-#{$K8S_VERSION}"
# @TODO: Clean this one when https://github.com/hashicorp/vagrant/issues/9822 is fixed.
server.vm.provision "ipv6-config-primary",
type: "shell",
run: "always",
inline: "ip -6 a a fd04::1#{i}/96 dev enp0s8 || true"
server.vm.provision "ipv6-config-secondary",
type: "shell",
run: "always",
inline: "ip -6 a a fd05::1#{i}/96 dev enp0s9 || true"
if $NFS
# This network is only used by NFS
server.vm.network "private_network", ip: "192.168.38.1#{i}"
server.vm.synced_folder cilium_dir, cilium_path, type: "nfs", nfs_udp: false
else
server.vm.synced_folder cilium_dir, cilium_path
end
# Provision section
server.vm.provision :shell,
:inline => "sudo sysctl -w net.ipv6.conf.all.forwarding=1"
server.vm.provision :shell,
:inline => "sed -i 's/^mesg n$/tty -s \\&\\& mesg n/g' /root/.profile"
# Disable unattended-upgrades to prevent it from holding the dpkg frontend lock
# To be removed once this has been added through packer-ci-build
server.vm.provision :shell,
:inline => "sudo systemctl disable unattended-upgrades.service"
server.vm.provision :shell,
:inline => "sudo systemctl stop unattended-upgrades.service"
server.vm.provision "file", source: "provision/", destination: "/tmp/"
server.vm.provision "shell" do |sh|
sh.path = "./provision/k8s_install.sh"
sh.args = [
"k8s#{i}", "192.168.36.1#{i}", "#{$K8S_VERSION}",
"#{$IPv6}", "#{$CONTAINER_RUNTIME}", "#{$CNI_INTEGRATION}"]
sh.env = {"CILIUM_IMAGE" => "#{$CILIUM_IMAGE}",
"CILIUM_TAG" => "#{$CILIUM_TAG}",
"CILIUM_OPERATOR_IMAGE" => "#{$CILIUM_OPERATOR_IMAGE}",
"CILIUM_OPERATOR_TAG" => "#{$CILIUM_OPERATOR_TAG}",
"HUBBLE_RELAY_IMAGE" => "#{$HUBBLE_RELAY_IMAGE}",
"HUBBLE_RELAY_TAG" => "#{$HUBBLE_RELAY_TAG}",
"PRELOAD_VM" => "#{$PRELOAD_VM}",
"SKIP_K8S_PROVISION" => "#{$SKIP_K8S_PROVISION}",
"KUBEPROXY" => "#{$KUBEPROXY}",
"RACE" => "#{$RACE}",
"LOCKDEBUG" => "#{$LOCKDEBUG}",
"BASE_IMAGE" => "#{$BASE_IMAGE}",
"DOCKER_LOGIN" => "#{$DOCKER_LOGIN}",
"DOCKER_PASSWORD" => "#{$DOCKER_PASSWORD}"
}
end
end
end
end
You can’t perform that action at this time.