Ejemplo n.º 1
0
def start_proxy(runner: Runner, args: argparse.Namespace) -> RemoteInfo:
    """Start the kubectl port-forward and SSH clients that do the proxying."""
    span = runner.span()
    if sys.stdout.isatty() and args.method != "container":
        runner.show("Starting proxy with method '{}', which has the following "
                    "limitations:".format(args.method))
        if args.method == "vpn-tcp":
            runner.show("All processes are affected, only one telepresence"
                        " can run per machine, and you can't use other VPNs."
                        " You may need to add cloud hosts with --also-proxy.")
        elif args.method == "inject-tcp":
            runner.show(
                "Go programs, static binaries, suid programs, and custom DNS"
                " implementations are not supported.")
        runner.show("For a full list of method limitations see "
                    "https://telepresence.io/reference/methods.html\n")
    if args.mount and sys.stdout.isatty():
        runner.show("\nVolumes are rooted at $TELEPRESENCE_ROOT. See "
                    "https://telepresence.io/howto/volumes.html for details.")

    run_id = None

    if args.new_deployment is not None:
        # This implies --new-deployment:
        args.deployment, run_id = create_new_deployment(runner, args)

    if args.swap_deployment is not None:
        # This implies --swap-deployment
        if runner.kubectl.command == "oc":
            args.deployment, run_id, container_json = (
                swap_deployment_openshift(runner, args))
        else:
            args.deployment, run_id, container_json = supplant_deployment(
                runner, args)
        args.expose.merge_automatic_ports([
            p["containerPort"] for p in container_json.get("ports", [])
            if p["protocol"] == "TCP"
        ])

    deployment_type = "deployment"
    if runner.kubectl.command == "oc":
        # OpenShift Origin uses DeploymentConfig instead, but for swapping we
        # mess with ReplicationController instead because mutating DC doesn't
        # work:
        if args.swap_deployment:
            deployment_type = "rc"
        else:
            deployment_type = "deploymentconfig"

    remote_info = get_remote_info(
        runner,
        args.deployment,
        args.context,
        args.namespace,
        deployment_type,
        run_id=run_id,
    )
    span.end()

    return remote_info
Ejemplo n.º 2
0
def start_proxy(
    runner: Runner, args: argparse.Namespace
) -> Tuple[Subprocesses, Dict[str, str], int, SSH, RemoteInfo]:
    """Start the kubectl port-forward and SSH clients that do the proxying."""
    span = runner.span()
    if sys.stdout.isatty() and args.method != "container":
        print(
            "Starting proxy with method '{}', which has the following "
            "limitations:".format(args.method),
            file=sys.stderr,
            end=" ",
        )
        if args.method == "vpn-tcp":
            print(
                "All processes are affected, only one telepresence"
                " can run per machine, and you can't use other VPNs."
                " You may need to add cloud hosts with --also-proxy.",
                file=sys.stderr,
                end=" ",
            )
        elif args.method == "inject-tcp":
            print(
                "Go programs, static binaries, suid programs, and custom DNS"
                " implementations are not supported.",
                file=sys.stderr,
                end=" ",
            )
        print(
            "For a full list of method limitations see "
            "https://telepresence.io/reference/methods.html",
            file=sys.stderr)
    if sys.stdout.isatty():
        print(
            "Volumes are rooted at $TELEPRESENCE_ROOT. See "
            "https://telepresence.io/howto/volumes.html for details.\n",
            file=sys.stderr)

    run_id = None

    if args.new_deployment is not None:
        # This implies --new-deployment:
        args.deployment, run_id = create_new_deployment(runner, args)

    if args.swap_deployment is not None:
        # This implies --swap-deployment
        if runner.kubectl_cmd == "oc":
            args.deployment, run_id, container_json = (
                swap_deployment_openshift(runner, args))
        else:
            args.deployment, run_id, container_json = swap_deployment(
                runner, args)
        args.expose.merge_automatic_ports([
            p["containerPort"] for p in container_json.get("ports", [])
            if p["protocol"] == "TCP"
        ])

    deployment_type = "deployment"
    if runner.kubectl_cmd == "oc":
        # OpenShift Origin uses DeploymentConfig instead, but for swapping we
        # mess with RweplicationController instead because mutating DC doesn't
        # work:
        if args.swap_deployment:
            deployment_type = "rc"
        else:
            deployment_type = "deploymentconfig"

    remote_info = get_remote_info(
        runner,
        args.deployment,
        args.context,
        args.namespace,
        deployment_type,
        run_id=run_id,
    )

    processes, socks_port, ssh = connect(runner, remote_info, args)

    # Get the environment variables we want to copy from the remote pod; it may
    # take a few seconds for the SSH proxies to get going:
    start = time()
    while time() - start < 10:
        try:
            env = get_env_variables(runner, remote_info, args.context)
            break
        except CalledProcessError:
            sleep(0.25)

    span.end()
    return processes, env, socks_port, ssh, remote_info