Skip to content

Commit 6ca1a0a

Browse files
committed
Review fixes
Signed-off-by: Hossam Rabbouh <horabbouh@microsoft.com>
1 parent d9662bc commit 6ca1a0a

2 files changed

Lines changed: 30 additions & 19 deletions

File tree

parts/linux/cloud-init/artifacts/cse_config.sh

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
967972
network:
@@ -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}"
979983
NETPLAN_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
999999
UseDomains=false
10001000
SendRelease=false
10011001
NETWORKD_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

10161027
ensureK8sControlPlane() {

spec/parts/linux/cloud-init/artifacts/cse_config_spec.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ Describe 'cse_config.sh'
258258
return 1
259259
}
260260
When run configureSecondaryNICs
261-
The stderr should include "Failed to apply netplan config for eth1"
262-
The output should not include "Configured secondary NIC"
261+
The output should include "Configured secondary NIC eth1"
262+
The stderr should include "Failed to apply netplan config for secondary NICs"
263263
The status should equal 243
264264
End
265265

@@ -271,8 +271,8 @@ Describe 'cse_config.sh'
271271
return 1
272272
}
273273
When run configureSecondaryNICs
274-
The stderr should include "Failed to reload networkd for eth1"
275-
The output should not include "Configured secondary NIC"
274+
The output should include "Configured secondary NIC eth1"
275+
The stderr should include "Failed to reload networkd for secondary NICs"
276276
The status should equal 243
277277
End
278278

@@ -288,8 +288,8 @@ Describe 'cse_config.sh'
288288
echo "networkctl $@"
289289
}
290290
When run configureSecondaryNICs
291+
The output should include "Configured secondary NIC eth1"
291292
The stderr should include "Failed to bring up eth1"
292-
The output should not include "Configured secondary NIC"
293293
The status should equal 243
294294
End
295295
End

0 commit comments

Comments
 (0)