From 9bdac930451166396c58d780fc6cecf042c2e729 Mon Sep 17 00:00:00 2001 From: Prince Pereira Date: Fri, 17 Feb 2023 21:16:03 +0530 Subject: [PATCH 1/4] Changes for supporting local copying of networkhealth script to hostprocess container. --- .../debug/networkmonitor/networkhealth.ps1 | 2 +- .../networkmonitor/networkhealthlocal.yaml | 37 ++++++++++++++++ .../networkmonitor/startnetworkhealth.ps1 | 44 +++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 Kubernetes/windows/debug/networkmonitor/networkhealthlocal.yaml create mode 100644 Kubernetes/windows/debug/networkmonitor/startnetworkhealth.ps1 diff --git a/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 b/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 index acb7a13d..783ece9d 100644 --- a/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 +++ b/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 @@ -1106,7 +1106,7 @@ class HNSManagement : DiagnosticTest { [TestStatus]Run([DiagnosticDataProvider] $DiagnosticDataProvider) { $this.Status = [TestStatus]::Passed $lb_ipv4_vip = "250.0.0.10" # Should not be used by users, "reserved for future use" address - $hns_module_path = Join-Path -Path $Global:BASE_DIRECTORY -ChildPath "hns.v2.psm1" + $hns_module_path = Join-Path -Path $Global:BASE_DIRECTORY -ChildPath "hns.v1.psm1" # check if path exists, skip the test otherwise if (!(Test-Path -Path $hns_module_path)){ return [TestStatus]::Skipped 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 From 935ed5de40abc8be4f2294448f25a9408c6cfa45 Mon Sep 17 00:00:00 2001 From: PRINCE PEREIRA Date: Wed, 22 Feb 2023 09:48:47 +0530 Subject: [PATCH 2/4] Update networkhealth.ps1 --- Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 b/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 index 783ece9d..7c51b60c 100644 --- a/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 +++ b/Kubernetes/windows/debug/networkmonitor/networkhealth.ps1 @@ -1106,7 +1106,7 @@ class HNSManagement : DiagnosticTest { [TestStatus]Run([DiagnosticDataProvider] $DiagnosticDataProvider) { $this.Status = [TestStatus]::Passed $lb_ipv4_vip = "250.0.0.10" # Should not be used by users, "reserved for future use" address - $hns_module_path = Join-Path -Path $Global:BASE_DIRECTORY -ChildPath "hns.v1.psm1" + $hns_module_path = Join-Path -Path $Global:BASE_DIRECTORY -ChildPath "hns.v2.psm1" # check if path exists, skip the test otherwise if (!(Test-Path -Path $hns_module_path)){ return [TestStatus]::Skipped @@ -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 +} From f08445e7a7decc90b635bf6397e72762d25712fc Mon Sep 17 00:00:00 2001 From: PRINCE PEREIRA Date: Wed, 22 Feb 2023 09:50:34 +0530 Subject: [PATCH 3/4] Update networkhealth.ps1 From 4725cc0e593bdf7a5b222d3aefbce4773c0d05f4 Mon Sep 17 00:00:00 2001 From: PRINCE PEREIRA Date: Wed, 22 Feb 2023 09:51:06 +0530 Subject: [PATCH 4/4] Update networkhealth.ps1