hjacobs / kube-ops-view

Kubernetes Operational View - read-only system dashboard for multiple K8s clusters
https://kubernetes-operational-view.readthedocs.io/
GNU General Public License v3.0
1.82k stars 258 forks source link

kubeconfig logic requires 'current-context' even when --kubeconfig-contexts are provided #133

Open ankon opened 7 years ago

ankon commented 7 years ago
$ python3 -m kube_ops_view --kubeconfig-path ~/kubeconfig --kubeconfig-contexts production
INFO:kube_ops_view.main:Listening on :8080..
ERROR:kube_ops_view.update:Failed to update
Traceback (most recent call last):
  File "/home/pi/kube-ops-view/kube_ops_view/update.py", line 42, in update_clusters
    for cluster in clusters:
  File "/home/pi/kube-ops-view/kube_ops_view/cluster_discovery.py", line 139, in get_clusters
    contexts, current_context = kubernetes.config.list_kube_config_contexts(config_file)
  File "/usr/local/lib/python3.4/dist-packages/kubernetes/config/kube_config.py", line 279, in list_kube_config_contexts
    loader = _get_kube_config_loader_for_yaml_file(config_file)
  File "/usr/local/lib/python3.4/dist-packages/kubernetes/config/kube_config.py", line 271, in _get_kube_config_loader_for_yaml_file
    **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/kubernetes/config/kube_config.py", line 108, in __init__
    self.set_active_context(active_context)
  File "/usr/local/lib/python3.4/dist-packages/kubernetes/config/kube_config.py", line 120, in set_active_context
    context_name = self._config['current-context']
  File "/usr/local/lib/python3.4/dist-packages/kubernetes/config/kube_config.py", line 242, in __getitem__
    % (key, self.name))
kubernetes.config.config_exception.ConfigException: Invalid kube-config file. Expected key current-context in kube-config

I think this is too strict: given that I am providing the name of the context to use, there is really no point in requiring a "current" context.

hjacobs commented 7 years ago

@ankon thanks for reporting, I think this is a bug in the used Kubernetes client library. I wanted to switch away anyway, see #112 (haven't checked yet whether this would fix this issue).