Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Wait-ForNamespaceToDie($namespace) {
- $old_ErrorActionPreference = $ErrorActionPreference
- try {
- $ErrorActionPreference = 'SilentlyContinue'
- $startDate = Get-Date
- do {
- kubectl get namespace $namespace
- } while ($LastExitCode -eq 0 -and $startDate.AddMinutes(5) -gt (Get-Date))
- } finally {
- $ErrorActionPreference = $old_ErrorActionPreference
- }
- }
- function Kill-AllPodsInNamespace($namespace) {
- # Clean up any existing pods left over from when we deleted the namespace
- $pods = kubectl get pods -o json -n $namespace | `
- ConvertFrom-Json | `
- Select -ExpandProperty items | `
- ? {$_.status.phase -eq "Terminating" -or $_.status.phase -eq "Unknown" -or $_.status.reason -eq "NodeLost"}
- if ($pods.Count -ne 0) {
- # Forcefully kill them
- $pods | % {kubectl delete pod $_.metadata.name --grace-period=0 --force -n $namespace}
- } else {
- Write-Host "No terminating pods found"
- }
- }
Add Comment
Please, Sign In to add comment