From d134bdc5832266599003235283bd782ed63e7d88 Mon Sep 17 00:00:00 2001 From: Abhay Krishna Arunachalam Date: Wed, 13 Sep 2023 09:52:10 -0700 Subject: [PATCH] Allow active network interface to be overriden --- .../build/setup_packer_configs.sh | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/projects/kubernetes-sigs/image-builder/build/setup_packer_configs.sh b/projects/kubernetes-sigs/image-builder/build/setup_packer_configs.sh index fbe039108a..6b3641b2e5 100755 --- a/projects/kubernetes-sigs/image-builder/build/setup_packer_configs.sh +++ b/projects/kubernetes-sigs/image-builder/build/setup_packer_configs.sh @@ -151,30 +151,41 @@ env_and_envsubst '$EKSD_NAME' \ # directory containing the kickstart config if [ "$IMAGE_FORMAT" = "ova" ] && \ ( [ "$IMAGE_OS" = "redhat" ] || ( [ "$IMAGE_OS" = "ubuntu" ] && [ "$IMAGE_OS_VERSION" != "2004" ] ) ); then - echo "Finding correct interface for packer temporary http server" - ACTIVE_INTERFACE="" - if [ "$(uname -s)" = "Linux" ]; then - INTERFACES=($(ls /sys/class/net)) - for interface in "${INTERFACES[@]}"; do - if [ "$interface" = "eth0" ] || [ "$interface" = "en0" ] || [ "$interface" = "eno1" ]; then - ACTIVE_INTERFACE=$interface - echo "Found interface: $interface" - break - fi - done - HTTP_SERVER_IP=$(ip a l $ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1) - elif [ "$(uname -s)" = "Darwin" ]; then - ACTIVE_INTERFACE="en0" - HTTP_SERVER_IP=$(ifconfig $ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1) - fi - if [ -z $ACTIVE_INTERFACE ]; then - echo "ACTIVE_INTERFACE cannot be an empty string. Please check your network configuration - and set an appropriate value for ACTIVE_INTERFACE" - exit 1 + # Get Packer HTTP server IP from env var if set + PACKER_HTTP_SERVER_IP=${PACKER_HTTP_SERVER_IP:-} + if [ -z $PACKER_HTTP_SERVER_IP ]; then + # Get active network interface from env var if set + PACKER_ACTIVE_INTERFACE="${PACKER_ACTIVE_INTERFACE:-}" + if [ -z $PACKER_ACTIVE_INTERFACE ]; then + echo "Finding interface for Packer temporary HTTP server" + if [ "$(uname -s)" = "Linux" ]; then + INTERFACES=($(ls /sys/class/net)) + for interface in "${INTERFACES[@]}"; do + if [ "$interface" = "eth0" ] || [ "$interface" = "en0" ] || [ "$interface" = "eno1" ]; then + PACKER_ACTIVE_INTERFACE=$interface + echo "Found interface: $interface" + break + fi + done + elif [ "$(uname -s)" = "Darwin" ]; then + PACKER_ACTIVE_INTERFACE="en0" + fi + fi + + if [ -z $PACKER_ACTIVE_INTERFACE ]; then + echo "PACKER_ACTIVE_INTERFACE cannot be automatically determined. Please export PACKER_ACTIVE_INTERFACE=" + exit 1 + fi + + if [ "$(uname -s)" = "Linux" ]; then + PACKER_HTTP_SERVER_IP=$(ip a l $PACKER_ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1) + elif + [ "$(uname -s)" = "Darwin" ]; then + PACKER_HTTP_SERVER_IP=$(ifconfig $PACKER_ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1) + fi fi - PACKER_HTTP_SERVER_IP=${PACKER_HTTP_SERVER_IP:-$HTTP_SERVER_IP} if [ -z $PACKER_HTTP_SERVER_IP ]; then echo "PACKER_HTTP_SERVER_IP cannot be automatically determined. Please export PACKER_HTTP_SERVER_IP=" exit 1