Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit ae6f059

Browse files
madhanrmPatrick Lang
authored andcommitted
Fix the network blip caused during network creation/deletion (#3438)
1 parent b0ce82b commit ae6f059

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

parts/k8s/kuberneteswindowssetup.ps1

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ c:\k\kubelet.exe --hostname-override=`$env:computername --pod-infra-container-im
346346
`$global:KubeBinariesVersion = "$global:KubeBinariesVersion"
347347
`$global:CNIPath = "$global:CNIPath"
348348
`$global:NetworkMode = "$global:NetworkMode"
349+
`$global:ExternalNetwork = "ext"
349350
`$global:CNIConfig = "$global:CNIConfig"
350351
`$global:HNSModule = "$global:HNSModule"
351352
`$global:VolumePluginDir = "$global:VolumePluginDir"
@@ -362,21 +363,35 @@ Write-Host "NetworkPlugin azure, starting kubelet."
362363
netsh advfirewall set allprofiles state off
363364
# startup the service
364365
365-
`$hnsNetwork = Get-HnsNetwork | ? Type -EQ `$global:NetworkMode.ToLower()
366+
# Find if the primary external switch network exists. If not create one.
367+
# This is done only once in the lifetime of the node
368+
`$hnsNetwork = Get-HnsNetwork | ? Name -EQ `$global:ExternalNetwork
369+
if (!`$hnsNetwork)
370+
{
371+
Write-Host "Creating a new hns Network"
372+
ipmo `$global:HNSModule
373+
# Fixme : use a smallest range possible, that will not collide with any pod space
374+
New-HNSNetwork -Type `$global:NetworkMode -AddressPrefix "192.168.255.0/30" -Gateway "192.168.255.1" -Name `$global:ExternalNetwork -Verbose
375+
}
376+
377+
# Find if network created by CNI exists, if yes, remove it
378+
# This is required to keep the network non-persistent behavior
379+
# Going forward, this would be done by HNS automatically during restart of the node
366380
381+
`$hnsNetwork = Get-HnsNetwork | ? Name -EQ $global:KubeNetwork
367382
if (`$hnsNetwork)
368383
{
369-
# Kubelet has been restarted with existing network.
370384
# Cleanup all containers
371385
docker ps -q | foreach {docker rm `$_ -f}
372-
# cleanup network
386+
373387
Write-Host "Cleaning up old HNS network found"
374388
Remove-HnsNetwork `$hnsNetwork
375389
Start-Sleep 10
376390
`$cnijson = "$global:KubeDir" + "\azure-vnet*"
377391
remove-item `$cnijson -ErrorAction SilentlyContinue
378392
}
379393
394+
# Restart Kubeproxy, which would wait, until the network is created
380395
Restart-Service Kubeproxy
381396
382397
$KubeletCommandLine
@@ -528,11 +543,12 @@ catch
528543
`$env:KUBE_NETWORK = "$global:KubeNetwork"
529544
`$global:NetworkMode = "$global:NetworkMode"
530545
`$global:HNSModule = "$global:HNSModule"
531-
`$hnsNetwork = Get-HnsNetwork | ? Type -EQ `$global:NetworkMode.ToLower()
546+
`$hnsNetwork = Get-HnsNetwork | ? Name -EQ $global:KubeNetwork
532547
while (!`$hnsNetwork)
533548
{
549+
Write-Host "Waiting for Network [$global:KubeNetwork] to be created . . ."
534550
Start-Sleep 10
535-
`$hnsNetwork = Get-HnsNetwork | ? Type -EQ `$global:NetworkMode.ToLower()
551+
`$hnsNetwork = Get-HnsNetwork | ? Name -EQ $global:KubeNetwork
536552
}
537553
538554
#

0 commit comments

Comments
 (0)