kelproject / pykube

Python client library for Kubernetes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting current context explicitly still sends requests to the context set in kubeconfig file

ecthiender opened this issue · comments

Expected behaviour: When the current_context is set explictly using KubeConfig.set_current_context, and then further Kubernetes requests are made, Kubernetes requests are being made to new context that is set.

Actual behaviour: When the current_context is set explictly using KubeConfig.set_current_context, and then further Kubernetes requests are made, Kubernetes requests are being made to the context set in "kubeconfig" file.

Steps to reproduce (the current-context in my kube config file is test123):

config = pykube.KubeConfig.from_file("/home/Me/.kube/config")
api = pykube.HTTPClient(config)
config.set_current_context("test42")
pykube.ConfigMap.objects(api).get_by_name("my-config")

Executing the above tries to fetch the configmap from the "test123" context and not from the "test42" context.

Can confirm that. Switching context before instantiating HTTPClient works though:

config = pykube.KubeConfig.from_file("/home/Me/.kube/config")
config.set_current_context("test42")
api = pykube.HTTPClient(config)
pykube.ConfigMap.objects(api).get_by_name("my-config")