def get_node_name():
    # Get all the nodes in the cluster
    cmd = 'kubectl --kubeconfig={} get no -o=json'.format(kubeconfig_path)
    cmd = cmd.split()
    deadline = time.time() + 60
    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)

    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']

                    # 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)