def wait_for_deployment(config, application, version, release, timeout, interval):
'''Wait for all pods to become ready'''
namespace = config.get('kubernetes_namespace')
kubectl_login(config)
deployment_name = '{}-{}-{}'.format(application, version, release)
cutoff = time.time() + timeout
while time.time() < cutoff:
data = kubectl_get(namespace, 'pods', '-l',
'application={},version={},release={}'.format(application, version, release))
pods = data['items']
pods_ready = 0
for pod in pods:
if pod['status'].get('phase') == 'Running':
all_containers_ready = True
for cont in pod['status'].get('containerStatuses', []):
if not cont.get('ready'):
all_containers_ready = False
if all_containers_ready:
pods_ready += 1
if pods and pods_ready >= len(pods):
return
info('Waiting up to {:.0f} more secs for deployment '
'{} ({}/{} pods ready)..'.format(cutoff - time.time(), deployment_name, pods_ready, len(pods)))
time.sleep(interval)
raise click.Abort()
评论列表
文章目录