|
| 1 | +import asyncio |
1 | 2 | import backoff |
2 | 3 | from collections import OrderedDict |
3 | 4 | from datetime import datetime |
@@ -294,9 +295,24 @@ def restart(self, **kwargs): # noqa |
294 | 295 | return [] |
295 | 296 |
|
296 | 297 | try: |
297 | | - for pod in self.list_pods(**kwargs): |
298 | | - # This function verifies the delete |
299 | | - self._scheduler.delete_pod(self.id, pod['name']) |
| 298 | + @asyncio.coroutine |
| 299 | + def delete_pod(namespace, name, loop): |
| 300 | + """ |
| 301 | + A synchronous function that deletes a pod |
| 302 | + """ |
| 303 | + logger.debug('Deleting pod {} as part of a pod restart call'.format(name)) |
| 304 | + # Gives a pod however long the termination grace period is to terminate |
| 305 | + # This executes a delete in its own thread (in parallel) |
| 306 | + yield from loop.run_in_executor(None, self._scheduler.delete_pod, namespace, name) |
| 307 | + logger.debug('Finished deleting pod {}'.format(name)) |
| 308 | + |
| 309 | + # gather all pods to be deleted |
| 310 | + loop = asyncio.get_event_loop() |
| 311 | + tasks = [delete_pod(self.id, pod['name'], loop) for pod in self.list_pods(**kwargs)] |
| 312 | + if tasks: |
| 313 | + # run deletes in parallel |
| 314 | + loop.run_until_complete(asyncio.wait(tasks)) |
| 315 | + |
300 | 316 | except Exception as e: |
301 | 317 | err = "warning, some pods failed to stop:\n{}".format(str(e)) |
302 | 318 | self.log(err, logging.WARNING) |
|
0 commit comments