DeleteNamespaceAndWait deletes a namespace if existent and returns when deletion is completed
( ctx context.Context, crudClient client.Client, name string, timeoutSeconds int, )
| 204 | |
| 205 | // DeleteNamespaceAndWait deletes a namespace if existent and returns when deletion is completed |
| 206 | func DeleteNamespaceAndWait( |
| 207 | ctx context.Context, |
| 208 | crudClient client.Client, |
| 209 | name string, |
| 210 | timeoutSeconds int, |
| 211 | ) error { |
| 212 | // Exit immediately if the namespace is listed in PreserveNamespaces |
| 213 | for _, v := range getPreserveNamespaces() { |
| 214 | if strings.HasPrefix(name, v) { |
| 215 | return nil |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | ctx, cancel := context.WithTimeout(ctx, time.Duration(timeoutSeconds)*time.Second) |
| 220 | defer cancel() |
| 221 | |
| 222 | err := deleteNamespace(ctx, crudClient, name, client.PropagationPolicy("Background")) |
| 223 | if err != nil { |
| 224 | return err |
| 225 | } |
| 226 | |
| 227 | podList, err := pods.List(ctx, crudClient, name) |
| 228 | if err != nil { |
| 229 | return err |
| 230 | } |
| 231 | |
| 232 | for _, pod := range podList.Items { |
| 233 | err = pods.Delete( |
| 234 | ctx, crudClient, |
| 235 | name, pod.Name, |
| 236 | client.GracePeriodSeconds(1), client.PropagationPolicy("Background"), |
| 237 | ) |
| 238 | if err != nil && !apierrs.IsNotFound(err) { |
| 239 | return err |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | return wait.PollUntilContextCancel(ctx, time.Second, true, |
| 244 | func(ctx context.Context) (bool, error) { |
| 245 | err := crudClient.Get(ctx, client.ObjectKey{Name: name}, &corev1.Namespace{}) |
| 246 | if apierrs.IsNotFound(err) { |
| 247 | return true, nil |
| 248 | } |
| 249 | return false, err |
| 250 | }, |
| 251 | ) |
| 252 | } |
| 253 | |
| 254 | // DumpNamespaceObjects logs the clusters, pods, pvcs etc. found in a namespace as JSON sections |
| 255 | func DumpNamespaceObjects( |
no test coverage detected