Skip to content

Commit a986fec

Browse files
committed
Remove mesos code from get_running_task_allocation
There's no more mesos, we can get rid of this code :p
1 parent 53cbabb commit a986fec

File tree

1 file changed

+14
-112
lines changed

1 file changed

+14
-112
lines changed

paasta_tools/contrib/get_running_task_allocation.py

+14-112
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/opt/venvs/paasta-tools/bin/python
22
import argparse
3+
import json
34
import time
45
from typing import Any
56
from typing import Dict
@@ -11,16 +12,11 @@
1112
from typing import Optional
1213
from typing import Tuple
1314

14-
import a_sync
15-
import simplejson as json
1615
from kubernetes.client import V1Pod
1716
from kubernetes.client import V1ResourceRequirements
1817

1918
from paasta_tools import kubernetes_tools
20-
from paasta_tools import mesos_tools
2119
from paasta_tools.kubernetes_tools import KubeClient
22-
from paasta_tools.mesos.exceptions import SlaveDoesNotExist
23-
from paasta_tools.mesos.task import Task
2420
from paasta_tools.utils import load_system_paasta_config
2521

2622

@@ -40,81 +36,10 @@ class TaskAllocationInfo(NamedTuple):
4036
host_ip: str
4137
git_sha: str
4238
config_sha: str
43-
mesos_container_id: str # Because Mesos task info does not have docker id
39+
mesos_container_id: str # XXX(luisp): can we delete this now or do we need to cleanup splunk usages first?
4440
namespace: Optional[str]
4541

4642

47-
def get_container_info_from_mesos_task(
48-
task: Task,
49-
) -> Tuple[Optional[str], Optional[float]]:
50-
for status in task["statuses"]:
51-
if status["state"] != "TASK_RUNNING":
52-
continue
53-
container_id = (
54-
status.get("container_status", {}).get("container_id", {}).get("value")
55-
)
56-
time_start = status.get("timestamp")
57-
return container_id, time_start
58-
return None, None
59-
60-
61-
def get_paasta_service_instance_from_mesos_task(
62-
task: Task,
63-
) -> Tuple[Optional[str], Optional[str]]:
64-
try:
65-
docker_params = task["container"].get("docker", {}).get("parameters", [])
66-
except KeyError:
67-
return None, None
68-
service, instance = None, None
69-
for param in docker_params:
70-
if param["key"] == "label":
71-
label = param["value"]
72-
if label.startswith("paasta_service="):
73-
service = label.split("=")[1]
74-
if label.startswith("paasta_instance="):
75-
instance = label.split("=")[1]
76-
return service, instance
77-
78-
79-
async def get_pool_from_mesos_task(task: Task) -> Optional[str]:
80-
try:
81-
attributes = (await task.slave())["attributes"]
82-
return attributes.get("pool", "default")
83-
except SlaveDoesNotExist:
84-
return None
85-
86-
87-
@a_sync.to_blocking
88-
async def get_mesos_task_allocation_info() -> Iterable[TaskAllocationInfo]:
89-
tasks = await mesos_tools.get_cached_list_of_running_tasks_from_frameworks()
90-
info_list = []
91-
for task in tasks:
92-
mesos_container_id, start_time = get_container_info_from_mesos_task(task)
93-
paasta_service, paasta_instance = get_paasta_service_instance_from_mesos_task(
94-
task
95-
)
96-
paasta_pool = await get_pool_from_mesos_task(task)
97-
info_list.append(
98-
TaskAllocationInfo(
99-
paasta_service=paasta_service,
100-
paasta_instance=paasta_instance,
101-
container_type=MAIN_CONTAINER_TYPE,
102-
paasta_pool=paasta_pool,
103-
resources=task["resources"],
104-
start_time=start_time,
105-
docker_id=None,
106-
pod_name=None,
107-
pod_ip=None,
108-
host_ip=None,
109-
git_sha=None,
110-
config_sha=None,
111-
mesos_container_id=mesos_container_id,
112-
namespace=None,
113-
)
114-
)
115-
return info_list
116-
117-
11843
def get_all_running_kubernetes_pods(
11944
kube_client: KubeClient, namespace: str
12045
) -> Iterable[V1Pod]:
@@ -256,39 +181,24 @@ def get_kubernetes_task_allocation_info(
256181
return info_list
257182

258183

259-
def get_task_allocation_info(
260-
scheduler: str,
261-
namespace: str,
262-
kube_client: Optional[KubeClient],
263-
) -> Iterable[TaskAllocationInfo]:
264-
if scheduler == "mesos":
265-
return get_mesos_task_allocation_info()
266-
elif scheduler == "kubernetes":
267-
return get_kubernetes_task_allocation_info(namespace, kube_client)
268-
else:
269-
return []
270-
271-
272184
def parse_args() -> argparse.Namespace:
273185
parser = argparse.ArgumentParser(description="")
274186
parser.add_argument(
275187
"--scheduler",
276188
help="Scheduler to get task info from",
277189
dest="scheduler",
278-
default="mesos",
279-
choices=["mesos", "kubernetes"],
190+
default="kubernetes",
191+
choices=["kubernetes"],
280192
)
281193
parser.add_argument(
282194
"--namespace-prefix",
283-
help="prefix of the namespace to fetch the logs for"
284-
"Used only when scheduler is kubernetes",
195+
help="prefix of the namespace to fetch the logs for",
285196
dest="namespace_prefix",
286197
default="paasta",
287198
)
288199
parser.add_argument(
289200
"--additional-namespaces",
290-
help="full names of namespaces to fetch allocation info for that don't match --namespace-prefix"
291-
"Used only when scheduler is kubernetes",
201+
help="full names of namespaces to fetch allocation info for that don't match --namespace-prefix",
292202
dest="additional_namespaces",
293203
nargs="+",
294204
# we default this to tron since this is really the only non-paasta-prefix namespaced that is part of paasta
@@ -310,28 +220,20 @@ def get_matching_namespaces(
310220

311221
def main(args: argparse.Namespace) -> None:
312222
cluster = load_system_paasta_config().get_cluster()
313-
if args.scheduler == "mesos":
314-
display_task_allocation_info(
315-
cluster, args.scheduler, args.namespace_prefix, kube_client=None
316-
)
317-
else:
318-
kube_client = KubeClient()
319-
all_namespaces = kubernetes_tools.get_all_namespaces(kube_client)
320-
for matching_namespace in get_matching_namespaces(
321-
all_namespaces, args.namespace_prefix, args.additional_namespaces
322-
):
323-
display_task_allocation_info(
324-
cluster, args.scheduler, matching_namespace, kube_client
325-
)
223+
kube_client = KubeClient()
224+
all_namespaces = kubernetes_tools.get_all_namespaces(kube_client)
225+
for matching_namespace in get_matching_namespaces(
226+
all_namespaces, args.namespace_prefix, args.additional_namespaces
227+
):
228+
display_task_allocation_info(cluster, matching_namespace, kube_client)
326229

327230

328231
def display_task_allocation_info(
329232
cluster: str,
330-
scheduler: str,
331233
namespace: str,
332-
kube_client: Optional[KubeClient],
234+
kube_client: KubeClient,
333235
) -> None:
334-
info_list = get_task_allocation_info(scheduler, namespace, kube_client)
236+
info_list = get_kubernetes_task_allocation_info(namespace, kube_client)
335237
timestamp = time.time()
336238
for info in info_list:
337239
info_dict = info._asdict()

0 commit comments

Comments
 (0)