Fix the network blip caused during network creation/deletion
@@ -346,6 +346,7 @@ c:\k\kubelet.exe --hostname-override=`$env:computername --pod-infra-container-im
`$global:KubeBinariesVersion = "$global:KubeBinariesVersion"
`$global:CNIPath = "$global:CNIPath"
`$global:NetworkMode = "$global:NetworkMode"
+`$global:ExternalNetwork = "ext"
`$global:CNIConfig = "$global:CNIConfig"
`$global:HNSModule = "$global:HNSModule"
`$global:VolumePluginDir = "$global:VolumePluginDir"
@@ -362,14 +363,27 @@ Write-Host "NetworkPlugin azure, starting kubelet."
netsh advfirewall set allprofiles state off
# startup the service
-`$hnsNetwork = Get-HnsNetwork | ? Type -EQ `$global:NetworkMode.ToLower()
+# Find if the primary external switch network exists. If not create one.
+# This is done only once in the lifetime of the node
+`$hnsNetwork = Get-HnsNetwork | ? Name -EQ `$global:ExternalNetwork
+if (!`$hnsNetwork)
+{
+ Write-Host "Creating a new hns Network"
+ ipmo `$global:HNSModule
+ # Fixme : use a smallest range possible, that will not collide with any pod space
+ New-HNSNetwork -Type `$global:NetworkMode -AddressPrefix "192.168.255.0/30" -Gateway "192.168.255.1" -Name `$global:ExternalNetwork -Verbose
+}
+# Find if network created by CNI exists, if yes, remove it
+# This is required to keep the network non-persistent behavior
+# Going forward, this would be done by HNS automatically during restart of the node
+
+`$hnsNetwork = Get-HnsNetwork | ? Name -EQ $global:KubeNetwork
if (`$hnsNetwork)
{
- # Kubelet has been restarted with existing network.
# Cleanup all containers
docker ps -q | foreach {docker rm `$_ -f}
- # cleanup network
+
Write-Host "Cleaning up old HNS network found"
Remove-HnsNetwork `$hnsNetwork
Start-Sleep 10
@@ -377,6 +391,7 @@ if (`$hnsNetwork)
remove-item `$cnijson -ErrorAction SilentlyContinue
}
+# Restart Kubeproxy, which would wait, until the network is created
Restart-Service Kubeproxy
$KubeletCommandLine
@@ -528,11 +543,12 @@ catch
`$env:KUBE_NETWORK = "$global:KubeNetwork"
`$global:NetworkMode = "$global:NetworkMode"
`$global:HNSModule = "$global:HNSModule"
-`$hnsNetwork = Get-HnsNetwork | ? Type -EQ `$global:NetworkMode.ToLower()
+`$hnsNetwork = Get-HnsNetwork | ? Name -EQ $global:KubeNetwork
while (!`$hnsNetwork)
{
+ Write-Host "Waiting for Network [$global:KubeNetwork] to be created . . ."
Start-Sleep 10
- `$hnsNetwork = Get-HnsNetwork | ? Type -EQ `$global:NetworkMode.ToLower()
+ `$hnsNetwork = Get-HnsNetwork | ? Name -EQ $global:KubeNetwork
}
#
