def switch_to_next_cluster():
if not os.path.exists(os.path.expanduser("~/.kube/config")):
return
with open(os.path.expanduser("~/.kube/config"), "r") as fd:
docs = yaml.load_all(fd)
for doc in docs:
contexts = doc.get("contexts")
if contexts:
KubeConfig.current_context_index = (KubeConfig.current_context_index+1) % len(contexts)
cluster_name = contexts[KubeConfig.current_context_index]['name']
kubectl_config_use_context = "kubectl config use-context " + cluster_name
cmd_process = subprocess.Popen(kubectl_config_use_context, shell=True, stdout=subprocess.PIPE)
cmd_process.wait()
return
评论列表
文章目录