-
Notifications
You must be signed in to change notification settings - Fork 539
Add scripts to detect HNS crashes in AKS clusters #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mdebjit
wants to merge
8
commits into
microsoft:master
Choose a base branch
from
mdebjit:user/debjit/hnsCrashDetection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5d44e48
Add scripts to detect HNS crashes in AKS clusters
mdebjit 0dbf27e
Minor changes
mdebjit 6655649
Minor changes
mdebjit 197653b
Minor changes
mdebjit 263358d
Minor changes
mdebjit b46dffa
Add doc and move scripts to new dir
mdebjit a717549
Update faulttolerance.yaml
mdebjit 10113a8
Update faultTolerance.ps1
mdebjit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Enlist the fixed crashes to detect codepath execution | ||
| $fixedCrashes = @( | ||
| [pscustomobject]@{ | ||
| faultStr='*ElbDsrPolicy-Update-Failure*'; | ||
| bugId='41071049'; | ||
| }, | ||
| [pscustomobject]@{ | ||
| faultStr='*Network-Not-Found*'; | ||
| bugId='42521831'; | ||
| } | ||
| ) | ||
|
|
||
| $errStr="" | ||
| $crashDetected=$false | ||
| $hnsCrash=(Get-WinEvent -FilterHashtable @{logname = 'System'; ProviderName = 'Service Control Manager' } | Select-Object -Property TimeCreated, Message | Where-Object Message -like "*The Host Network Service terminated unexpectedly*").TimeCreated; | ||
| if($hnsCrash.Count -gt 0) { | ||
| $crashDetected=$true | ||
| # Log HNS Crashes | ||
| $errStr += "HNS crash detected at "; | ||
| foreach ($ts in $hnsCrash) { | ||
| $errStr += "("+$ts+") "; | ||
| } | ||
| $errStr += "`n"; | ||
| } | ||
|
|
||
| foreach($fault in $fixedCrashes.GetEnumerator()) { | ||
| $faultEvent=(Get-WinEvent -FilterHashtable @{logname = 'Microsoft-Windows-Host-Network-Service-Admin' } | Select-Object -Property TimeCreated, Message | Where-Object Message -like $fault.faultStr).TimeCreated | ||
| if ($faultEvent.Count -gt 0) { | ||
| $errStr += "Bug #" + $fault.bugId + " gracefully handled at "; | ||
| foreach ($ts in $faultEvent) { | ||
| $errStr += "("+$ts+") "; | ||
| } | ||
| $errStr += "`n"; | ||
| } | ||
| } | ||
|
|
||
| if ($crashDetected -eq $false) { | ||
| Write-Host "$(date) HNS crash not detected" | ||
| } | ||
|
|
||
| Write-Host $errStr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| $faultToleranceYaml = @' | ||
| apiVersion: apps/v1 | ||
| kind: DaemonSet | ||
| metadata: | ||
| name: faulttolerance | ||
| labels: | ||
| app: faulttolerance | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| name: faulttolerance | ||
| template: | ||
| metadata: | ||
| labels: | ||
| name: faulttolerance | ||
| spec: | ||
| securityContext: | ||
| windowsOptions: | ||
| hostProcess: true | ||
| runAsUserName: "NT AUTHORITY\\SYSTEM" | ||
| hostNetwork: true | ||
| containers: | ||
| - name: faulttolerance | ||
| image: mcr.microsoft.com/windows/servercore:1809 | ||
| args: | ||
| - powershell.exe | ||
| - -Command | ||
| - "$BaseDir = \"c:\\k\\debug\"; Invoke-WebRequest -UseBasicParsing \"https://raw.githubusercontent.com/microsoft/SDN/master/Kubernetes/windows/debug/faultAnalysis.ps1\" -OutFile $BaseDir\\faultAnalysis.ps1; c:\\k\\debug\\faultAnalysis.ps1; 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 | ||
| '@ | ||
|
|
||
| $faultToleranceYaml | kubectl delete --ignore-not-found=true -f - | ||
|
|
||
| $faultToleranceYaml | kubectl apply -f - | ||
| Write-Output "Sleep for a minute for fault tolerance pods to be up..." | ||
| Start-Sleep 60 | ||
|
|
||
| [System.Collections.ArrayList] $ws2019Nodes = @() | ||
| $nodes = (kubectl get nodes -o jsonpath="{.items[*].metadata.name}").Split() | ||
| foreach ($node in $nodes) { | ||
| $nodeImage = kubectl get node $node -o jsonpath="{.status.nodeInfo.osImage}" | ||
|
|
||
| if ($nodeImage.ToString().trim() -eq "Windows Server 2019 Datacenter") { | ||
| $ws2019Nodes += $node.trim(); | ||
| } | ||
| } | ||
|
|
||
| $report="" | ||
| $pods = (kubectl get pods -o jsonpath="{.items[*].metadata.name}").Split() | ||
| foreach ($pod in $pods) { | ||
| if ($pod.StartsWith('faulttolerance')) { | ||
| # if hns crashed - get the reason | ||
| $nodeName = kubectl get pod $pod -o jsonpath="{.spec.nodeName}" | ||
| $podLog = kubectl logs $pod | ||
| if ($podLog -like "*HNS crash not detected*") { | ||
| $ws2019Nodes.Remove($nodeName) | ||
| } | ||
| if (($podLog -like "*gracefully handled*") -or ($podLog -like "*HNS crash detected*")) { | ||
| # Generate Analysis Report | ||
| $report += $nodeName+" - Fault Analysis Report: `n"+$podLog+"`n" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ($report -ne "") { | ||
| Write-Host $report -ForegroundColor black -BackgroundColor white | ||
| } | ||
|
|
||
| if ($ws2019Nodes.Count -eq 0) { | ||
| Write-Host "No HNS crashes detected in the cluster" -ForegroundColor darkgreen -BackgroundColor white | ||
| } else { | ||
| Write-Host "HNS crashed on nodes: $ws2019Nodes" -ForegroundColor darkred -BackgroundColor white | ||
| } | ||
|
|
||
|
|
||
| Write-Output "Sleep for an hour before deleting the fault tolerance pods automatically..." | ||
| Start-Sleep 3600 | ||
| $faultToleranceYaml | kubectl delete --ignore-not-found=true -f - | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.