Beispiel #1
0
def main():
    """
    Top-level function for Telepresence
    """

    ########################################
    # Preliminaries: No changes to the machine or the cluster, no cleanup
    # Capture environment info and the user's intent

    with crash_reporting():
        args = parse_args()  # tab-completion stuff goes here

        runner = Runner(Output(args.logfile), None, args.verbose)
        span = runner.span()
        runner.add_cleanup("Stop time tracking", span.end)
        runner.kubectl = KubeInfo(runner, args)

        start_proxy = proxy.setup(runner, args)
        do_connect = connect.setup(runner, args)
        get_remote_env, write_env_files = remote_env.setup(runner, args)
        launch = outbound.setup(runner, args)
        mount_remote = mount.setup(runner, args)

        final_checks(runner, args)

        # Usage tracking
        call_scout(runner, args)

    ########################################
    # Now it's okay to change things

    with runner.cleanup_handling(), crash_reporting(runner):
        # Set up the proxy pod (operation -> pod name)
        remote_info = start_proxy(runner)

        # Connect to the proxy (pod name -> ssh object)
        socks_port, ssh = do_connect(runner, remote_info)

        # Capture remote environment information (ssh object -> env info)
        env = get_remote_env(runner, remote_info)

        # Handle filesystem stuff
        mount_dir = mount_remote(runner, env, ssh)

        # Maybe write environment files
        write_env_files(runner, env)

        # Set up outbound networking (pod name, ssh object)
        # Launch user command with the correct environment (...)
        user_process = launch(runner, remote_info, env, socks_port, ssh,
                              mount_dir)

        wait_for_exit(runner, user_process)
Beispiel #2
0
    def open(cls, logfile_path, kubectl_cmd: str, verbose: bool):
        """
        FIXME: This is bogus now.

        The second argument to the constructor should be a KubeInfo instance.
        This method is used by the local-docker entrypoint script. Maybe we can
        kill this method and have it just pass None instead?

        :return: File-like object for the given logfile path.
        """
        output = Output(logfile_path)
        return cls(output, kubectl_cmd, verbose)
Beispiel #3
0
 def open(cls, logfile_path, kubectl_cmd: str, verbose: bool):
     """
     :return: File-like object for the given logfile path.
     """
     output = Output(logfile_path)
     return cls(output, kubectl_cmd, verbose)
Beispiel #4
0
def main(session):
    """
    Top-level function for Telepresence
    """

    ########################################
    # Preliminaries: No changes to the machine or the cluster, no cleanup

    with crash_reporting():
        session.args = parse_args()  # tab-completion stuff goes here

        session.output = Output(session.args.logfile)
        del session.args.logfile

        session.kube_info, session.runner = analyze_args(session)

        span = session.runner.span()
        session.runner.add_cleanup("Stop time tracking", span.end)

        # Usage tracking
        call_scout(session)

    ########################################
    # Now it's okay to change things

    with session.runner.cleanup_handling(), crash_reporting(session.runner):
        runner = session.runner
        args = session.args

        # Set up the proxy pod (operation -> pod name)
        remote_info = start_proxy(runner, args)

        # Connect to the proxy (pod name -> ssh object)
        socks_port, ssh = connect(runner, remote_info, args)

        # Capture remote environment information (ssh object -> env info)
        env = get_remote_env(runner, args, remote_info)

        # Used by mount_remote
        session.ssh = ssh
        session.remote_info = remote_info
        session.env = env

        # Handle filesystem stuff (pod name, ssh object)
        mount_dir = mount_remote(session)

        # Maybe write environment files
        write_env_files(session)

        # Set up outbound networking (pod name, ssh object)
        # Launch user command with the correct environment (...)
        if args.method == "container":
            user_process = run_docker_command(
                runner,
                remote_info,
                args,
                env,
                ssh,
                mount_dir,
            )
        else:
            user_process = run_local_command(runner, remote_info, args, env,
                                             socks_port, ssh)

        wait_for_exit(runner, user_process)
Beispiel #5
0
def main(session):
    """
    Top-level function for Telepresence
    """

    ########################################
    # Preliminaries: No changes to the machine or the cluster, no cleanup

    session.args = parse_args()  # tab-completion stuff goes here

    session.output = Output(session.args.logfile)
    del session.args.logfile

    session.kube_info, session.runner = analyze_args(session)

    span = session.runner.span()
    atexit.register(span.end)

    # Set up signal handling
    # Make SIGTERM and SIGHUP do clean shutdown (in particular, we want atexit
    # functions to be called):
    def shutdown(signum, frame):
        raise SystemExit(0)

    signal.signal(signal.SIGTERM, shutdown)
    signal.signal(signal.SIGHUP, shutdown)

    # Usage tracking
    call_scout(session)

    # Set up exit handling
    # XXX exit handling via atexit
    try:
        ########################################
        # Now it's okay to change things

        runner = session.runner
        args = session.args

        # Set up the proxy pod (operation -> pod name)
        remote_info = start_proxy(runner, args)

        # Connect to the proxy (pod name -> ssh object)
        subprocesses, socks_port, ssh = connect(runner, remote_info, args)

        # Capture remote environment information (ssh object -> env info)
        env = get_remote_env(runner, args, remote_info)

        # Used by mount_remote
        session.ssh = ssh
        session.remote_info = remote_info
        session.env = env

        # Handle filesystem stuff (pod name, ssh object)
        mount_dir = mount_remote(session)

        # Maybe write environment files
        write_env_files(session)

        # Set up outbound networking (pod name, ssh object)
        # Launch user command with the correct environment (...)
        if args.method == "container":
            user_process = run_docker_command(
                runner,
                remote_info,
                args,
                env,
                subprocesses,
                ssh,
                mount_dir,
            )
        else:
            user_process = run_local_command(runner, remote_info, args, env,
                                             subprocesses, socks_port, ssh,
                                             mount_dir)

        # Clean up (call the cleanup methods for everything above)
        # XXX handled by wait_for_exit and atexit
        wait_for_exit(runner, user_process, subprocesses)

    finally:
        pass