Skip to content

Commit e5b51b2

Browse files
committed
move network configuration to NodePrep phase
fix network configuration for VHD caching
1 parent 3397ed0 commit e5b51b2

File tree

3 files changed

+67
-53
lines changed

3 files changed

+67
-53
lines changed

e2e/scenario_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,14 +2195,17 @@ func Test_Ubuntu2404_VHDCaching(t *testing.T) {
21952195
RunScenario(t, &Scenario{
21962196
Description: "T",
21972197
Config: Config{
2198-
Cluster: ClusterKubenet,
2199-
VHD: config.VHDUbuntu2204Gen2Containerd,
2200-
VHDCaching: true,
2201-
BootstrapConfigMutator: func(nbc *datamodel.NodeBootstrappingConfiguration) {
2202-
},
2198+
Cluster: ClusterKubenet,
2199+
VHD: config.VHDUbuntu2204Gen2Containerd,
2200+
VHDCaching: true,
2201+
BootstrapConfigMutator: EmptyBootstrapConfigMutator,
22032202
Validator: func(ctx context.Context, s *Scenario) {
22042203
},
22052204
VMConfigMutator: func(vmss *armcompute.VirtualMachineScaleSet) {
2205+
// If the VHD is misconfigured (e.g. incorrect network settings), deploying multiple instances may cause conflicts.
2206+
// This validation can be unreliable and may not catch issues on every run, as the current framework creates only a single VM per test.
2207+
// False positives are more likely than false negatives in this scenario.
2208+
vmss.SKU.Capacity = to.Ptr[int64](2)
22062209
},
22072210
},
22082211
})

e2e/scenario_win_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,15 @@ func Test_Windows2022_VHDCaching(t *testing.T) {
346346
RunScenario(t, &Scenario{
347347
Description: "VHD Caching",
348348
Config: Config{
349-
Cluster: ClusterAzureNetwork,
350-
VHD: config.VHDWindows2022Containerd, // gen1 is default for windows 2022
351-
VHDCaching: true,
352-
VMConfigMutator: EmptyVMConfigMutator,
349+
Cluster: ClusterAzureNetwork,
350+
VHD: config.VHDWindows2022Containerd, // gen1 is default for windows 2022
351+
VHDCaching: true,
352+
VMConfigMutator: func(vmss *armcompute.VirtualMachineScaleSet) {
353+
// If the VHD is misconfigured (e.g. incorrect network settings), deploying multiple instances may cause conflicts.
354+
// This validation can be unreliable and may not catch issues on every run, as the current framework creates only a single VM per test.
355+
// False positives are more likely than false negatives in this scenario.
356+
vmss.SKU.Capacity = to.Ptr[int64](2)
357+
},
353358
BootstrapConfigMutator: EmptyBootstrapConfigMutator,
354359
Validator: func(ctx context.Context, s *Scenario) {
355360
ValidateWindowsVersionFromWindowsSettings(ctx, s, "2022-containerd")

parts/windows/kuberneteswindowssetup.ps1

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,56 @@ function BasePrep {
411411
New-HostsConfigService
412412
}
413413

414+
# NOTE: Network configuration has been moved to NodePrep to prevent HNS network
415+
# state from being baked into VHD images, which causes DHCP conflicts when
416+
# multiple VMs are created from the same image.
417+
418+
Set-Explorer
419+
Adjust-PageFileSize
420+
Logs-To-Event -TaskName "AKS.WindowsCSE.PreprovisionExtension" -TaskMessage "Start preProvisioning script"
421+
PREPROVISION_EXTENSION
422+
Update-ServiceFailureActions
423+
Adjust-DynamicPortRange
424+
Register-LogsCleanupScriptTask
425+
Register-NodeResetScriptTask
426+
427+
Update-DefenderPreferences
428+
429+
$windowsVersion = Get-WindowsVersion
430+
if ($windowsVersion -ne "1809") {
431+
Logs-To-Event -TaskName "AKS.WindowsCSE.EnableSecureTLS" -TaskMessage "Skip secure TLS protocols for Windows version: $windowsVersion"
432+
} else {
433+
Logs-To-Event -TaskName "AKS.WindowsCSE.EnableSecureTLS" -TaskMessage "Start to enable secure TLS protocols"
434+
try {
435+
. C:\k\windowssecuretls.ps1
436+
Enable-SecureTls
437+
}
438+
catch {
439+
Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_ENABLE_SECURE_TLS -ErrorMessage $_
440+
}
441+
}
442+
443+
Enable-FIPSMode -FipsEnabled $fipsEnabled
444+
if ($global:WindowsGmsaPackageUrl) {
445+
Install-GmsaPlugin -GmsaPackageUrl $global:WindowsGmsaPackageUrl
446+
}
447+
448+
Write-Log "BasePrep completed successfully"
449+
Logs-To-Event -TaskName "AKS.WindowsCSE.BasePrep" -TaskMessage "BasePrep completed successfully"
450+
}
451+
452+
# ====== NODE PREP: CLUSTER INTEGRATION ======
453+
# All operations that should only run when connecting to the actual cluster
454+
function NodePrep {
455+
Install-KubernetesServices -KubeDir $global:KubeDir
456+
457+
Write-Log "Starting NodePrep - Cluster integration"
458+
Logs-To-Event -TaskName "AKS.WindowsCSE.NodePrep" -TaskMessage "Starting NodePrep - Cluster integration"
459+
460+
Check-APIServerConnectivity -MasterIP $MasterIP
461+
462+
# Configure networking - this must run during node provisioning, not VHD creation
463+
# to ensure each VM gets unique HNS network IDs and avoids DHCP conflicts
414464
Write-Log "Configuring networking with NetworkPlugin:$global:NetworkPlugin"
415465

416466
# Configure network policy.
@@ -458,50 +508,6 @@ function BasePrep {
458508
Write-Log "Enable-WindowsCiliumNetworking is not a recognized function, will skip Windows Cilium Networking installation"
459509
}
460510

461-
Set-Explorer
462-
Adjust-PageFileSize
463-
Logs-To-Event -TaskName "AKS.WindowsCSE.PreprovisionExtension" -TaskMessage "Start preProvisioning script"
464-
PREPROVISION_EXTENSION
465-
Update-ServiceFailureActions
466-
Adjust-DynamicPortRange
467-
Register-LogsCleanupScriptTask
468-
Register-NodeResetScriptTask
469-
470-
Update-DefenderPreferences
471-
472-
$windowsVersion = Get-WindowsVersion
473-
if ($windowsVersion -ne "1809") {
474-
Logs-To-Event -TaskName "AKS.WindowsCSE.EnableSecureTLS" -TaskMessage "Skip secure TLS protocols for Windows version: $windowsVersion"
475-
} else {
476-
Logs-To-Event -TaskName "AKS.WindowsCSE.EnableSecureTLS" -TaskMessage "Start to enable secure TLS protocols"
477-
try {
478-
. C:\k\windowssecuretls.ps1
479-
Enable-SecureTls
480-
}
481-
catch {
482-
Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_ENABLE_SECURE_TLS -ErrorMessage $_
483-
}
484-
}
485-
486-
Enable-FIPSMode -FipsEnabled $fipsEnabled
487-
if ($global:WindowsGmsaPackageUrl) {
488-
Install-GmsaPlugin -GmsaPackageUrl $global:WindowsGmsaPackageUrl
489-
}
490-
491-
Write-Log "BasePrep completed successfully"
492-
Logs-To-Event -TaskName "AKS.WindowsCSE.BasePrep" -TaskMessage "BasePrep completed successfully"
493-
}
494-
495-
# ====== NODE PREP: CLUSTER INTEGRATION ======
496-
# All operations that should only run when connecting to the actual cluster
497-
function NodePrep {
498-
Install-KubernetesServices -KubeDir $global:KubeDir
499-
500-
Write-Log "Starting NodePrep - Cluster integration"
501-
Logs-To-Event -TaskName "AKS.WindowsCSE.NodePrep" -TaskMessage "Starting NodePrep - Cluster integration"
502-
503-
Check-APIServerConnectivity -MasterIP $MasterIP
504-
505511
if ($global:WindowsCalicoPackageURL) {
506512
Start-InstallCalico -RootDir "c:\" -KubeServiceCIDR $global:KubeServiceCIDR -KubeDnsServiceIp $KubeDnsServiceIp
507513
}

0 commit comments

Comments
 (0)