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 # Check for a subcommand with crash_reporting(): args = command_parse_args(None, only_for_commands=True) if args is not None: command_main(args) 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)
def main(): """ Top-level function for Telepresence """ with crash_reporting(): ######################################## # Preliminaries: No changes to the machine or the cluster, no cleanup # Capture environment info args = parse_args() # tab-completion stuff goes here runner = Runner(args.logfile, args.verbose) span = runner.span() runner.add_cleanup("Stop time tracking", span.end) set_kube_command(runner, args) with runner.cleanup_handling(), crash_reporting(runner): ######################################## # Intent: Fast, user prompts here, cleanup available # Capture the user's intent 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) ######################################## # Action: Perform the user's intended operation(s) # Now it's okay to change things # 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, pod_info = get_remote_env(runner, ssh, 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, pod_info ) runner.wait_for_exit(user_process)