kubeshell.py 文件源码

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

项目:kube-shell 作者: cloudnativelabs 项目源码 文件源码
def parse_kubeconfig():
        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:
                current_context = doc.get("current-context", "")
                contexts = doc.get("contexts")
                if contexts:
                    for index, context in enumerate(contexts):
                        if context['name'] == current_context:
                            KubeConfig.current_context_index = index
                            KubeConfig.current_context_name = context['name']
                            if 'cluster' in context['context']:
                                KubeConfig.clustername = context['context']['cluster']
                            if 'namespace' in context['context']:
                                KubeConfig.namespace = context['context']['namespace']
                            if 'user' in context['context']:
                                KubeConfig.user = context['context']['user']
                            return (KubeConfig.clustername, KubeConfig.user, KubeConfig.namespace)
        return ("", "", "")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号