From e87b537654fefcf92b5e8cb8518147072839660c Mon Sep 17 00:00:00 2001 From: Mike Wilson Date: Mon, 29 Jan 2018 20:27:35 -0500 Subject: [PATCH] Forcing get_node_name to continue searching for a node name if the returned list of nodes doesn't include this one. There was a race condition where the kubelet was restarting and we were querying the api server for this node. --- .../reactive/kubernetes_worker.py | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/cluster/juju/layers/kubernetes-worker/reactive/kubernetes_worker.py b/cluster/juju/layers/kubernetes-worker/reactive/kubernetes_worker.py index 1a4fa1641dd..a5fa34c5fc8 100644 --- a/cluster/juju/layers/kubernetes-worker/reactive/kubernetes_worker.py +++ b/cluster/juju/layers/kubernetes-worker/reactive/kubernetes_worker.py @@ -979,31 +979,30 @@ def get_node_name(): while time.time() < deadline: try: raw = check_output(cmd) - break except CalledProcessError: hookenv.log('Failed to get node name for node %s.' ' Will retry.' % (gethostname())) time.sleep(1) - else: - msg = 'Failed to get node name for node %s' % gethostname() - raise GetNodeNameFailed(msg) + continue - result = json.loads(raw.decode('utf-8')) - if 'items' in result: - for node in result['items']: - if 'status' not in node: - continue - if 'addresses' not in node['status']: - continue + result = json.loads(raw.decode('utf-8')) + if 'items' in result: + for node in result['items']: + if 'status' not in node: + continue + if 'addresses' not in node['status']: + continue - # find the hostname - for address in node['status']['addresses']: - if address['type'] == 'Hostname': - if address['address'] == gethostname(): - return node['metadata']['name'] + # find the hostname + for address in node['status']['addresses']: + if address['type'] == 'Hostname': + if address['address'] == gethostname(): + return node['metadata']['name'] + + # if we didn't match, just bail to the next node + break + time.sleep(1) - # if we didn't match, just bail to the next node - break msg = 'Failed to get node name for node %s' % gethostname() raise GetNodeNameFailed(msg)