Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/jrajahalme/arm64 multipass 1.11.0 rebase #352

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
26910df
provision: Apply kernel-patches if they exist
jrajahalme Jan 3, 2022
2aea27a
build: Bump versions for arm64
jrajahalme Dec 8, 2021
0931626
provision: Generalize CPU architecture
jrajahalme Dec 8, 2021
3a7772f
provision: Do not use $HOME
jrajahalme Dec 8, 2021
be00df0
provision: Generalize user name
jrajahalme Dec 8, 2021
744c169
provision: change owner of home before trying to create 'go' directory
jrajahalme Dec 8, 2021
0f6966d
provision: Export GOPATH
jrajahalme Dec 8, 2021
84380a5
provision: Force links
jrajahalme Dec 8, 2021
ba0bb1d
provision: Do not overwrite SSH authorized keys
jrajahalme Dec 8, 2021
87ad122
provision: Install VirtualBox guest additions conditionally
jrajahalme Dec 8, 2021
a859fca
provision: Only install docker if not already installed
jrajahalme Dec 8, 2021
f0eea3d
netperf: Pull from sayboras/netperf
jrajahalme Dec 16, 2022
98f21f1
kernel: Generalize rules for 5.4 to all kernels > 4
jrajahalme Jan 3, 2023
7e2a458
install: Add git safe directory also for the normal user
jrajahalme Jan 4, 2023
3eacb23
ubuntu: Echo "Rebooting kernel" before reboot
jrajahalme Dec 14, 2021
abd240a
provision: Add top-level provisioning scripts for kernel install and …
jrajahalme Dec 8, 2021
07d79ed
provision: Install kind and kubectl by default
jrajahalme Aug 11, 2022
a4bdfda
fix: Allow reprovisioning
jrajahalme Jan 4, 2023
0b74c8a
ubuntu: Support 22.04, skip nodejs install
jrajahalme Feb 19, 2023
47e8ae9
build: Add script and make target for multipass
jrajahalme Dec 8, 2021
68d1112
multipass: Updates for Multipass 1.11
jrajahalme Jan 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@ clean:
install:
vagrant box add --force cilium/$(DISTRIBUTION) $(BOX_FILE)

.PHONY = build validate clean install
# Sane defaults for a VM used for development
VM_CPUS ?= 8
VM_MEMORY ?= 16G
VM_DISK ?= 100G
VM_NAME ?= dev

multipass:
VM_CPUS=$(VM_CPUS) VM_MEMORY=$(VM_MEMORY) VM_DISK=$(VM_DISK) provision/multipass.sh ${VM_NAME}

# VM_NAME must exists as an env variable
multipass-reinstall:
VM_CPUS=$(VM_CPUS) VM_MEMORY=$(VM_MEMORY) VM_DISK=$(VM_DISK) provision/multipass.sh -f ${VM_NAME}

multipass-netnext:
NETNEXT=true VM_CPUS=$(VM_CPUS) VM_MEMORY=$(VM_MEMORY) VM_DISK=$(VM_DISK) provision/multipass.sh netnext

multipass-netnext-reinstall:
NETNEXT=true VM_CPUS=$(VM_CPUS) VM_MEMORY=$(VM_MEMORY) VM_DISK=$(VM_DISK) provision/multipass.sh -f netnext

