Private/menu-functions.ps1
function show-mainMenu { do { if ($firstRun) { $firstRun = $false } else { Clear-Host } Write-Host "`n[š Main Menu]" -ForegroundColor Cyan Write-Host "------------------------------------------" -ForegroundColor DarkGray # Main menu options $options = @( "[1] Cluster Summary š" "[2] Node Details š„ļø" "[3] Namespace Management š" "[4] Workload Management āļø" "[5] Pod Management š" "[6] Kubernetes Jobs š¢" "[7] Service & Networking š" "[8] Storage Management š¦" "[9] RBAC & Security š" "[10] Cluster Warning Events ā ļø" "[11] Infrastructure Best Practices ā " "[Q] Exit ā" ) foreach ($option in $options) { Write-Host $option } # Get user choice $choice = Read-Host "`nš¤ Enter your choice" Clear-Host switch ($choice) { "1" { Show-ClusterSummary } "2" { Show-NodeMenu } "3" { Show-NamespaceMenu } "4" { Show-WorkloadMenu } "5" { Show-PodMenu } "6" { Show-JobsMenu } "7" { Show-ServiceMenu } "8" { Show-StorageMenu } "9" { Show-RBACMenu } "10" { Show-KubeEvents } "11" { Show-InfraBestPracticesMenu } "Q" { Write-Host "š Goodbye! Have a great day! š"; return } default { Write-Host "ā ļø Invalid choice. Please try again!" -ForegroundColor Red } } } while ($true) } function Show-WorkloadMenu { do { Clear-Host Write-Host "`n[āļø Workload Management]" -ForegroundColor Cyan Write-Host "------------------------------------------" -ForegroundColor DarkGray $options = @( "[1] Check DaemonSet Health š ļø" "[2] Check Deployment Issues š" "[3] Check StatefulSet Issues šļø" "[4] Check ReplicaSet Health š" "š Back [B] | ā Exit [Q]" ) foreach ($option in $options) { Write-Host $option } $choice = Read-Host "`nš¤ Enter your choice" Clear-Host switch ($choice) { "1" { Show-DaemonSetIssues } "2" { $msg = @( "š¤ Deployment Issues Check is coming soon!", "", " - This feature will identify failing or unhealthy Deployments, rollout failures, and unavailable pods.", " - Stay tuned! š" ) Write-SpeechBubble -msg $msg -color "Cyan" -icon "š¤" -lastColor "Cyan" -delay 50 Read-Host "š¤ Press Enter to return to the menu" } "3" { $msg = @( "š¤ StatefulSet Health Check is coming soon!", "", " - This feature will analyze StatefulSets for failures, stuck rollouts, and missing pods.", " - Stay tuned for updates! šļø" ) Write-SpeechBubble -msg $msg -color "Cyan" -icon "š¤" -lastColor "Cyan" -delay 50 Read-Host "š¤ Press Enter to return to the menu" } "4" { $msg = @( "š¤ ReplicaSet Health Check is coming soon!", "", " - This feature will monitor ReplicaSets for pod mismatches, scaling issues, and failures.", " - Coming soon! š" ) Write-SpeechBubble -msg $msg -color "Cyan" -icon "š¤" -lastColor "Cyan" -delay 50 Read-Host "š¤ Press Enter to return to the menu" } "B" { return } "Q" { Write-Host "š Exiting KubeBuddy. Have a great day! š"; exit } default { Write-Host "ā ļø Invalid choice. Please try again!" -ForegroundColor Red } } } while ($true) } function Show-NodeMenu { do { Write-Host "`nš Node Details Menu" -ForegroundColor Cyan Write-Host "----------------------------------" $nodeOptions = @( "[1] List all nodes and node conditions" "[2] Get node resource usage" "š Back [B] | ā Exit [Q]" ) foreach ($option in $nodeOptions) { Write-Host $option } # Get user choice $nodeChoice = Read-Host "`nš¤ Enter a number" Clear-Host switch ($nodeChoice) { "1" { Show-NodeConditions } "2" { Show-NodeResourceUsage } "B" { return } # Back to main menu "Q" { Write-Host "š Exiting KubeBuddy. Have a great day! š"; exit } default { Write-Host "ā ļø Invalid choice. Please try again!" -ForegroundColor Red } } Clear-Host } while ($true) } function show-NamespaceMenu { do { Write-Host "`nš Namespace Menu" -ForegroundColor Cyan Write-Host "------------------------------------" $namespaceOptions = @( "[1] Show empty namespaces" "š Back (B) | ā Exit (Q)" ) foreach ($option in $namespaceOptions) { Write-Host $option } $namespaceChoice = Read-Host "`nš¤ Enter your choice" Clear-Host switch ($namespaceChoice) { "1" { Show-EmptyNamespaces } "B" { return } "Q" { Write-Host "š Exiting KubeBuddy. Have a great day! š"; exit } default { Write-Host "ā ļø Invalid choice. Please try again!" -ForegroundColor Red } } Clear-Host } while ($true) } # š Pod Management Menu function Show-PodMenu { do { Write-Host "`nš Pod Management Menu" -ForegroundColor Cyan Write-Host "--------------------------------`n" # Ask for namespace preference Write-Host "š¤ Would you like to check:`n" -ForegroundColor Yellow Write-Host " [1] All namespaces š" Write-Host " [2] Choose a specific namespace" Write-Host " š Back [B]" $nsChoice = Read-Host "`nEnter choice" Clear-Host if ($nsChoice -match "^[Bb]$") { return } $namespace = "" if ($nsChoice -match "^[2]$") { do { $selectedNamespace = Read-Host "`nš¤ Enter the namespace (or type 'L' to list available ones)" Clear-Host if ($selectedNamespace -match "^[Ll]$") { Write-Host -NoNewline "`rš¤ Fetching available namespaces..." -ForegroundColor Yellow Start-Sleep -Seconds 1 # Optional small delay for UX # Capture namespaces first $namespaces = kubectl get namespaces --no-headers | ForEach-Object { $_.Split()[0] } # Clear previous line and print the list properly Write-Host "`rš¤ Available namespaces fetched. " -ForegroundColor Green Write-Host "`nš¤ Available Namespaces:`n" -ForegroundColor Cyan $namespaces | ForEach-Object { Write-Host $_ } Write-Host "" $selectedNamespace = "" # Reset to prompt again } } until ($selectedNamespace -match "^[a-zA-Z0-9-]+$" -and $selectedNamespace -ne "") $namespace = "$selectedNamespace" } do { # Clear screen but keep the "Using namespace" message Clear-Host Write-Host "`nš¤ Using namespace: " -NoNewline -ForegroundColor Cyan Write-Host $(if ($namespace -eq "") { "All Namespaces š" } else { $namespace }) -ForegroundColor Yellow Write-Host "" Write-Host "š¦ Choose a pod operation:`n" -ForegroundColor Cyan $podOptions = @( "[1] Show pods with high restarts" "[2] Show long-running pods" "[3] Show failed pods" "[4] Show pending pods" "[5] Show CrashLoopBackOff pods" "[6] Show running debug pods." "š Back [B] | ā Exit [Q]" ) foreach ($option in $podOptions) { Write-Host $option } $podChoice = Read-Host "`nš¤ Enter your choice" Clear-Host switch ($podChoice) { "1" { Show-PodsWithHighRestarts -Namespace $Namespace } "2" { Show-LongRunningPods -Namespace $Namespace } "3" { Show-FailedPods -Namespace $Namespace } "4" { Show-PendingPods -Namespace $Namespace } "5" { Show-CrashLoopBackOffPods -Namespace $Namespace } "6" { Show-LeftoverDebugPods -Namespace $Namespace } "B" { return } "Q" { Write-Host "š Exiting KubeBuddy. Have a great day! š"; exit } default { Write-Host "ā ļø Invalid choice. Please try again!" -ForegroundColor Red } } Clear-Host } while ($true) } while ($true) } # š Service & Networking Menu function Show-ServiceMenu { do { Write-Host "`nš Service & Networking Menu" -ForegroundColor Cyan Write-Host "------------------------------------" $serviceOptions = @( "[1] Show services without endpoints" "š Back [B] | ā Exit [Q]" ) foreach ($option in $serviceOptions) { Write-Host $option } $serviceChoice = Read-Host "`nš¤ Enter your choice" Clear-Host switch ($serviceChoice) { "1" { Show-ServicesWithoutEndpoints } "B" { return } "Q" { Write-Host "š Exiting KubeBuddy. Have a great day! š"; exit } default { Write-Host "ā ļø Invalid choice. Please try again!" -ForegroundColor Red } } Clear-Host } while ($true) } # š¦ Storage Management Menu function Show-StorageMenu { do { Write-Host "`nš¦ Storage Management Menu" -ForegroundColor Cyan Write-Host "------------------------------------" $storageOptions = @( "[1] Show unused PVCs" "š Back [B] | ā Exit [Q]" ) foreach ($option in $storageOptions) { Write-Host $option } $storageChoice = Read-Host "`nš¤ Enter your choice" Clear-Host switch ($storageChoice) { "1" { Show-UnusedPVCs } "B" { return } "Q" { Write-Host "š Exiting KubeBuddy. Have a great day! š"; exit } default { Write-Host "ā ļø Invalid choice. Please try again!" -ForegroundColor Red } } Clear-Host } while ($true) } # š RBAC & Security Menu function Show-RBACMenu { do { Write-Host "`nš RBAC & Security Menu" -ForegroundColor Cyan Write-Host "------------------------------------" $rbacOptions = @( "[1] Check RBAC misconfigurations" "[2] Show orphaned ConfigMaps" "[3] Show orphaned Secrets" "š Back [B] | ā Exit [Q]" ) foreach ($option in $rbacOptions) { Write-Host $option } $rbacChoice = Read-Host "`nš¤ Enter your choice" Clear-Host switch ($rbacChoice) { "1" { Check-RBACMisconfigurations } "2" { Check-OrphanedConfigMaps } "3" { Check-OrphanedSecrets } "B" { return } "Q" { Write-Host "š Exiting KubeBuddy. Have a great day! š"; exit } default { Write-Host "ā ļø Invalid choice. Please try again!" -ForegroundColor Red } } Clear-Host } while ($true) } # šļø Kubernetes Jobs Menu function Show-JobsMenu { do { Write-Host "`nš¢ Kubernetes Jobs Menu" -ForegroundColor Cyan Write-Host "------------------------------------" $jobOptions = @( "[1] Show stuck Kubernetes jobs" "[2] Show failed Kubernetes jobs" "š Back [B] | ā Exit [Q]" ) foreach ($option in $jobOptions) { Write-Host $option } $jobChoice = Read-Host "`nš¤ Enter your choice" Clear-Host switch ($jobChoice) { "1" { Show-StuckJobs } "2" { Show-FailedJobs } "B" { return } "Q" { Write-Host "š Exiting KubeBuddy. Have a great day! š"; exit } default { Write-Host "ā ļø Invalid choice. Please try again!" -ForegroundColor Red } } Clear-Host } while ($true) } function Show-InfraBestPracticesMenu { do { Write-Host "`nā Infrastructure Best Practices Menu" -ForegroundColor Cyan Write-Host "----------------------------------" $infraOptions = @( "[1] Run AKS Best Practices Check" "š Back [B] | ā Exit [Q]" ) foreach ($option in $infraOptions) { Write-Host $option } # Get user choice $infraChoice = Read-Host "`nš¤ Enter a number" Clear-Host switch ($infraChoice) { "1" { Invoke-AKSBestPractices -SubscriptionId $SubscriptionId -ResourceGroup $ResourceGroup -ClusterName $ClusterName } "B" { return } # Back to main menu "Q" { Write-Host "š Exiting KubeBuddy. Have a great day! š"; exit } default { Write-Host "ā ļø Invalid choice. Please try again!" -ForegroundColor Red } } Clear-Host } while ($true) } |