Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Juju kubernetes-master charm: improve status messages #40691

Merged
merged 4 commits into from Jan 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 35 additions & 24 deletions cluster/juju/layers/kubernetes-master/reactive/kubernetes_master.py
Expand Up @@ -19,7 +19,7 @@
import random
import socket
import string

import json

from shlex import split
from subprocess import call
Expand Down Expand Up @@ -182,7 +182,9 @@ def set_app_version():
@when('kube-dns.available', 'kubernetes-master.components.installed')
def idle_status():
''' Signal at the end of the run that we are running. '''
if hookenv.config('service-cidr') != service_cidr():
if not all_kube_system_pods_running():
hookenv.status_set('waiting', 'Waiting for kube-system pods to start')
elif hookenv.config('service-cidr') != service_cidr():
hookenv.status_set('active', 'WARN: cannot change service-cidr, still using ' + service_cidr())
else:
hookenv.status_set('active', 'Kubernetes master running.')
Expand All @@ -208,7 +210,6 @@ def start_master(etcd, tls):
hookenv.log('Starting {0} service.'.format(service))
host.service_start(service)
hookenv.open_port(6443)
hookenv.status_set('active', 'Kubernetes master services ready.')
set_state('kubernetes-master.components.started')


Expand Down Expand Up @@ -293,28 +294,11 @@ def remove_dashboard_addons():
remove_state('kubernetes.dashboard.available')


@when('kubernetes-master.components.installed')
@when('kubernetes-master.components.started')
@when_not('kube-dns.available')
def start_kube_dns():
''' State guard to starting DNS '''

# Interrogate the cluster to find out if we have at least one worker
# that is capable of running the workload.

cmd = ['kubectl', 'get', 'nodes']
try:
out = check_output(cmd)
if b'NAME' not in out:
hookenv.log('Unable to determine node count, waiting '
'until nodes are ready')
return
except CalledProcessError:
hookenv.log('kube-apiserver not ready, not requesting dns deployment')
return

message = 'Rendering the Kubernetes DNS files.'
hookenv.log(message)
hookenv.status_set('maintenance', message)
hookenv.status_set('maintenance', 'Deploying KubeDNS')

context = {
'arch': arch(),
Expand All @@ -325,8 +309,14 @@ def start_kube_dns():
'dns_domain': hookenv.config('dns_domain')
}
}
create_addon('kubedns-controller.yaml', context)
create_addon('kubedns-svc.yaml', context)

try:
create_addon('kubedns-controller.yaml', context)
create_addon('kubedns-svc.yaml', context)
except CalledProcessError:
hookenv.status_set('waiting', 'Waiting to retry KubeDNS deployment')
return

set_state('kube-dns.available')


Expand Down Expand Up @@ -666,3 +656,24 @@ def setup_tokens(token, username, user):
token = ''.join(random.SystemRandom().choice(alpha) for _ in range(32))
with open(known_tokens, 'w') as stream:
stream.write('{0},{1},{2}'.format(token, username, user))


def all_kube_system_pods_running():
''' Check pod status in the kube-system namespace. Returns True if all
pods are running, False otherwise. '''
cmd = ['kubectl', 'get', 'po', '-n', 'kube-system', '-o', 'json']

try:
output = check_output(cmd).decode('utf-8')
except CalledProcessError:
hookenv.log('failed to get kube-system pod status')
return False

result = json.loads(output)

for pod in result['items']:
status = pod['status']['phase']
if status != 'Running':
return False

return True