@@ -953,6 +953,11 @@ configureSecondaryNICs() {
953953
954954 echo " Detected $nic_count NICs, configuring secondary interfaces..."
955955
956+ local is_netplan=false
957+ if [ -d /etc/netplan ]; then
958+ is_netplan=true
959+ fi
960+
956961 for i in $( seq 1 $(( nic_count - 1 )) ) ; do
957962 local mac
958963 mac=$( jq -r " .network.interface[$i ].macAddress" " $IMDS_INSTANCE_METADATA_CACHE_FILE " )
@@ -961,7 +966,7 @@ configureSecondaryNICs() {
961966 local iface_name=" eth${i} "
962967 local metric=$(( 100 + i * 100 ))
963968
964- if [ -d /etc/netplan ]; then
969+ if [ " $is_netplan " = true ]; then
965970 # Ubuntu: generate netplan config for the secondary NIC
966971 cat > " /etc/netplan/60-secondary-nic-${i} .yaml" << NETPLAN_EOF
967972network:
@@ -970,18 +975,13 @@ network:
970975 ${iface_name} :
971976 match:
972977 macaddress: "${mac} "
973- driver: "hv_netvsc"
974978 dhcp4: true
975979 dhcp4-overrides:
976980 route-metric: ${metric}
977981 use-dns: false
978982 set-name: "${iface_name} "
979983NETPLAN_EOF
980984 chmod 600 " /etc/netplan/60-secondary-nic-${i} .yaml"
981- if ! netplan apply; then
982- echo " Failed to apply netplan config for ${iface_name} " >&2
983- return $ERR_SECONDARY_NIC_CONFIG_FAIL
984- fi
985985 else
986986 # AzureLinux/Mariner: generate networkd .network unit.
987987 # Prefix 10- so it takes precedence over the VHD's 99-dhcp-en.network.
@@ -999,18 +999,29 @@ UseDNS=false
999999UseDomains=false
10001000SendRelease=false
10011001NETWORKD_EOF
1002- if ! networkctl reload; then
1003- echo " Failed to reload networkd for ${iface_name} " >&2
1004- return $ERR_SECONDARY_NIC_CONFIG_FAIL
1005- fi
1006- if ! networkctl up " ${iface_name} " ; then
1007- echo " Failed to bring up ${iface_name} " >&2
1008- return $ERR_SECONDARY_NIC_CONFIG_FAIL
1009- fi
10101002 fi
10111003
10121004 echo " Configured secondary NIC ${iface_name} (mac=${mac} , metric=${metric} )"
10131005 done
1006+
1007+ # Apply all configs in a single operation to avoid repeated network restarts
1008+ if [ " $is_netplan " = true ]; then
1009+ if ! netplan apply; then
1010+ echo " Failed to apply netplan config for secondary NICs" >&2
1011+ return $ERR_SECONDARY_NIC_CONFIG_FAIL
1012+ fi
1013+ else
1014+ if ! networkctl reload; then
1015+ echo " Failed to reload networkd for secondary NICs" >&2
1016+ return $ERR_SECONDARY_NIC_CONFIG_FAIL
1017+ fi
1018+ for i in $( seq 1 $(( nic_count - 1 )) ) ; do
1019+ if ! networkctl up " eth${i} " ; then
1020+ echo " Failed to bring up eth${i} " >&2
1021+ return $ERR_SECONDARY_NIC_CONFIG_FAIL
1022+ fi
1023+ done
1024+ fi
10141025}
10151026
10161027ensureK8sControlPlane () {
0 commit comments