Permalink
Browse files

Move code around to turn some stages into packages

  • Loading branch information...
ark3 committed Aug 2, 2018
1 parent 473976f commit dc1049126367b36bd9aedec7390d22f27d57dc4b
@@ -53,8 +53,8 @@
from socket import gethostbyname, gaierror
from time import time, sleep
from telepresence.expose import expose_local_services
from telepresence.ssh import SSH
from telepresence.connect.expose import expose_local_services
from telepresence.connect.ssh import SSH
from telepresence.runner import Runner, wait_for_exit
@@ -16,14 +16,12 @@
import re
from typing import Tuple
from telepresence.background import launch_local_server
from telepresence.container import MAC_LOOPBACK_IP
from telepresence.deployment import create_new_deployment, \
swap_deployment_openshift, supplant_deployment
from telepresence.expose import expose_local_services
from telepresence.remote import RemoteInfo, get_remote_info
from telepresence.runner.background import launch_local_server
from telepresence.connect.expose import expose_local_services
from telepresence.connect.ssh import SSH
from telepresence.startup import MAC_LOOPBACK_IP
from telepresence.proxy.remote import RemoteInfo
from telepresence.runner import Runner
from telepresence.ssh import SSH
from telepresence.utilities import find_free_port
@@ -149,76 +147,3 @@ def connect(
span.end()
return socks_port, ssh
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 runner.chatty 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 runner.chatty:
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
@@ -15,7 +15,7 @@
from typing import List, Tuple
from telepresence.runner import Runner
from telepresence.ssh import SSH
from telepresence.connect.ssh import SSH
def expose_local_services(
File renamed without changes.
@@ -22,15 +22,13 @@
import os.path
from telepresence import TELEPRESENCE_LOCAL_IMAGE
from telepresence.remote import RemoteInfo
from telepresence.proxy.remote import RemoteInfo
from telepresence.runner import Runner
from telepresence.ssh import SSH
from telepresence.connect.ssh import SSH
from telepresence.startup import MAC_LOOPBACK_IP
from telepresence.utilities import random_name
from telepresence.vpn import get_proxy_cidrs
# IP that shouldn't be in use on Internet, *or* local networks:
MAC_LOOPBACK_IP = "198.18.0.254"
# Whether Docker requires sudo
SUDO_FOR_DOCKER = os.path.exists("/var/run/docker.sock") and not os.access(
"/var/run/docker.sock", os.W_OK
View
@@ -22,9 +22,9 @@
from shutil import copy
from telepresence.utilities import kill_process
from telepresence.remote import RemoteInfo
from telepresence.proxy.remote import RemoteInfo
from telepresence.runner import Runner
from telepresence.ssh import SSH
from telepresence.connect.ssh import SSH
from telepresence.vpn import connect_sshuttle
View
@@ -23,7 +23,8 @@
from telepresence.container import run_docker_command
from telepresence.local import run_local_command
from telepresence.output import Output
from telepresence.proxy import start_proxy, connect
from telepresence.proxy import start_proxy
from telepresence.connect import connect
from telepresence.mount import mount_remote
from telepresence.remote_env import get_remote_env, write_env_files
from telepresence.startup import analyze_args
View
@@ -16,7 +16,7 @@
from typing import Tuple, Callable
from telepresence.runner import Runner
from telepresence.ssh import SSH
from telepresence.connect.ssh import SSH
def mount_remote_volumes(
@@ -0,0 +1,93 @@
# Copyright 2018 Datawire. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
from telepresence.proxy.deployment import create_new_deployment, \
swap_deployment_openshift, supplant_deployment
from telepresence.proxy.remote import RemoteInfo, get_remote_info
from telepresence.runner import Runner
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 runner.chatty 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 runner.chatty:
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
@@ -22,7 +22,7 @@
from telepresence import (
TELEPRESENCE_REMOTE_IMAGE, TELEPRESENCE_REMOTE_IMAGE_PRIV
)
from telepresence.remote import get_deployment_json
from telepresence.proxy.remote import get_deployment_json
from telepresence.runner import Runner
from telepresence.utilities import get_alternate_nameserver
File renamed without changes.
@@ -18,7 +18,7 @@
from time import time, sleep
from typing import Dict, Tuple, List
from telepresence.remote import RemoteInfo
from telepresence.proxy.remote import RemoteInfo
from telepresence.runner import Runner
@@ -26,12 +26,12 @@
from threading import Thread
from time import sleep, time
from telepresence.background import (
from telepresence.runner.background import (
Background, BackgroundThread, BackgroundProcess, TrackedBG
)
from telepresence.cache import Cache
from telepresence.runner.cache import Cache
from telepresence.output import Output
from telepresence.span import Span
from telepresence.runner.span import Span
from telepresence.utilities import str_command
_CleanupItem = typing.NamedTuple(
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -24,6 +24,9 @@
from telepresence.runner import Runner
# IP that shouldn't be in use on Internet, *or* local networks:
MAC_LOOPBACK_IP = "198.18.0.254"
def kubectl_or_oc(server: str) -> str:
"""
View
@@ -19,8 +19,8 @@
from time import time, sleep
from typing import List, Dict
from telepresence.ssh import SSH
from telepresence.remote import RemoteInfo
from telepresence.connect.ssh import SSH
from telepresence.proxy.remote import RemoteInfo
from telepresence.utilities import random_name
from telepresence.runner import Runner
View
@@ -24,12 +24,12 @@
import telepresence.cli
import telepresence.container
import telepresence.deployment
import telepresence.proxy.deployment
import telepresence.output
import telepresence.vpn
import telepresence.main
from telepresence.cache import Cache
from telepresence.runner.cache import Cache
COMPLEX_DEPLOYMENT = """\
apiVersion: extensions/v1beta1
@@ -189,7 +189,7 @@ def test_swap_deployment_changes():
"""
original = yaml.safe_load(COMPLEX_DEPLOYMENT)
expected = yaml.safe_load(SWAPPED_DEPLOYMENT)
assert telepresence.deployment.new_swapped_deployment(
assert telepresence.proxy.deployment.new_swapped_deployment(
original,
"nginxhttps",
"random_id_123",

0 comments on commit dc10491

Please sign in to comment.