shell.py 文件源码

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

项目:kyber 作者: TakumiHQ 项目源码 文件源码
def run(name, shell):
    for pod in Pod.objects(kube_api).filter(selector={'app': name}).iterator():
        if pod.ready:  # use the first ready pod, otherwise we use the last pod
            break

    def env_vars():
        d = {
            'KYBER_USER': pwd.getpwuid(os.getuid()).pw_name,
            'KYBER_POD': pod.name,
            'KYBER_APP': name,
            'KYBER_KUBECTL_CONTEXT': kube_api.config.current_context,
        }
        return " ".join(["{}={}".format(key, val) for key, val in d.iteritems()])

    cmd = '{env} {shell}'.format(env=env_vars(), shell=shell)

    click.echo("Running shell in pod `{}` in kube ctx `{}`".format(
               pod.name, kube_api.config.current_context))
    os.execve(
        get_executable_path('kubectl'),
        ["kubectl", "exec", "-i", "-t", pod.name, '--', shell, '-c', cmd],
        os.environ
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号