|
| 1 | +$ZipPath = "Binaries.zip" |
| 2 | +$DirPath = "Binaries" |
| 3 | + |
| 4 | +$CreateZip = $true |
| 5 | +$CopyBinaries = $true |
| 6 | +$ReplaceHns = $true |
| 7 | +$ReplaceVfpCtrl = $false |
| 8 | +$ReplaceVfpExt = $false |
| 9 | +$ReplaceVfpApi = $false |
| 10 | +$ReplaceKubeProxy = $false |
| 11 | +$ReplaceAzureVnet = $false |
| 12 | +$SetRegKeys = $false |
| 13 | + |
| 14 | +$HpcName = "hpc-ds-win22" |
| 15 | +$Namespace = "demo" |
| 16 | + |
| 17 | +$RegKeys = @( |
| 18 | + "reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hns\State /v HNSLbNatDupRuleChange /t REG_DWORD /d 1 /f", |
| 19 | + "reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VfpExt\Parameters /v VfpIpv6DipsPrintingIsEnabled /t REG_DWORD /d 1 /f", |
| 20 | + "reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hns\State /v HnsTcpNodeToClusterIPChange /t REG_DWORD /d 1 /f" |
| 21 | +) |
| 22 | + |
| 23 | +function GetAllPodNames { |
| 24 | + param ( |
| 25 | + [Parameter (Mandatory = $true)] [String]$namespace, |
| 26 | + [Parameter (Mandatory = $true)] [String]$daemonsetName |
| 27 | + ) |
| 28 | + $podNames = @() |
| 29 | + $metadatas = ((kubectl get pods -n $namespace -o json | ConvertFrom-Json).Items).metadata |
| 30 | + foreach($metadata in $metadatas) { |
| 31 | + if(($metadata.labels).Name -eq $daemonsetName ) { |
| 32 | + $podNames += $metadata.name |
| 33 | + } |
| 34 | + } |
| 35 | + return $podNames |
| 36 | +} |
| 37 | + |
| 38 | +function ValidateBinariesDir { |
| 39 | + |
| 40 | + if((Test-Path $DirPath) -eq $false) { |
| 41 | + Write-Host "Missing dir [$DirPath] " |
| 42 | + return $false |
| 43 | + } |
| 44 | + |
| 45 | + $missingBins = @() |
| 46 | + $sfpcopyNeeded = $false |
| 47 | + |
| 48 | + if($ReplaceHns -and ((Test-Path $DirPath\hostnetsvc.dll) -eq $false)) { |
| 49 | + $missingBins += "hostnetsvc.dll" |
| 50 | + } |
| 51 | + |
| 52 | + if($ReplaceVfpCtrl -and ((Test-Path $DirPath\vfpctrl.exe) -eq $false)){ |
| 53 | + $missingBins += "vfpctrl.exe" |
| 54 | + } |
| 55 | + |
| 56 | + if($ReplaceVfpExt -and ((Test-Path $DirPath\vfpext.sys) -eq $false)) { |
| 57 | + $missingBins += "vfpext.sys" |
| 58 | + } |
| 59 | + |
| 60 | + if($ReplaceVfpApi -and ((Test-Path $DirPath\vfpapi.dll) -eq $false)){ |
| 61 | + $missingBins += "vfpapi.dll" |
| 62 | + } |
| 63 | + |
| 64 | + if($ReplaceKubeProxy -and ((Test-Path $DirPath\kube-proxy.exe) -eq $false)) { |
| 65 | + $missingBins += "kube-proxy.exe" |
| 66 | + } |
| 67 | + |
| 68 | + if($ReplaceAzureVnet -and ((Test-Path $DirPath\azure-vnet.exe) -eq $false)){ |
| 69 | + $missingBins += "azure-vnet.exe" |
| 70 | + } |
| 71 | + |
| 72 | + if($ReplaceHns -or $ReplaceVfpCtrl -or $ReplaceVfpExt -or $ReplaceVfpApi -or $ReplaceKubeProxy) { |
| 73 | + $sfpcopyNeeded = $true |
| 74 | + } |
| 75 | + |
| 76 | + if($sfpcopyNeeded -and ((Test-Path $DirPath\sfpcopy.exe) -eq $false)) { |
| 77 | + $missingBins += "sfpcopy.exe" |
| 78 | + } |
| 79 | + |
| 80 | + if($missingBins.Count -gt 0) { |
| 81 | + Write-Host "Missing binaries in dir [$DirPath] : $missingBins" |
| 82 | + return $false |
| 83 | + } |
| 84 | + |
| 85 | + return $true |
| 86 | +} |
| 87 | + |
| 88 | +if($CreateZip) { |
| 89 | + if(!(ValidateBinariesDir)) { |
| 90 | + return |
| 91 | + } |
| 92 | + Write-Host "Creating Binary zip." |
| 93 | + Remove-Item -Recurse -Force $ZipPath -ErrorAction Ignore |
| 94 | + Compress-Archive -Path $DirPath -DestinationPath $ZipPath |
| 95 | +} |
| 96 | + |
| 97 | +$allHpcPods = GetAllPodNames -namespace $Namespace -daemonsetName $HpcName |
| 98 | +foreach($hpcPod in $allHpcPods) { |
| 99 | + |
| 100 | + Write-Host "Setting up host pod : $hpcPod" |
| 101 | + if($CopyBinaries) { |
| 102 | + Write-Host "Cleaning up existing binaries : $hpcPod" |
| 103 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command rm -r -Force $ZipPath -ErrorAction Ignore |
| 104 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command rm -r -Force Binaries -ErrorAction Ignore |
| 105 | + Write-Host "Copying binaries to : $hpcPod" |
| 106 | + kubectl cp .\$ZipPath $hpcPod`:$ZipPath -n $Namespace |
| 107 | + Start-Sleep -Seconds 1 |
| 108 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Expand-Archive -Path $ZipPath -DestinationPath . |
| 109 | + } |
| 110 | + |
| 111 | + # Taking Backup of originals |
| 112 | + $origDirExists = kubectl exec $hpcPod -n $Namespace -- powershell -command Test-Path orig |
| 113 | + if($origDirExists -eq $false) { |
| 114 | + Write-Host "Taking backup of original binaries : $hpcPod" |
| 115 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command mkdir orig |
| 116 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command cp C:\k\azure-vnet.json .\orig\ |
| 117 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command cp C:\k\azurecni\netconf\10-azure.conflist .\orig\ |
| 118 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command cp C:\Windows\system32\vfpctrl.exe .\orig\ |
| 119 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command cp C:\Windows\system32\hostnetsvc.dll .\orig\ |
| 120 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command cp C:\k\azurecni\bin\azure-vnet.exe .\orig\ |
| 121 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command cp C:\Windows\system32\drivers\vfpext.sys .\orig\ |
| 122 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command cp C:\Windows\system32\vfpapi.dll .\orig\ |
| 123 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command cp C:\k\kube-proxy.exe .\orig\ |
| 124 | + } |
| 125 | + |
| 126 | + if($SetRegKeys) { |
| 127 | + Write-Host "Setting up host pod reg keys : $hpcPod" |
| 128 | + foreach($key in $RegKeys) { |
| 129 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command $key |
| 130 | + } |
| 131 | + Write-Host "Reg keys set : $hpcPod" |
| 132 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hns\State |
| 133 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VfpExt\Parameters |
| 134 | + } |
| 135 | + |
| 136 | + if($ReplaceAzureVnet) { |
| 137 | + Write-Host "Replacing azure vnet in : $hpcPod" |
| 138 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command cp .\Binaries\azure-vnet.exe C:\k\azurecni\bin\azure-vnet.exe |
| 139 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command rm C:\k\azure-vnet.json -ErrorAction Ignore |
| 140 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Get-HnsNetwork | Where name -eq azure | Remove-HnsNetwork |
| 141 | + Write-Host "FileHash for azure vnet : $hpcPod" |
| 142 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Get-FileHash C:\k\azurecni\bin\azure-vnet.exe |
| 143 | + } |
| 144 | + |
| 145 | + if($ReplaceHns) { |
| 146 | + Write-Host "Replacing hns in : $hpcPod" |
| 147 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command .\Binaries\sfpcopy.exe .\Binaries\HostNetSvc.dll C:\Windows\system32\hostnetsvc.dll |
| 148 | + Start-Sleep -Seconds 2 |
| 149 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Restart-Service -f hns |
| 150 | + Start-Sleep -Seconds 2 |
| 151 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Get-Service hns |
| 152 | + Write-Host "FileHash for hns : $hpcPod" |
| 153 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Get-FileHash C:\Windows\system32\hostnetsvc.dll |
| 154 | + } |
| 155 | + |
| 156 | + if($ReplaceVfpExt) { |
| 157 | + Write-Host "Replacing vfpext.sys in : $hpcPod" |
| 158 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command .\Binaries\sfpcopy.exe .\Binaries\vfpext.sys C:\Windows\system32\drivers\vfpext.sys |
| 159 | + Start-Sleep -Seconds 2 |
| 160 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Restart-Service -f vfpext |
| 161 | + Start-Sleep -Seconds 2 |
| 162 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Get-Service vfpext |
| 163 | + Write-Host "FileHash for vfpext.sys : $hpcPod" |
| 164 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Get-FileHash C:\Windows\system32\drivers\vfpext.sys |
| 165 | + } |
| 166 | + |
| 167 | + if($ReplaceVfpApi) { |
| 168 | + Write-Host "Replacing vfpapi.dll in : $hpcPod" |
| 169 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command .\Binaries\sfpcopy.exe .\Binaries\vfpapi.dll C:\Windows\system32\vfpapi.dll |
| 170 | + Write-Host "FileHash for vfpapi.dll : $hpcPod" |
| 171 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Get-FileHash C:\Windows\system32\vfpapi.dll |
| 172 | + } |
| 173 | + |
| 174 | + if($ReplaceVfpCtrl) { |
| 175 | + Write-Host "Replacing vfpctrl in : $hpcPod" |
| 176 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command .\Binaries\sfpcopy.exe .\Binaries\vfpctrl.exe C:\Windows\system32\vfpctrl.exe |
| 177 | + Write-Host "FileHash for vfpctrl : $hpcPod" |
| 178 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Get-FileHash C:\Windows\system32\vfpctrl.exe |
| 179 | + } |
| 180 | + |
| 181 | + if($ReplaceKubeProxy) { |
| 182 | + Write-Host "Replacing KubeProxy in : $hpcPod" |
| 183 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command .\Binaries\sfpcopy.exe .\Binaries\kube-proxy.exe C:\k\kube-proxy.exe |
| 184 | + Start-Sleep -Seconds 2 |
| 185 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Restart-Service -f kubeproxy |
| 186 | + Start-Sleep -Seconds 2 |
| 187 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Get-Service kubeproxy |
| 188 | + Write-Host "FileHash for KubeProxy : $hpcPod" |
| 189 | + kubectl exec $hpcPod -n $Namespace -- powershell -ExecutionPolicy Unrestricted -command Get-FileHash C:\k\kube-proxy.exe |
| 190 | + } |
| 191 | + |
| 192 | + Write-Host "Setting up host pod : $hpcPod completed" |
| 193 | +} |
0 commit comments