question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not having a current context set causes

See original GitHub issue

When initializing kubectl you typically do something like:

for cluster in clusters
do
  kubectl config set-cluster $cluster
  kubectl config set-credentials ...
  kubectl config set-context ...

That creates a valid config with multiple clusters, but with current-context set to "". If you try to load that config with config.load_kube_config() the library assumes "" is a context name and fails with the following:

  File "app/main.py", line 131, in get_versions
    config.load_kube_config()
  File "/usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py", line 739, in load_kube_config
    persist_config=persist_config)
  File "/usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py", line 707, in _get_kube_config_loader_for_yaml_file
    **kwargs)
  File "/usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py", line 197, in __init__
    self.set_active_context(active_context)
  File "/usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py", line 250, in set_active_context
    context_name)
  File "/usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py", line 625, in get_with_name
    'Expected object with name %s in %s list' % (name, self.name))
kubernetes.config.config_exception.ConfigException: Invalid kube-config file. Expected object with name  in /kubeconfig/contexts list

Shouldn’t the library assume "" means the context is unset and avoid trying to look it up, or make the context argument to config.load_kube_config() mandatory?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:26 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
vinayan3commented, Jan 20, 2021

I am running into this issue just like @roycaihw is hitting. I am not able to list the context because the current-context is blank.

If current-context is blank then it should still be possible to get a listing of the contexts. kubectl supports this and doesn’t blow up.

1reaction
moshevaynercommented, Nov 30, 2021

I can take that one. /assign

Read more comments on GitHub >

github_iconTop Results From Across the Web

Current context is not set Kubectl - Stack Overflow
The correct command is: kubectl config use-context ${CONTEXT}. You can confirm this with: kubectl config --help set-context Set a context ...
Read more >
contextvars — Context Variables — Python 3.11.1 ...
This module provides APIs to manage, store, and access context-local state. The ContextVar class is used to declare and work with Context Variables....
Read more >
Namespaces - Kubernetes
In Kubernetes, namespaces provides a mechanism for isolating groups of resources within a single cluster. Names of resources need to be unique ...
Read more >
Install kubectl and configure cluster access - Google Cloud
Set a default cluster for kubectl by setting the current context in the kubeconfig file. Run kubectl commands against a specific cluster using...
Read more >
Current-context must exist in order to minify - GitLab Forum
I've set up a kubernetes cluster on Google Cloud and have added Gitlab ... Any ideas what's causing the error error: current-context must ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found