From 979c5bdabefb4f4fb84f2f682b6d6532953c770a Mon Sep 17 00:00:00 2001 From: "Chung Chih, Hung" Date: Fri, 3 Mar 2017 22:16:45 +0800 Subject: [PATCH] Kube Util could not get api url from kubeconfig Kube Util could not get api url from kubeconfig when cluster name is not match with current-context Current code flow will iterator each cluster in kube config, and then find matched name with current context. The cluster's server could not been found if cluster name is not match with current context. We should find match context name instead cluster name, and then using context's cluster name to find cluster. Finally get the cluster's server Change-Id: Ia8a5004552e47e2216fe6413e0359a0df59a3d4e Closed-Bug: 1669788 --- kolla_kubernetes/utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kolla_kubernetes/utils.py b/kolla_kubernetes/utils.py index 8d78ad736..c5c35bc43 100644 --- a/kolla_kubernetes/utils.py +++ b/kolla_kubernetes/utils.py @@ -269,11 +269,13 @@ class KubeUtils(object): return ('', code) configuration = YamlUtils.yaml_dict_from_string(res) + for context in configuration['contexts']: + if context['name'] != current_context: + continue - for cluster in configuration['clusters']: - server = cluster['cluster']['server'] - context = cluster['name'] - if context == current_context: - return server + context_cluster = context['context']['cluster'] + for cluster in configuration['clusters']: + if cluster['name'] == context_cluster: + return cluster['cluster']['server'] return None