feat: Support Kubernetes interfaces (#80)
This commit is contained in:
parent
df2c38893f
commit
97b4a558df
1 changed files with 9 additions and 5 deletions
|
@ -12,6 +12,7 @@ set -Eeuo pipefail
|
||||||
: "${VM_NET_TAP:="qemu"}"
|
: "${VM_NET_TAP:="qemu"}"
|
||||||
: "${VM_NET_MAC:="$MAC"}"
|
: "${VM_NET_MAC:="$MAC"}"
|
||||||
: "${VM_NET_HOST:="QEMU"}"
|
: "${VM_NET_HOST:="QEMU"}"
|
||||||
|
: "${VM_NET_IP:="20.20.20.21"}"
|
||||||
|
|
||||||
: "${DNSMASQ_OPTS:=""}"
|
: "${DNSMASQ_OPTS:=""}"
|
||||||
: "${DNSMASQ:="/usr/sbin/dnsmasq"}"
|
: "${DNSMASQ:="/usr/sbin/dnsmasq"}"
|
||||||
|
@ -154,15 +155,13 @@ configureNAT() {
|
||||||
|
|
||||||
# Create a bridge with a static IP for the VM guest
|
# Create a bridge with a static IP for the VM guest
|
||||||
|
|
||||||
VM_NET_IP='20.20.20.21'
|
|
||||||
|
|
||||||
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
error "Failed to create bridge. $ADD_ERR --cap-add NET_ADMIN" && exit 23
|
error "Failed to create bridge. $ADD_ERR --cap-add NET_ADMIN" && exit 23
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ip address add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge
|
ip address add "${VM_NET_IP%.*}.1/24" broadcast "${VM_NET_IP%.*}.255" dev dockerbridge
|
||||||
|
|
||||||
while ! ip link set dockerbridge up; do
|
while ! ip link set dockerbridge up; do
|
||||||
info "Waiting for IP address to become available..."
|
info "Waiting for IP address to become available..."
|
||||||
|
@ -264,8 +263,13 @@ checkOS() {
|
||||||
getInfo() {
|
getInfo() {
|
||||||
|
|
||||||
if [ -z "$VM_NET_DEV" ]; then
|
if [ -z "$VM_NET_DEV" ]; then
|
||||||
|
# Give Kubernetes priority over the default interface
|
||||||
|
[ -d "/sys/class/net/net0" ] && VM_NET_DEV="net0"
|
||||||
|
[ -d "/sys/class/net/net1" ] && VM_NET_DEV="net1"
|
||||||
|
[ -d "/sys/class/net/net2" ] && VM_NET_DEV="net2"
|
||||||
|
[ -d "/sys/class/net/net3" ] && VM_NET_DEV="net3"
|
||||||
# Automaticly detect the default network interface
|
# Automaticly detect the default network interface
|
||||||
VM_NET_DEV=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
|
[ -z "$VM_NET_DEV" ] && VM_NET_DEV=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
|
||||||
[ -z "$VM_NET_DEV" ] && VM_NET_DEV="eth0"
|
[ -z "$VM_NET_DEV" ] && VM_NET_DEV="eth0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -296,7 +300,7 @@ getInfo() {
|
||||||
error "Invalid MAC address: '$VM_NET_MAC', should be 12 or 17 digits long!" && exit 28
|
error "Invalid MAC address: '$VM_NET_MAC', should be 12 or 17 digits long!" && exit 28
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GATEWAY=$(ip r | grep default | awk '{print $3}')
|
GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}')
|
||||||
IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in a new issue