Skip to content

Commit

Permalink
is_eks
Browse files Browse the repository at this point in the history
  • Loading branch information
Qmando committed Nov 12, 2024
1 parent a5cc802 commit 5707d6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
24 changes: 21 additions & 3 deletions paasta_tools/api/views/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,11 @@ def remote_run_stop(request):
service = request.swagger_data.get("service")
instance = request.swagger_data.get("instance")
user = request.swagger_data["json_body"].get("user")
is_eks = is_instance_eks(service, instance)

try:
response = paasta_remote_run_2.remote_run_stop(
service, instance, user, settings.cluster
service, instance, user, settings.cluster, is_eks
)
except:
error_message = traceback.format_exc()
Expand All @@ -410,16 +411,32 @@ def remote_run_token(request):
service = request.swagger_data.get("service")
instance = request.swagger_data.get("instance")
user = request.swagger_data.get("user")
is_eks = is_instance_eks(service, instance)
try:
token = paasta_remote_run_2.create_exec_token(
service, instance, user, settings.cluster
service, instance, user, settings.cluster, is_eks
)
except:
error_message = traceback.format_exc()
raise ApiFailure(error_message, 500)
return json.dumps({"token": token})


def is_instance_eks(service, instance):
try:
instance_type = validate_service_instance(
service, instance, settings.cluster, settings.soa_dir
)
except NoConfigurationForServiceError:
error_message = no_configuration_for_service_message(
settings.cluster,
service,
instance,
)
raise Exception(error_message, 404)
return instance_type == "eks"


@view_config(route_name="remote_run.start", request_method="POST", renderer="json")
def remote_run_start(request):
service = request.swagger_data.get("service")
Expand All @@ -428,9 +445,10 @@ def remote_run_start(request):
interactive = request.swagger_data["json_body"].get("interactive", True)
recreate = request.swagger_data["json_body"].get("recreate", True)

is_eks = is_instance_eks(service, instance)
try:
response = paasta_remote_run_2.remote_run_start(
service, instance, user, settings.cluster, interactive, recreate
service, instance, user, settings.cluster, interactive, recreate, is_eks
)
except Exception:
error_message = traceback.format_exc()
Expand Down
12 changes: 4 additions & 8 deletions paasta_tools/paasta_remote_run_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from paasta_tools.utils import DEFAULT_SOA_DIR


def create_exec_token(service, instance, user, cluster):
def create_exec_token(service, instance, user, cluster, is_eks):
"""Creates a short lived token for execing into a pod"""
kube_client = KubeClient(config_file="/etc/kubernetes/admin.conf")
is_eks = True

# Load the service deployment settings
if is_eks:
deployment = load_eks_service_config_no_cache(
Expand All @@ -34,13 +34,10 @@ def create_exec_token(service, instance, user, cluster):
return token.status.token


def remote_run_start(service, instance, user, cluster, interactive, recreate):
def remote_run_start(service, instance, user, cluster, interactive, recreate, is_eks):
# TODO Overriding the kube client config for now as the api has limited permissions
kube_client = KubeClient(config_file="/etc/kubernetes/admin.conf")

# TODO hardcoded for now
is_eks = True

# Load the service deployment settings
if is_eks:
deployment = load_eks_service_config_no_cache(
Expand Down Expand Up @@ -118,10 +115,9 @@ def wait_until_pod_running(kube_client, namespace, job_name):
return pod


def remote_run_stop(service, instance, user, cluster):
def remote_run_stop(service, instance, user, cluster, is_eks):
# TODO Overriding the kube client config for now as the api has limited permissions
kube_client = KubeClient(config_file="/etc/kubernetes/admin.conf")
is_eks = True
if is_eks:
deployment = load_eks_service_config_no_cache(
service, instance, cluster, DEFAULT_SOA_DIR
Expand Down

0 comments on commit 5707d6c

Please sign in to comment.