diff --git a/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 b/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 index acb7a13d..7c51b60c 100644 --- a/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 +++ b/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 @@ -1242,4 +1242,4 @@ Remove-Variable -name BASE_DIRECTORY -Scope Global if ($MODE -ne [Mode]::HtmlOnly) { Remove-Variable -name EVENT_SOURCE_NAME -Scope Global Remove-Variable -name LOG_NAME -Scope Global -} \ No newline at end of file +} diff --git a/Kubernetes/windows/debug/networkmonitor/networkhealthlocal.yaml b/Kubernetes/windows/debug/networkmonitor/networkhealthlocal.yaml new file mode 100644 index 00000000..764987d3 --- /dev/null +++ b/Kubernetes/windows/debug/networkmonitor/networkhealthlocal.yaml @@ -0,0 +1,37 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: networkhealth + labels: + app: networkhealth +spec: + selector: + matchLabels: + name: networkhealth + template: + metadata: + labels: + name: networkhealth + spec: + securityContext: + windowsOptions: + hostProcess: true + runAsUserName: "NT AUTHORITY\\SYSTEM" + hostNetwork: true + containers: + - name: networkhealth + image: mcr.microsoft.com/windows/servercore:1809 + args: + - powershell.exe + - -Command + - "$i = 1 ; $fileHash = \"00D231F41DBB11FAF13319124CAABE73806F0E5857068E1681A9ED1ECD2B2655\" ; While($i -le 300) { Start-Sleep -Seconds 2 ; Write-Host \"Iteration : $i\" ; if((Test-Path c:\\k\\debug\\networkhealth.ps1) -And ((Get-FileHash C:\\k\\debug\\networkhealth.ps1).Hash -Eq $fileHash) ){ Write-Host \"Networkhealthscript found.\" ; break ; } $i++ ; } c:\\k\\debug\\networkhealth.ps1 -OutputMode stdout; start-sleep 3600;" + imagePullPolicy: IfNotPresent + volumeMounts: + - name: kube-path + mountPath: C:\k + volumes: + - name: kube-path + hostPath: + path: C:\k + nodeSelector: + kubernetes.azure.com/os-sku: Windows2019 diff --git a/Kubernetes/windows/debug/networkmonitor/startnetworkhealth.ps1 b/Kubernetes/windows/debug/networkmonitor/startnetworkhealth.ps1 new file mode 100644 index 00000000..e8a78d99 --- /dev/null +++ b/Kubernetes/windows/debug/networkmonitor/startnetworkhealth.ps1 @@ -0,0 +1,44 @@ + +function WaitForDaemonsetToBeReady { + param ( + [parameter(Mandatory = $true)] [string] $dsName + ) + Write-Host "Checking status of daemonset $dsName ..." + $i = 0 + $maxWait = 300 + + while($i -le $maxWait) + { + $status = (kubectl get ds $dsName -o json | ConvertFrom-Json).status + if($status.currentNumberScheduled -eq $status.desiredNumberScheduled) + { + Write-Host "Deamonset $dsName is ready ..." + return $true + } + Write-Host "Deamonset $dsName is not yet ready. Scheduled Pods : $status.currentNumberScheduled , Desired Pods : $status.desiredNumberScheduled ..." + Start-Sleep -Seconds 2 + $i++ + } + + Write-Host "Creating $dsName daemonset failed. Scheduled Pods : $status.currentNumberScheduled , Desired Pods : $status.desiredNumberScheduled . Exiting..." + return $false +} + +Write-Host "Deleting networkhealth daemonset if anything running..." +kubectl delete -f .\networkhealthlocal.yaml +Write-Host "Creating hetworkhealth daemonset to run script..." +kubectl create -f .\networkhealthlocal.yaml +$nwHlthPodStatus = WaitForDaemonsetToBeReady("networkhealth") +if(!$nwHlthPodStatus) { + return +} +Start-Sleep -Seconds 5 +$nwHlthPods = kubectl get pods --no-headers -o custom-columns=":metadata.name" | findstr "networkhealth" +Write-Host "Networkhealth Pods : $nwHlthPods" +foreach($pod in $nwHlthPods) +{ + Write-Host "Copying networkhealth script to hpc pod : $pod ..." + kubectl cp .\networkhealth.ps1 $pod`:C:\k\debug\networkhealth.ps1 + Write-Host "Copying networkhealth script to hpc pod : $pod completed" +} +Write-Host "Creating networkhealth daemonset completed..." \ No newline at end of file