.PHONY = build validate clean install multipass multipass-reinstall multipass-netnext multipass-netnext-reinstall
14 changes: 11 additions & 3 deletions cilium-ubuntu-4.19.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,19 @@
]
},{
"type": "shell",
"environment_vars": [
"VM_ARCH=amd64"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"expect_disconnect": true,
"scripts": [
"provision/ubuntu/netperf.sh"
]
},{
"type": "shell",
"environment_vars": [
"VM_ARCH=amd64"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}' 0419190 202105070933",
"expect_disconnect": true,
"scripts": [
Expand All @@ -85,9 +91,11 @@
},{
"type": "shell",
"environment_vars": [
"ENV_FILEPATH=/tmp/env.bash",
"CILIUM_BRANCH={{ user `CILIUM_BRANCH` }}",
"NAME_PREFIX={{ user `NAME_PREFIX` }}"
"VM_ARCH=amd64",
"USERNAME=vagrant",
"ENV_FILEPATH=/tmp/env.bash",
"CILIUM_BRANCH={{ user `CILIUM_BRANCH` }}",
"NAME_PREFIX={{ user `NAME_PREFIX` }}"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"expect_disconnect": true,
Expand Down
14 changes: 11 additions & 3 deletions cilium-ubuntu-5.4.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@
]
},{
"type": "shell",
"environment_vars": [
"VM_ARCH=amd64"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"expect_disconnect": true,
"scripts": [
"provision/ubuntu/netperf.sh"
]
},{
"type": "shell",
"environment_vars": [
"VM_ARCH=amd64"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}' 0504220 202210261259",
"expect_disconnect": true,
"scripts": [
Expand All @@ -86,9 +92,11 @@
},{
"type": "shell",
"environment_vars": [
"ENV_FILEPATH=/tmp/env.bash",
"CILIUM_BRANCH={{ user `CILIUM_BRANCH` }}",
"NAME_PREFIX={{ user `NAME_PREFIX` }}"
"VM_ARCH=amd64",
"USERNAME=vagrant",
"ENV_FILEPATH=/tmp/env.bash",
"CILIUM_BRANCH={{ user `CILIUM_BRANCH` }}",
"NAME_PREFIX={{ user `NAME_PREFIX` }}"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"expect_disconnect": true,
Expand Down
12 changes: 10 additions & 2 deletions cilium-ubuntu-next.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
]
},{
"type": "shell",
"environment_vars": [
"VM_ARCH=amd64"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"expect_disconnect": true,
"scripts": [
Expand All @@ -76,6 +79,9 @@
]
},{
"type": "shell",
"environment_vars": [
"VM_ARCH=amd64"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"expect_disconnect": true,
"scripts": [
Expand All @@ -88,8 +94,10 @@
},{
"type": "shell",
"environment_vars": [
"ENV_FILEPATH=/tmp/env.bash",
"NETNEXT=true"
"VM_ARCH=amd64",
"USERNAME=vagrant",
"ENV_FILEPATH=/tmp/env.bash",
"NETNEXT=true"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"expect_disconnect": true,
Expand Down
14 changes: 11 additions & 3 deletions cilium-ubuntu.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,19 @@
]
},{
"type": "shell",
"environment_vars": [
"VM_ARCH=amd64"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"expect_disconnect": true,
"scripts": [
"provision/ubuntu/netperf.sh"
]
},{
"type": "shell",
"environment_vars": [
"VM_ARCH=amd64"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"expect_disconnect": true,
"scripts": [
Expand All @@ -85,9 +91,11 @@
},{
"type": "shell",
"environment_vars": [
"ENV_FILEPATH=/tmp/env.bash",
"CILIUM_BRANCH={{ user `CILIUM_BRANCH` }}",
"NAME_PREFIX={{ user `NAME_PREFIX` }}"
"VM_ARCH=amd64",
"USERNAME=vagrant",
"ENV_FILEPATH=/tmp/env.bash",
"CILIUM_BRANCH={{ user `CILIUM_BRANCH` }}",
"NAME_PREFIX={{ user `NAME_PREFIX` }}"
],
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
"expect_disconnect": true,
Expand Down
9 changes: 4 additions & 5 deletions provision/env.bash
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env bash

export GOLANG_VERSION="1.19.5"
export ETCD_VERSION="v3.1.0"
export ETCD_VERSION="v3.2.32"
export CONTAINERD_VERSION="1.6.4"
export HUBBLE_VERSION="0.9.0"
export SONOBUOY_VERSION="0.14.2"
export SONOBUOY_VERSION="0.16.5"
export PROTOC_VERSION="3.12.4"
export HOME_DIR=/home/vagrant
export HOME=/home/vagrant
export GOPATH="${HOME}/go"
export HOME_DIR=/home/${USERNAME}
export GOPATH="${HOME_DIR}/go"
export PATH="${GOPATH}/bin:$PATH"
4 changes: 2 additions & 2 deletions provision/fix-home-ownership.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash

source "${ENV_FILEPATH}"

Expand All @@ -7,4 +7,4 @@ set -e
# Provisioning scripts run as root, causing files in the vagrant user's home
# directory to be owned by root, not vagrant. As a last step, fix the ownership
# of all files.
chown -R vagrant:vagrant "${HOME_DIR}"
chown -R ${USERNAME}:${USERNAME} "${HOME_DIR}"
7 changes: 5 additions & 2 deletions provision/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ source "${ENV_FILEPATH}"

set -e

sudo -u vagrant -E bash -c "mkdir -p ${GOPATH} && \
sudo -E chown ${USERNAME}:${USERNAME} ${HOME_DIR}
sudo -u ${USERNAME} -E bash -c "mkdir -p ${GOPATH} && \
go install github.com/google/gops@latest && \
go install github.com/subfuzion/envtpl/cmd/envtpl@latest && \
go install github.com/mfridman/tparse@latest"

curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b ${GOPATH}/bin/ v1.48.0

sudo -E ln -s "${GOPATH}/bin/"* /usr/bin
sudo -E ln -sf "${GOPATH}/bin/"* /usr/bin

if ! grep "export GOPATH=" ${HOME_DIR}/.profile ; then echo "export GOPATH=${GOPATH}" >>${HOME_DIR}/.profile; fi
19 changes: 19 additions & 0 deletions provision/kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

# source "${ENV_FILEPATH}"

set -e

#
# Install kubectl
#
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/$VM_ARCH/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
#
# Install Kind
#
go install sigs.k8s.io/kind@latest
if ! grep -i -e "PATH.*go.*/bin" ~/.profile ; then
echo "PATH=\"\$GOPATH/bin:\$PATH\"" >> ~/.profile
fi
162 changes: 162 additions & 0 deletions provision/multipass.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/usr/bin/env bash

set -eux

continue=false
purge=false
while getopts cf flag
do
case "${flag}" in
c) continue=true;;
f) purge=true;;
esac
done
shift $(($OPTIND - 1))

# check that VM name is given as a positional argument
if [ -z "${1-}" ]; then
echo "Usage: $0 [-f] [-c] <VM-name>"
echo "following environment variables are honored: MOUNT, KERNEL, KERNEL_DATE, NETNEXT, PULL_IMAGES, UBUNTU, VM_CPUS, VM_MEMORY, VM_DISK, VM_USERNAME, HOST_IP, HOST_NETWORK, HOST_MASK, LOG"
exit 1
fi
VM_NAME=$1

# Mount using NFS by default since it is the fastest mount option on macOS,
# other options are 'native' (p9 on multipass 1.11 on macOS) and 'default' (sshfs)
MOUNT=${MOUNT:-NFS}
case "$MOUNT" in
NFS) ;;
native) ;;
default) ;;
*)
echo "unsupported MOUNT type, use NFS, native, or default"
exit 1
;;
esac

KERNEL=${KERNEL:-}
KERNEL_DATE=${KERNEL_DATE:-}
NETNEXT=${NETNEXT:-}
PULL_IMAGES=${PULL_IMAGES:-}

UBUNTU=${UBUNTU:-22.04}
VM_CPUS=${VM_CPUS:-4}
VM_MEMORY=${VM_MEMORY:-4G}
VM_DISK=${VM_DISK:-40G}
VM_ARCH=$(uname -m)
VM_ARCH=${VM_ARCH/x86_64/amd64}
VM_ARCH=${VM_ARCH/aarch64/arm64}
VM_USERNAME=${VM_USERNAME:-ubuntu}
HOST_IP=${HOST_IP:-192.168.64.1}

HOST_NETWORK=${HOST_NETWORK:-${HOST_IP%.*}.0}
HOST_MASK=${HOST_MASK:-255.255.255.0}

LOG=/tmp/$VM_NAME-provision.log

# Share parent if it is named "cilium", so that it can be correctly mounted
# as ~/go/src/github.com/cilium"
parent=$(cd "$(dirname $PWD)"; pwd -P)
if [ "$(basename $parent)" = "cilium" ]; then
SHARE_SOURCE=$(dirname $parent)
SHARE_TARGET=/home/$VM_USERNAME/go/src/github.com
else
SHARE_SOURCE=$parent
SHARE_TARGET=/home/$VM_USERNAME/go/src/github.com/cilium
fi

function copy_provision {
multipass transfer --recursive --parents provision $VM_NAME:/tmp/provision
multipass exec $VM_NAME -- bash -c "chmod +x /tmp/provision/*.sh /tmp/provision/ubuntu/*.sh"
}

function nfs_export {
ETC_EXPORTS="$SHARE_SOURCE -mapall=$(whoami) -alldirs -network $HOST_NETWORK -mask $HOST_MASK"

if ! grep "$ETC_EXPORTS" /etc/exports; then
echo "Adding entry to /etc/exports, sudo password may be needed."
sudo sh -c "echo >> /etc/exports \"$ETC_EXPORTS\""
if [ -f `which nfsd` ]; then
sudo nfsd restart
fi
else
echo /etc/exports already has line with "$ETC_EXPORTS"
fi
}

if [ $purge == "true" ]; then
multipass delete $VM_NAME --purge
fi

if ! multipass info $VM_NAME 2>&1 >/dev/null; then
echo "Launching $VM_NAME"
rm -f $LOG

cp user-data.yaml /tmp
if [ -f ~/.ssh/id_rsa.pub ]; then
printf "\nssh_authorized_keys:\n - " >> /tmp/user-data.yaml
cat ~/.ssh/id_rsa.pub >> /tmp/user-data.yaml
fi
multipass launch -vvvv --disk $VM_DISK --cloud-init /tmp/user-data.yaml --cpus $VM_CPUS --memory $VM_MEMORY --name $VM_NAME $UBUNTU
echo "Launched multipass VM \"$VM_NAME\", use \"multipass delete $VM_NAME --purge\" to delete it."
elif [ $continue == "false" ]; then
echo "$VM_NAME already exists, specify -c to use it or -f to delete it."
exit 1
fi

#
# Configure kernel if not already done
#
if ! tail $LOG | grep -e "Rebooting kernel" -e "KEEPING KERNEL"; then
copy_provision
multipass exec $VM_NAME -- bash -c "VM_ARCH=$VM_ARCH KERNEL=$KERNEL KERNEL_DATE=$KERNEL_DATE NETNEXT=$NETNEXT /tmp/provision/provision-kernel.sh 2>&1 || true" | tee $LOG
if tail $LOG | grep "Rebooting kernel"; then
echo "Waiting until kernel reboots"
until multipass exec $VM_NAME -- uname -a; do
sleep 5
done
echo "Resuming provisioning..."
elif ! tail $LOG | grep "KEEPING KERNEL"; then
echo "*** Kernel provisioning failed, see $LOG ***"
exit 1
fi
fi

#
# Continue provisioning if not already done
#
if ! tail $LOG | grep "PROVISIONING SUCCESSFULLY COMPLETED"; then
copy_provision
multipass exec $VM_NAME -- bash -c "NETNEXT=$NETNEXT VM_ARCH=$VM_ARCH USERNAME=$VM_USERNAME PULL_IMAGES=$PULL_IMAGES /tmp/provision/provision.sh 2>&1" | tee -a $LOG
#
# Fail if not successfully completed
#
tail $LOG | grep "PROVISIONING SUCCESSFULLY COMPLETED"
fi

#
# Add mount to Cilium directory.
#
if [ "$MOUNT" = "NFS" ]; then
nfs_export
multipass exec $VM_NAME -- mkdir -p $SHARE_TARGET
multipass exec $VM_NAME -- sudo bash -c "echo \"$HOST_IP:$SHARE_SOURCE $SHARE_TARGET nfs defaults 0 0\" >>/etc/fstab && mount -a"
elif [ "$MOUNT" = "native" ]; then
multipass stop $VM_NAME
multipass mount -t native $SHARE_SOURCE $VM_NAME:$SHARE_TARGET
multipass start $VM_NAME
else # the default case
multipass mount $SHARE_SOURCE $VM_NAME:$SHARE_TARGET
fi

#
# Verify that the mount works
#
multipass exec $VM_NAME -- cat /home/$VM_USERNAME/go/src/github.com/cilium/cilium/VERSION

#
# Remove provisioning artifacts last so that we keep them when provisioning fails
#
rm -f /tmp/user-data.yaml || true
rm -f $LOG || true
multipass exec $VM_NAME -- rm -rf /tmp/provision || true
Loading