Skip to content

Commit

Permalink
Fix the network blip caused during network creation/deletion (Azure#3438
Browse files Browse the repository at this point in the history
)
  • Loading branch information
madhanrm authored and jackfrancis committed Jul 7, 2018
1 parent 4d70c90 commit 904db6a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions parts/k8s/kuberneteswindowssetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -362,21 +363,35 @@ 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
`$cnijson = "$global:KubeDir" + "\azure-vnet*"
remove-item `$cnijson -ErrorAction SilentlyContinue
}
# Restart Kubeproxy, which would wait, until the network is created
Restart-Service Kubeproxy
$KubeletCommandLine
Expand Down Expand Up @@ -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
}
#
Expand Down

0 comments on commit 904db6a

Please sign in to comment.