kubeshell.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:kube-shell 作者: cloudnativelabs 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号