Guest User

Untitled

a guest
Nov 15th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. function Wait-ForNamespaceToDie($namespace) {
  2. $old_ErrorActionPreference = $ErrorActionPreference
  3. try {
  4. $ErrorActionPreference = 'SilentlyContinue'
  5. $startDate = Get-Date
  6. do {
  7. kubectl get namespace $namespace
  8. } while ($LastExitCode -eq 0 -and $startDate.AddMinutes(5) -gt (Get-Date))
  9. } finally {
  10. $ErrorActionPreference = $old_ErrorActionPreference
  11. }
  12. }
  13.  
  14. function Kill-AllPodsInNamespace($namespace) {
  15. # Clean up any existing pods left over from when we deleted the namespace
  16. $pods = kubectl get pods -o json -n $namespace | `
  17. ConvertFrom-Json | `
  18. Select -ExpandProperty items | `
  19. ? {$_.status.phase -eq "Terminating" -or $_.status.phase -eq "Unknown" -or $_.status.reason -eq "NodeLost"}
  20.  
  21. if ($pods.Count -ne 0) {
  22. # Forcefully kill them
  23. $pods | % {kubectl delete pod $_.metadata.name --grace-period=0 --force -n $namespace}
  24. } else {
  25. Write-Host "No terminating pods found"
  26. }
  27. }
Add Comment
Please, Sign In to add comment