Update status to show failing services.

This commit is contained in:
Konstantinos Tsakalozos
2017-07-20 14:57:02 +03:00
parent acc19cafa4
commit 685dff99ab
2 changed files with 52 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ from shlex import split
from subprocess import check_call, check_output
from subprocess import CalledProcessError
from socket import gethostname
from time import sleep
from charms import layer
from charms.layer import snap
@@ -257,11 +258,27 @@ def update_kubelet_status():
''' There are different states that the kubelet can be in, where we are
waiting for dns, waiting for cluster turnup, or ready to serve
applications.'''
if (_systemctl_is_active('snap.kubelet.daemon')):
services = [
'kubelet',
'kube-proxy'
]
for service in services:
daemon = 'snap.{}.daemon'.format(service)
if not _systemctl_is_active(daemon):
hookenv.log("Service {} id down. Starting it.".format(daemon))
sleep(10)
failing_services = []
for service in services:
daemon = 'snap.{}.daemon'.format(service)
if not _systemctl_is_active(daemon):
failing_services.append(service)
if len(failing_services) == 0:
hookenv.status_set('active', 'Kubernetes worker running.')
# if kubelet is not running, we're waiting on something else to converge
elif (not _systemctl_is_active('snap.kubelet.daemon')):
hookenv.status_set('waiting', 'Waiting for kubelet to start.')
else:
msg = 'Waiting for {} to start.'.format(','.join(failing_services))
hookenv.status_set('waiting', msg)
@when('certificates.available')